Explorar o código

Editor: plugged object delete and scene reset actions into menubar.

Default scene on the initialization is now created via resetScene action, in the same way like via menubar.
alteredq %!s(int64=13) %!d(string=hai) anos
pai
achega
19b029c62e

+ 7 - 10
editor/index.html

@@ -66,7 +66,7 @@
 
 				// notifications
 
-				sceneCreated: new SIGNALS.Signal(),
+				sceneAdded: new SIGNALS.Signal(),
 				sceneChanged: new SIGNALS.Signal(),
 				objectAdded: new SIGNALS.Signal(),
 				objectSelected: new SIGNALS.Signal(),
@@ -244,7 +244,7 @@
 
 									if ( resetScene ) {
 
-										signals.resetScene.dispatch( result.scene, result.currentCamera, result.bgColor );
+										signals.sceneAdded.dispatch( result.scene, result.currentCamera, result.bgColor );
 
 									} else {
 
@@ -350,16 +350,11 @@
 
 			}
 
-			var geometry = new THREE.SphereGeometry( 75, 25, 15 );
+			// create default scene
 
-			var material = new THREE.MeshPhongMaterial();
-			material.color.setHSV( Math.random(), Math.random(), 1 );
+			signals.resetScene.dispatch();
 
-			var mesh = new THREE.Mesh( geometry, material );
-			mesh.name = "Sphere";
-
-			signals.objectAdded.dispatch( mesh );
-			signals.objectSelected.dispatch( mesh );
+			//
 
 			var onWindowResize = function ( event ) {
 
@@ -373,6 +368,8 @@
 
 			};
 
+			//
+
 			onWindowResize();
 
 			window.addEventListener( 'resize', onWindowResize, false );

+ 1 - 1
editor/js/ui/Menubar.Edit.js

