提交 ee4436a4 编写于 作者: M Mr.doob

Editor: Trying to bring back Scripting.

上级 b99aed7c
......@@ -76,6 +76,7 @@
<script src="js/Sidebar.Geometry.TorusKnotGeometry.js"></script>
<script src="js/Sidebar.Material.js"></script>
<script src="js/Sidebar.Script.js"></script>
<script src="js/Sidebar.Script.Editor.js"></script>
<script src="js/Toolbar.js"></script>
<script src="js/Viewport.js"></script>
<script src="js/Viewport.Info.js"></script>
......
......@@ -72,7 +72,6 @@ var Editor = function () {
this.geometries = {};
this.materials = {};
this.textures = {};
this.scripts = {};
this.selected = null;
......
/**
* @author mrdoob / http://mrdoob.com/
*/
Sidebar.Script.Editor = function ( editor ) {
var timeout;
var scriptSource = new UI.TextArea( 'javascript' ).setWidth( '240px' ).setHeight( '180px' ).setFontSize( '12px' );
scriptSource.onKeyUp( function () {
clearTimeout( timeout );
timeout = setTimeout( function () {
var object = editor.selected;
var source = scriptSource.getValue();
try {
var script = new Function( 'scene', 'time', source ).bind( object.clone() );
script( new THREE.Scene(), 0 );
scriptSource.dom.classList.add( 'success' );
scriptSource.dom.classList.remove( 'fail' );
} catch ( error ) {
scriptSource.dom.classList.remove( 'success' );
scriptSource.dom.classList.add( 'fail' );
return;
}
editor.scripts[ object.uuid ] = [ source ];
editor.signals.objectChanged.dispatch( object );
}, 500 );
} );
return scriptSource;
}
......@@ -18,61 +18,16 @@ Sidebar.Script = function ( editor ) {
container.addStatic( new UI.Text( 'Script' ).setTextTransform( 'uppercase' ) );
container.add( new UI.Break() );
var scriptsRow = new UI.Panel();
container.add( scriptsRow );
// source
var timeout;
var scriptSourceRow = new UI.Panel();
var scriptSource = new UI.TextArea( 'javascript' ).setWidth( '240px' ).setHeight( '180px' ).setFontSize( '12px' );
scriptSource.onKeyUp( function () {
clearTimeout( timeout );
timeout = setTimeout( function () {
var object = editor.selected;
var source = scriptSource.getValue();
try {
var script = new Function( 'scene', 'time', source ).bind( object.clone() );
script( new THREE.Scene(), 0 );
scriptSource.dom.classList.add( 'success' );
scriptSource.dom.classList.remove( 'fail' );
} catch ( error ) {
scriptSource.dom.classList.remove( 'success' );
scriptSource.dom.classList.add( 'fail' );
return;
}
editor.scripts[ object.uuid ] = [ source ];
editor.signals.objectChanged.dispatch( object );
}, 500 );
} );
scriptSourceRow.add( scriptSource );
container.add( scriptSourceRow );
//
var source = new Sidebar.Script.Editor( editor );
container.add( source );
signals.objectSelected.add( function ( object ) {
if ( object !== null ) {
container.setDisplay( 'block' );
/*
var scripts = editor.scripts[ object.uuid ];
if ( scripts !== undefined ) {
......@@ -84,6 +39,7 @@ Sidebar.Script = function ( editor ) {
scriptSource.setValue( '' );
}
*/
} else {
......
......@@ -83,6 +83,7 @@ APP.Player = function () {
APP.Script = function ( source ) {
this.uuid = THREE.Math.generateUUID();
this.source = source;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册