Browse Source

Editor: plugged in adding of SpotLight, HemisphereLight and AmbientLight to menubar.

Also nicer whitespace formatting for lights and cameras in strings generated by SceneExporter.
alteredq 12 years ago
parent
commit
314dcf0255
2 changed files with 90 additions and 31 deletions
  1. 59 0
      editor/js/ui/Menubar.Add.js
  2. 31 31
      examples/js/exporters/SceneExporter.js

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

@@ -132,10 +132,69 @@ Menubar.Add = function ( signals ) {
 
 	// add spot light
 
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Spot light' );
+	option.onClick( function () {
+
+		var color = 0xffffff;
+		var intensity = 1;
+		var distance = 0;
+		var angle = Math.PI * 0.1;
+		var exponent = 10;
+
+		var light = new THREE.SpotLight( color, intensity, distance, angle, exponent );
+		light.name = 'Light ' + light.id;
+		light.target.name = 'Light ' + light.id + ' target';
+
+		light.target.properties.targetInverse = light;
+
+		light.position.set( 0, 1, 0 ).multiplyScalar( 200 );
+
+		signals.objectAdded.dispatch( light );
+
+	} );
+	options.add( option );
+
 	// add hemisphere light
 
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Hemisphere light' );
+	option.onClick( function () {
+
+		var skyColor = 0x00aaff;
+		var groundColor = 0xffaa00;
+		var intensity = 1;
+
+		var light = new THREE.HemisphereLight( skyColor, groundColor, intensity );
+		light.name = 'Light ' + light.id;
+
+		light.position.set( 1, 1, 1 ).multiplyScalar( 200 );
+
+		signals.objectAdded.dispatch( light );
+
+	} );
+	options.add( option );
+
 	// add ambient light
 
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Ambient light' );
+	option.onClick( function () {
+
+		var color = 0x222222;
+
+		var light = new THREE.AmbientLight( color );
+		light.name = 'Light ' + light.id;
+
+		signals.objectAdded.dispatch( light );
+
+	} );
+	options.add( option );
+
+	//
 
 	function createDummyMaterial() {
 

+ 31 - 31
examples/js/exporters/SceneExporter.js

@@ -217,8 +217,8 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "AmbientLight",',
-				'	"color"  : ' + o.color.getHex() + ( o.children.length ? ',' : '' )
+				'	"type"  : "AmbientLight",',
+				'	"color" : ' + o.color.getHex() + ( o.children.length ? ',' : '' )
 
 				];
 
@@ -227,9 +227,9 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "DirectionalLight",',
-				'	"color"  : ' + o.color.getHex() + ',',
-				'	"intensity"  : ' + o.intensity + ',',
+				'	"type"      : "DirectionalLight",',
+				'	"color"     : ' + o.color.getHex() + ',',
+				'	"intensity" : ' + o.intensity + ',',
 				'	"direction" : ' + Vector3String( o.position ) + ',',
 				'	"target"    : ' + LabelString( getObjectName( o.target ) ) + ( o.children.length ? ',' : '' )
 
@@ -240,10 +240,10 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "PointLight",',
-				'	"color"  : ' + o.color.getHex() + ',',
-				'	"intensity"  : ' + o.intensity + ',',
-				'	"position" : ' + Vector3String( o.position ) + ',',
+				'	"type"      : "PointLight",',
+				'	"color"     : ' + o.color.getHex() + ',',
+				'	"intensity" : ' + o.intensity + ',',
+				'	"position"  : ' + Vector3String( o.position ) + ',',
 				'	"distance"  : ' + o.distance + ( o.children.length ? ',' : '' )
 
 				];
@@ -253,12 +253,12 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "SpotLight",',
-				'	"color"  : ' + o.color.getHex() + ',',
-				'	"intensity"  : ' + o.intensity + ',',
-				'	"position" : ' + Vector3String( o.position ) + ',',
+				'	"type"      : "SpotLight",',
+				'	"color"     : ' + o.color.getHex() + ',',
+				'	"intensity" : ' + o.intensity + ',',
+				'	"position"  : ' + Vector3String( o.position ) + ',',
 				'	"distance"  : ' + o.distance + ',',
-				'	"angle"  : ' + o.angle + ',',
+				'	"angle"     : ' + o.angle + ',',
 				'	"exponent"  : ' + o.exponent + ',',
 				'	"target"    : ' + LabelString( getObjectName( o.target ) ) + ( o.children.length ? ',' : '' )
 
@@ -269,11 +269,11 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "HemisphereLight",',
-				'	"skyColor"  : ' + o.color.getHex() + ',',
-				'	"groundColor"  : ' + o.groundColor.getHex() + ',',
-				'	"intensity"  : ' + o.intensity + ',',
-				'	"position" : ' + Vector3String( o.position ) + ( o.children.length ? ',' : '' )
+				'	"type"        : "HemisphereLight",',
+				'	"skyColor"    : ' + o.color.getHex() + ',',
+				'	"groundColor" : ' + o.groundColor.getHex() + ',',
+				'	"intensity"   : ' + o.intensity + ',',
+				'	"position"    : ' + Vector3String( o.position ) + ( o.children.length ? ',' : '' )
 
 				];
 
@@ -294,11 +294,11 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "PerspectiveCamera",',
-				'	"fov": ' + o.fov + ',',
-				'	"aspect": ' + o.aspect + ',',
-				'	"near": ' + o.near + ',',
-				'	"far": ' + o.far + ',',
+				'	"type"     : "PerspectiveCamera",',
+				'	"fov"      : ' + o.fov + ',',
+				'	"aspect"   : ' + o.aspect + ',',
+				'	"near"     : ' + o.near + ',',
+				'	"far"      : ' + o.far + ',',
 				'	"position" : ' + Vector3String( o.position ) + ( o.children.length ? ',' : '' )
 
 				];
@@ -308,13 +308,13 @@ THREE.SceneExporter.prototype = {
 				var output = [
 
 				'\t\t' + LabelString( getObjectName( o ) ) + ' : {',
-				'	"type" : "OrthographicCamera",',
-				'	"left": ' + o.left + ',',
-				'	"right": ' + o.right + ',',
-				'	"top": ' + o.top + ',',
-				'	"bottom": ' + o.bottom + ',',
-				'	"near": ' + o.near + ',',
-				'	"far": ' + o.far + ',',
+				'	"type"     : "OrthographicCamera",',
+				'	"left"     : ' + o.left + ',',
+				'	"right"    : ' + o.right + ',',
+				'	"top"      : ' + o.top + ',',
+				'	"bottom"   : ' + o.bottom + ',',
+				'	"near"     : ' + o.near + ',',
+				'	"far"      : ' + o.far + ',',
 				'	"position" : ' + Vector3String( o.position ) + ( o.children.length ? ',' : '' )
 
 				];