Browse Source

Editor: Trying to bring back Scripting.

Mr.doob 10 năm trước cách đây
mục cha
commit
ee4436a401

+ 1 - 0
editor/index.html

@@ -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>

+ 0 - 1
editor/js/Editor.js

@@ -72,7 +72,6 @@ var Editor = function () {
 	this.geometries = {};
 	this.materials = {};
 	this.textures = {};
-
 	this.scripts = {};
 
 	this.selected = null;

+ 46 - 0
editor/js/Sidebar.Script.Editor.js

@@ -0,0 +1,46 @@
+/**
+ * @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;
+
+}

+ 5 - 49
editor/js/Sidebar.Script.js

@@ -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 {
 

+ 1 - 0
editor/js/libs/app.js

@@ -83,6 +83,7 @@ APP.Player = function () {
 
 APP.Script = function ( source ) {
 
+	this.uuid = THREE.Math.generateUUID();
 	this.source = source;
 
 };