Browse Source

Editor: plugged in adding of point and directional lights to menubar.

alteredq 12 years ago
parent
commit
3689f6b306
2 changed files with 64 additions and 1 deletions
  1. 56 0
      editor/js/ui/Menubar.Add.js
  2. 8 1
      editor/js/ui/Viewport.js

+ 56 - 0
editor/js/ui/Menubar.Add.js

@@ -97,6 +97,62 @@ Menubar.Add = function ( signals ) {
 
 	addHoverStyle( option );
 
+	// divider
+
+	var option = new UI.Panel();
+	option.setBackgroundColor( '#ccc' ).setPadding( '1px 12px' );
+	options.add( option );
+
+	// add directional light
+
+	var option = new UI.Panel();
+	option.setTextContent( 'Directional light' ).setColor( '#666' ).setPadding( '6px 12px' );
+	option.onClick( function () {
+
+		var color = 0xffffff;
+		var intensity = 1;
+
+		var light = new THREE.DirectionalLight( color, intensity );
+		light.name = 'Light ' + light.id;
+		light.target.name = 'Light ' + light.id + ' target';
+
+		light.target.properties.targetInverse = light;
+
+		light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
+
+		signals.objectAdded.dispatch( light );
+
+	} );
+	options.add( option );
+
+	addHoverStyle( option );
+
+	// add point light
+
+	var option = new UI.Panel();
+	option.setTextContent( 'Point light' ).setColor( '#666' ).setPadding( '6px 12px' );
+	option.onClick( function () {
+
+		var color = 0xffffff;
+		var intensity = 1;
+		var distance = 0;
+
+		var light = new THREE.PointLight( color, intensity, distance );
+		light.name = 'Light ' + light.id;
+
+		signals.objectAdded.dispatch( light );
+
+	} );
+	options.add( option );
+
+	addHoverStyle( option );
+
+	// add spot light
+
+	// add hemisphere light
+
+	// add ambient light
+
 	//
 
 	function addHoverStyle( element ) {

+ 8 - 1
editor/js/ui/Viewport.js

@@ -353,6 +353,13 @@ var Viewport = function ( signals ) {
 		object.traverse( handleAddition );
 
 		scene.add( object );
+
+		if ( object instanceof THREE.Light && ! ( object instanceof THREE.AmbientLight ) )  {
+
+			updateMaterials( scene );
+
+		}
+
 		render();
 
 		signals.sceneChanged.dispatch( scene );
@@ -481,7 +488,7 @@ var Viewport = function ( signals ) {
 
 		} );
 
-		if ( selected instanceof THREE.Light && !selected instanceof THREE.AmbientLight )  {
+		if ( selected instanceof THREE.Light && ! ( selected instanceof THREE.AmbientLight ) )  {
 
 			updateMaterials( scene );