Browse Source

Merge pull request #10177 from polygontwist/patch-3

add support for Lightimport in VRML (to DEV)
Mr.doob 8 years ago
parent
commit
2be03c31c8
1 changed files with 86 additions and 2 deletions
  1. 86 2
      examples/js/loaders/VRMLLoader.js

+ 86 - 2
examples/js/loaders/VRMLLoader.js

@@ -415,7 +415,9 @@ THREE.VRMLLoader.prototype = {
 							};
 							};
 
 
 							break;
 							break;
-
+							
++						case 'location':
++						case 'direction':
 						case 'translation':
 						case 'translation':
 						case 'scale':
 						case 'scale':
 						case 'size':
 						case 'size':
@@ -434,6 +436,8 @@ THREE.VRMLLoader.prototype = {
 
 
 							break;
 							break;
 
 
+						case 'intensity':				
+						case 'cutOffAngle':
 						case 'radius':
 						case 'radius':
 						case 'topRadius':
 						case 'topRadius':
 						case 'bottomRadius':
 						case 'bottomRadius':
@@ -468,7 +472,8 @@ THREE.VRMLLoader.prototype = {
 							};
 							};
 
 
 							break;
 							break;
-
+							
+						case 'on':
 						case 'ccw':
 						case 'ccw':
 						case 'solid':
 						case 'solid':
 						case 'colorPerVertex':
 						case 'colorPerVertex':
@@ -623,6 +628,85 @@ THREE.VRMLLoader.prototype = {
 
 
 				var object = parent;
 				var object = parent;
 
 
+				if(data.string.indexOf("AmbientLight")>-1 && data.nodeType=='PointLight'){
+					//wenn im Namen "AmbientLight" vorkommt und es ein PointLight ist, 
+					//diesen Typ in 'AmbientLight' ändern
+					data.nodeType='AmbientLight';	
+				}
+				
+				l_visible=data.on;
+				if(l_visible==undefined)l_visible=true;
+				l_intensity=data.intensity;
+				if(l_intensity==undefined)l_intensity=true;
+				if(data.color!=undefined)
+					l_color= new THREE.Color(data.color.r, data.color.g,data.color.b );
+					else
+					l_color= new THREE.Color(0, 0,0);
+				
+				
+				
+				if('AmbientLight' === data.nodeType){
+					object=new THREE.AmbientLight( 
+								l_color.getHex(), 
+								l_intensity
+								);
+					object.visible=l_visible;
+					
+					parent.add( object );
+					
+				}
+				else
+				if('PointLight' === data.nodeType){
+						l_distance =0;	//0="unendlich" ...1000
+						l_decay=0;		//-1.. ?
+						
+						if(data.radius!=undefined && data.radius<1000){
+							//l_radius=data.radius;
+							l_distance=data.radius;
+							l_decay=1;
+						}
+						object=new THREE.PointLight( 
+								l_color.getHex(), 
+								l_intensity, 
+								l_distance);
+						object.visible=l_visible;
+						
+						parent.add( object );
+				}
+				else
+				if('SpotLight' === data.nodeType){						
+						l_intensity=1;
+						l_distance =0;//0="unendlich"=1000
+						l_angle=Math.PI/3;
+						l_penumbra=0.0;//0..1
+						l_decay=0;//-1.. ?
+						l_visible=true;
+						
+						if(data.radius!=undefined && data.radius<1000){
+							//l_radius=data.radius;
+							l_distance=data.radius;
+							l_decay=1;
+						}
+						if(data.cutOffAngle!=undefined)l_angle=data.cutOffAngle;
+						
+						object = new THREE.SpotLight(
+									l_color.getHex(),
+									l_intensity,
+									l_distance,
+									l_angle,
+									l_penumbra,
+									l_decay
+									);
+						object.visible=l_visible;						
+						parent.add( object );
+						/*
+						var lightHelper = new THREE.SpotLightHelper( object );
+						parent.parent.add( lightHelper );
+						lightHelper.update();
+						*/
+				}
+				else				
+				
 				if ( 'Transform' === data.nodeType || 'Group' === data.nodeType ) {
 				if ( 'Transform' === data.nodeType || 'Group' === data.nodeType ) {
 
 
 					object = new THREE.Object3D();
 					object = new THREE.Object3D();