Pārlūkot izejas kodu

Moving THREE.Script to the Editor.

Mr.doob 10 gadi atpakaļ
vecāks
revīzija
a4fd0c8c7c

+ 3 - 2
editor/index.html

@@ -41,10 +41,11 @@
 		<script src="js/libs/ui.editor.js"></script>
 		<script src="js/libs/ui.editor.js"></script>
 		<script src="js/libs/ui.three.js"></script>
 		<script src="js/libs/ui.three.js"></script>
 
 
-		<script src="js/Storage.js"></script>
-
+		<script src="js/libs/app.js"></script>
 		<script src="js/Player.js"></script>
 		<script src="js/Player.js"></script>
 
 
+		<script src="js/Storage.js"></script>
+
 		<script src="js/Editor.js"></script>
 		<script src="js/Editor.js"></script>
 		<script src="js/Config.js"></script>
 		<script src="js/Config.js"></script>
 		<script src="js/Loader.js"></script>
 		<script src="js/Loader.js"></script>

+ 11 - 78
editor/js/Player.js

@@ -12,87 +12,18 @@ var Player = function ( editor ) {
 
 
 	//
 	//
 
 
-	var camera, scene, renderer;
-	var scripts;
-
-	//
-
-	var load = function ( json ) {
-
-		renderer = new THREE.WebGLRenderer( { antialias: true } );
-		renderer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
-		container.dom.appendChild( renderer.domElement );
-
-		camera = editor.camera.clone();
-
-		scene = new THREE.ObjectLoader().parse( json );
-
-		//
-
-		scripts = [];
-
-		scene.traverse( function ( child ) {
-
-			if ( child.script !== undefined ) {
-
-				var script = new Function( 'scene', 'time', child.script.source ).bind( child );
-				scripts.push( script );
-
-			}
-
-		} );
-
-	};
-
-	var request;
-
-	var play = function () {
-
-		request = requestAnimationFrame( play );
-
-		update();
-		render();
-
-	};
-
-	var stop = function () {
-
-		cancelAnimationFrame( request );
-
-		if ( renderer !== undefined ) {
-
-			container.dom.removeChild( renderer.domElement );
-
-		}
-
-	};
-
-	var render = function () {
-
-		renderer.render( scene, camera );
-
-	};
-
-	var update = function () {
-
-		var time = performance.now();
-
-		for ( var i = 0; i < scripts.length; i ++ ) {
-
-			scripts[ i ]( scene, time );
-
-		}
-
-		render();
-
-	};
+	var player = new APP.Player();
 
 
 	signals.startPlayer.add( function ( json ) {
 	signals.startPlayer.add( function ( json ) {
 
 
 		container.setDisplay( '' );
 		container.setDisplay( '' );
 
 
-		load( json );
-		play();
+		player.load( json );
+		player.setCamera( editor.camera );
+		player.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
+		player.play();
+
+		container.dom.appendChild( player.dom );
 
 
 	} );
 	} );
 
 
@@ -100,10 +31,12 @@ var Player = function ( editor ) {
 
 
 		container.setDisplay( 'none' );
 		container.setDisplay( 'none' );
 
 
-		stop();
+		player.stop();
+
+		container.dom.removeChild( player.dom );
 
 
 	} );
 	} );
 
 
 	return container;
 	return container;
 
 
-};
+};

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

@@ -53,7 +53,7 @@ Sidebar.Script = function ( editor ) {
 
 
 			}
 			}
 
 
-			object.script = new THREE.Script( source );
+			editor.scripts[ object.uuid ] = [ source ];
 
 
 			editor.signals.objectChanged.dispatch( object );
 			editor.signals.objectChanged.dispatch( object );
 
 