@@ -25,7 +25,7 @@ Menubar.Edit = function ( signals ) {
 
 	var option = new UI.Panel();
 	option.setTextContent( 'Delete' ).setColor( '#666' );
-	option.onClick( function () { alert( 'Delete' ) } );
+	option.onClick( function () { signals.removeSelectedObject.dispatch(); } );
 	options.add( option );
 
 	return container;

+ 1 - 1
editor/js/ui/Menubar.File.js

@@ -30,7 +30,7 @@ Menubar.File = function ( signals ) {
 
 	var option = new UI.Panel();
 	option.setTextContent( 'Reset' ).setColor( '#666' );
-	option.onClick( function () { alert( 'Reset' ) } );
+	option.onClick( function () { signals.resetScene.dispatch(); } );
 	options.add( option );
 
 	var option = new UI.Panel();

+ 0 - 6
editor/js/ui/Sidebar.Scene.js

@@ -224,12 +224,6 @@ Sidebar.Scene = function ( signals ) {
 
 	// events
 
-	signals.sceneCreated.add( function ( object ) {
-
-		scene = object;
-
-	} );
-
 	signals.sceneChanged.add( function ( object ) {
 
 		scene = object;

+ 92 - 46
editor/js/ui/Viewport.js

@@ -47,30 +47,10 @@ var Viewport = function ( signals ) {
 	selectionAxis.visible = false;
 	sceneHelpers.add( selectionAxis );
 
-	//
+	// default dummy scene and camera
 
 	var scene = new THREE.Scene();
-
-	var camera = new THREE.PerspectiveCamera( 50, 1, 1, 5000 );
-	camera.position.set( 500, 250, 500 );
-	camera.lookAt( scene.position );
-	scene.add( camera );
-
-	var light1 = new THREE.DirectionalLight( 0xffffff, 0.8 );
-	light1.position.set( 1, 0.5, 0 ).multiplyScalar( 400 );
-
-	var light2 = new THREE.SpotLight( 0xffffff, 1.5, 500, Math.PI * 0.025 );
-	light2.position.set( - 1, 0.5, 1 ).multiplyScalar( 300 );
-
-	light1.target.properties.targetInverse = light1;
-	light2.target.properties.targetInverse = light2;
-
-	var light3 = new THREE.PointLight( 0xffaa00, 0.75 );
-	light3.position.set( -250, 200, -200 );
-
-	//var light4 = new THREE.AmbientLight( 0x111111 );
-	var light4 = new THREE.HemisphereLight( 0x00aaff, 0xff0000, 0.75 );
-	light4.position.y = 250;
+	var camera = new THREE.Camera();
 
 	// fog
 
@@ -80,24 +60,6 @@ var Viewport = function ( signals ) {
 	var oldFogFar = 5000;
 	var oldFogDensity = 0.00025;
 
-	// default objects names
-
-	camera.name = "Camera";
-
-	light1.name = "Light 1";
-	light1.target.name = "Light 1 Target";
-
-	light2.name = "Light 2";
-	light2.target.name = "Light 2 Target";
-
-	light3.name = "Light 3";
-
-	light4.name = "Light 4";
-
-	// active objects
-
-	camera.properties.active = true;
-
 	// object picking
 
 	var intersectionPlane = new THREE.Mesh( new THREE.PlaneGeometry( 10000, 10000, 8, 8 ) );
@@ -679,7 +641,21 @@ var Viewport = function ( signals ) {
 
 	} );
 
-	signals.resetScene.add( function ( newScene, newCamera, newClearColor ) {
+	signals.resetScene.add( function () {
+
+		var defaultScene = createDefaultScene();
+		var defaultCamera = createDefaultCamera();
+		var defaultBgColor = new THREE.Color( 0xaaaaaa );
+
+		defaultCamera.lookAt( defaultScene.position );
+		defaultScene.add( defaultCamera );
+
+		signals.sceneAdded.dispatch( defaultScene, defaultCamera, defaultBgColor );
+		signals.objectSelected.dispatch( defaultScene.properties.defaultSelection );
+
+	} );
+
+	signals.sceneAdded.add( function ( newScene, newCamera, newClearColor ) {
 
 		scene = newScene;
 
@@ -787,11 +763,6 @@ var Viewport = function ( signals ) {
 
 	signals.sceneChanged.dispatch( scene );
 
-	signals.objectAdded.dispatch( light1 );
-	signals.objectAdded.dispatch( light2 );
-	signals.objectAdded.dispatch( light3 );
-	signals.objectAdded.dispatch( light4 );
-
 	//
 
 	function updateMaterials( root ) {
@@ -832,6 +803,81 @@ var Viewport = function ( signals ) {
 
 	}
 
+	function createDefaultScene() {
+
+		// create scene
+
+		var scene = new THREE.Scene();
+
+		// create lights
+
+		var light1 = new THREE.DirectionalLight( 0xffffff, 0.8 );
+		light1.position.set( 1, 0.5, 0 ).multiplyScalar( 400 );
+
+		var light2 = new THREE.SpotLight( 0xffffff, 1.5, 500, Math.PI * 0.025 );
+		light2.position.set( - 1, 0.5, 1 ).multiplyScalar( 300 );
+
+		var light3 = new THREE.PointLight( 0xffaa00, 0.75 );
+		light3.position.set( -250, 200, -200 );
+
+		//var light4 = new THREE.AmbientLight( 0x111111 );
+		var light4 = new THREE.HemisphereLight( 0x00aaff, 0xff0000, 0.75 );
+		light4.position.y = 250;
+
+		light1.target.properties.targetInverse = light1;
+		light2.target.properties.targetInverse = light2;
+
+		// create objects
+
+		var geometry = new THREE.SphereGeometry( 75, 25, 15 );
+
+		var material = new THREE.MeshPhongMaterial();
+		material.color.setHSV( Math.random(), Math.random(), 1 );
+
+		var mesh = new THREE.Mesh( geometry, material );
+
+		// set default names
+
+		light1.name = "Light 1";
+		light1.target.name = "Light 1 Target";
+
+		light2.name = "Light 2";
+		light2.target.name = "Light 2 Target";
+
+		light3.name = "Light 3";
+
+		light4.name = "Light 4";
+
+		mesh.name = "Sphere";
+
+		// set default selection
+
+		scene.properties.defaultSelection = mesh;
+
+		// add to scene
+
+		scene.add( light1 );
+		scene.add( light2 );
+		scene.add( light3 );
+		scene.add( light4 );
+		scene.add( mesh );
+
+		return scene;
+
+	}
+
+	function createDefaultCamera() {
+
+		var camera = new THREE.PerspectiveCamera( 50, 1, 1, 5000 );
+		camera.position.set( 500, 250, 500 );
+
+		camera.name = "Camera";
+		camera.properties.active = true;
+
+		return camera;
+
+	}
+
 	function animate() {
 
 		requestAnimationFrame( animate );