From fc496e86ec9ffb41a71a61803d41a75901f8d967 Mon Sep 17 00:00:00 2001 From: zz85 Date: Fri, 7 Oct 2011 18:08:38 +0800 Subject: [PATCH] Some fixes to GUI Codegen + Preview --- gui/js/Code.Templates.js | 2 +- gui/js/Code.js | 52 +++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/gui/js/Code.Templates.js b/gui/js/Code.Templates.js index be11259bd5..1c1bd0f9be 100644 --- a/gui/js/Code.Templates.js +++ b/gui/js/Code.Templates.js @@ -126,7 +126,7 @@ THREE.MeshBasicMaterial.prototype.gui = { return 'new THREE.MeshBasicMaterial( { ' + [ - 'color: ' + material.color.getHex() + 'color: 0x' + material.color.getHex().toString(16) ].join( ', ' ) + ' } )'; diff --git a/gui/js/Code.js b/gui/js/Code.js index f1bca79029..11a351d904 100644 --- a/gui/js/Code.js +++ b/gui/js/Code.js @@ -14,6 +14,40 @@ var Code = function () { _checkbox.style.margin = '20px 6px 0px 20px'; _checkbox.addEventListener( 'click', function () { _html = !_html; _update(); }, false ); _domElement.appendChild( _checkbox ); + + var _preview = document.createElement( 'a' ); + _preview.href = '#'; + _preview.innerHTML = 'preview'; + _preview.style.margin = '20px 6px 0px 20px'; + _preview.addEventListener( 'click', + function () { + + + // Get unescaped code gen + var temp=document.createElement("pre"); + temp.innerHTML = _codegen( true ); + temp = temp.firstChild.nodeValue; + temp = temp.replace("js/Three.js", "../build/Three.js"); + temp = temp.replace("js/RequestAnimationFrame.js", "../examples/js/RequestAnimationFrame.js"); + aaa = temp; + console.log('test', temp); + + var opener = window.open('','myconsole', + 'width=800,height=400' + +',menubar=1' + +',toolbar=0' + +',status=1' + +',scrollbars=1' + +',resizable=1'); + + + opener.document.writeln( temp ); + opener.document.close(); + + }, false + ); + _domElement.appendChild( _preview ); + /* var _checkboxText = document.createElement( 'span' ); @@ -34,9 +68,8 @@ var Code = function () { // var _list = []; - - var _update = function () { - + + var _codegen = function (html) { var string = ''; string += [ @@ -48,7 +81,8 @@ var Code = function () { '', 'function init() {', '', - '\tcamera = new THREE.Camera();', + '\tcamera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );', + '\tcamera.position.z = 500;', '', '\tscene = new THREE.Scene();', '' @@ -79,18 +113,24 @@ var Code = function () { 'function render() {', '', '\trenderer.render( scene, camera );', + '\trenderer.setSize( window.innerWidth, window.innerHeight );', '', '}' ].join( '\n' ); - if ( _html ) { + if ( html ) { string = '<!doctype html>\n<html>\n\t<body>\n\t\t<script src=\"js/Three.js\"></script>\n\t\t<script src=\"js/RequestAnimationFrame.js\"></script>\n\t\t<script>\n' + ( '\n' + string ).replace( /\n/gi, '\n\t\t\t' ) + '\n\n\t\t</script>\n\t</body>\n</html>'; } - _code.innerHTML = string; + return string; + } + + var _update = function () { + + _code.innerHTML = _codegen( _html ); } -- GitLab