@@ -72,10 +72,12 @@ Sidebar.Script = function ( editor ) {
 		if ( object !== null ) {
 		if ( object !== null ) {
 
 
 			container.setDisplay( 'block' );
 			container.setDisplay( 'block' );
+			
+			var scripts = editor.scripts[ object.uuid ];
 
 
-			if ( object.script !== undefined ) {
+			if ( scripts !== undefined ) {
 
 
-				scriptSource.setValue( object.script.source );
+				scriptSource.setValue( scripts[ 0 ] );
 
 
 			} else {
 			} else {
 
 

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

@@ -0,0 +1,88 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+var APP = {};
+
+APP.Player = function () {
+
+	var loader = new THREE.ObjectLoader();
+	var camera, scene, renderer;
+	var scripts;
+	
+	this.dom = undefined;
+
+	this.load = function ( json ) {
+
+		renderer = new THREE.WebGLRenderer( { antialias: true } );
+
+		scene = loader.parse( json );
+
+		/*
+		scripts = [];
+
+		scene.traverse( function ( child ) {
+
+			if ( child.script !== undefined ) {
+
+				var script = new Function( 'scene', 'time', child.script.source ).bind( child );
+				scripts.push( script );
+
+			}
+
+		} );
+		*/
+
+		this.dom = renderer.domElement;
+
+	};
+
+	this.setCamera = function ( master ) {
+
+		camera = master.clone();
+
+	};
+
+	this.setSize = function ( width, height ) {
+
+		renderer.setSize( width, height );
+
+	};
+
+	var request;
+
+	var animate = function ( time ) {
+
+		request = requestAnimationFrame( animate );
+
+		/*
+		for ( var i = 0; i < scripts.length; i ++ ) {
+
+			scripts[ i ]( scene, time );
+
+		}
+		*/
+
+		renderer.render( scene, camera );
+
+	};
+
+	this.play = function () {
+
+		request = requestAnimationFrame( animate );
+
+	};
+
+	this.stop = function () {
+
+		cancelAnimationFrame( request );
+
+	};
+
+};
+
+APP.Script = function ( source ) {
+
+	this.source = source;
+
+};

+ 0 - 3
src/core/Object3D.js

@@ -564,7 +564,6 @@ THREE.Object3D.prototype = {
 
 
 			if ( object.name !== '' ) data.name = object.name;
 			if ( object.name !== '' ) data.name = object.name;
 			if ( JSON.stringify( object.userData ) !== '{}' ) data.userData = object.userData;
 			if ( JSON.stringify( object.userData ) !== '{}' ) data.userData = object.userData;
-			if ( object.script !== undefined ) data.script = object.script.source;
 			if ( object.visible !== true ) data.visible = object.visible;
 			if ( object.visible !== true ) data.visible = object.visible;
 
 
 			if ( object instanceof THREE.PerspectiveCamera ) {
 			if ( object instanceof THREE.PerspectiveCamera ) {
@@ -678,8 +677,6 @@ THREE.Object3D.prototype = {
 
 
 		object.userData = JSON.parse( JSON.stringify( this.userData ) );
 		object.userData = JSON.parse( JSON.stringify( this.userData ) );
 
 
-		if ( this.script !== undefined ) object.script = this.script.clone();
-
 		if ( recursive === true ) {
 		if ( recursive === true ) {
 
 
 			for ( var i = 0; i < this.children.length; i ++ ) {
 			for ( var i = 0; i < this.children.length; i ++ ) {

+ 0 - 22
src/core/Script.js

@@ -1,22 +0,0 @@
-/**
- * @author mrdoob / http://mrdoob.com/
- */
-
-THREE.Script = function ( source ) {
-
-	this.uuid = THREE.Math.generateUUID();
-	this.source = source;
-
-};
-
-THREE.Script.prototype = {
-
-	constructor: THREE.Script,
-
-	clone: function () {
-
-		return new THREE.Script( this.source );
-
-	}
-
-};

+ 0 - 1
src/loaders/ObjectLoader.js

@@ -332,7 +332,6 @@ THREE.ObjectLoader.prototype = {
 
 
 			if ( data.visible !== undefined ) object.visible = data.visible;
 			if ( data.visible !== undefined ) object.visible = data.visible;
 			if ( data.userData !== undefined ) object.userData = data.userData;
 			if ( data.userData !== undefined ) object.userData = data.userData;
-			if ( data.script !== undefined ) object.script = new THREE.Script( data.script );
 
 
 			if ( data.children !== undefined ) {
 			if ( data.children !== undefined ) {
 
 

+ 0 - 1
utils/build/includes/canvas.json

@@ -23,7 +23,6 @@
 	"src/core/Face3.js",
 	"src/core/Face3.js",
 	"src/core/Face4.js",
 	"src/core/Face4.js",
 	"src/core/Geometry.js",
 	"src/core/Geometry.js",
-	"src/core/Script.js",
 	"src/cameras/Camera.js",
 	"src/cameras/Camera.js",
 	"src/cameras/OrthographicCamera.js",
 	"src/cameras/OrthographicCamera.js",
 	"src/cameras/PerspectiveCamera.js",
 	"src/cameras/PerspectiveCamera.js",

+ 0 - 1
utils/build/includes/common.json

@@ -28,7 +28,6 @@
 	"src/core/BufferAttribute.js",
 	"src/core/BufferAttribute.js",
 	"src/core/BufferGeometry.js",
 	"src/core/BufferGeometry.js",
 	"src/core/Geometry.js",
 	"src/core/Geometry.js",
-	"src/core/Script.js",
 	"src/cameras/Camera.js",
 	"src/cameras/Camera.js",
 	"src/cameras/CubeCamera.js",
 	"src/cameras/CubeCamera.js",
 	"src/cameras/OrthographicCamera.js",
 	"src/cameras/OrthographicCamera.js",

+ 0 - 1
utils/build/includes/css3d.json

@@ -15,7 +15,6 @@
 	"src/math/Plane.js",
 	"src/math/Plane.js",
 	"src/core/EventDispatcher.js",
 	"src/core/EventDispatcher.js",
 	"src/core/Object3D.js",
 	"src/core/Object3D.js",
-	"src/core/Script.js",
 	"src/cameras/Camera.js",
 	"src/cameras/Camera.js",
 	"src/cameras/PerspectiveCamera.js",
 	"src/cameras/PerspectiveCamera.js",
 	"src/lights/Light.js",
 	"src/lights/Light.js",