Przeglądaj źródła

Merge branch 'master' of git://github.com/tparisi/three.js into dev

Mr.doob 12 lat temu
rodzic
commit
1f0f08d3f7
1 zmienionych plików z 129 dodań i 55 usunięć
  1. 129 55
      examples/js/loaders/ColladaLoader.js

+ 129 - 55
examples/js/loaders/ColladaLoader.js

@@ -835,31 +835,51 @@ THREE.ColladaLoader = function () {
 
 		for ( i = 0; i < node.cameras.length; i ++ ) {
 
-			var params = cameras[node.cameras[i].url];
-			obj = new THREE.PerspectiveCamera(params.fov, params.aspect_ratio, params.znear, params.zfar);
+			var instance_camera = node.cameras[i];
+			var cparams = cameras[instance_camera.url];
+
+			obj = new THREE.PerspectiveCamera(cparams.fov, parseFloat(cparams.aspect_ratio), 
+					parseFloat(cparams.znear), parseFloat(cparams.zfar));
 
 		}
 
 		for ( i = 0; i < node.lights.length; i ++ ) {
 
-			var params = lights[node.lights[i].url];
-
-			switch ( params.technique ) {
-
-				case 'ambient':
-					obj = new THREE.AmbientLight(params.color);
-					break;
-
-				case 'point':
-					obj = new THREE.PointLight(params.color);
-					break;
+			var instance_light = node.lights[i];
+			var lparams = lights[instance_light.url];
+
+			if (lparams && lparams.technique)
+			{
+				var color = lparams.color.getHex();
+				var intensity = lparams.intensity;
+				var distance = 0;
+				var angle = lparams.falloff_angle;
+				var exponent; // Intentionally undefined, don't know what this is yet
+				
+				switch (lparams.technique)
+				{
+					case 'directional' :
+						
+						obj = new THREE.DirectionalLight(color, intensity, distance);
+						break;
+				
+					case 'point' :
+						
+						obj = new THREE.PointLight(color, intensity, distance);
+						break;
 
-				case 'directional':
-					obj = new THREE.DirectionalLight(params.color);
-					break;
+					case 'spot' :
+						
+						obj = new THREE.SpotLight(color, intensity, distance, angle, exponent);
+						break;
 
+					case 'ambient' :
+						
+						obj = new THREE.AmbientLight(color);
+						break;
+				}
 			}
-
+			
 		}
 
 		obj.name = node.name || node.id || "";
@@ -1845,11 +1865,6 @@ THREE.ColladaLoader = function () {
 					this.cameras.push( ( new InstanceCamera() ).parse( child ) );
 					break;
 
-				case 'instance_light':
-
-					this.lights.push( ( new InstanceLight() ).parse( child ) );
-					break;
-
 				case 'instance_controller':
 
 					this.controllers.push( ( new InstanceController() ).parse( child ) );
@@ -1860,6 +1875,11 @@ THREE.ColladaLoader = function () {
 					this.geometries.push( ( new InstanceGeometry() ).parse( child ) );
 					break;
 
+				case 'instance_light':
+
+					this.lights.push( ( new InstanceLight() ).parse( child ) );
+					break;
+
 				case 'instance_node':
 
 					url = child.getAttribute( 'url' ).replace( /^#/, '' );
@@ -2978,6 +2998,11 @@ THREE.ColladaLoader = function () {
 
 	ColorOrTexture.prototype.parse = function ( element ) {
 
+		if (element.nodeName == 'transparent')
+		{
+			this.opaque = element.getAttribute('opaque');
+		}
+		
 		for ( var i = 0; i < element.childNodes.length; i ++ ) {
 
 			var child = element.childNodes[ i ];
@@ -3124,8 +3149,25 @@ THREE.ColladaLoader = function () {
 	Shader.prototype.create = function() {
 
 		var props = {};
-		var transparent = ( this['transparency'] !== undefined && this['transparency'] < 1.0 );
 
+		var transparent = false;
+		if (this['transparency'] !== undefined && this['transparent'] !== undefined)
+		{
+			// convert transparent color RBG to average value
+			var transparentColor = this['transparent'];
+			var transparencyLevel = (this.transparent.color.r +
+										this.transparent.color.g + 
+										this.transparent.color.b)
+										/ 3 * this.transparency;
+			
+			if (transparencyLevel > 0)
+			{
+				transparent = true;
+				props[ 'transparent' ] = true;
+				props[ 'opacity' ] = 1 - transparencyLevel;
+			}
+		}
+		
 		for ( var prop in this ) {
 
 			switch ( prop ) {
@@ -3204,15 +3246,7 @@ THREE.ColladaLoader = function () {
 					break;
 
 				case 'transparency':
-
-					if ( transparent ) {
-
-						props[ 'transparent' ] = true;
-						props[ 'opacity' ] = this[ prop ];
-						transparent = true;
-
-					}
-
+					// gets figured out up top
 					break;
 
 				default:
@@ -3941,7 +3975,6 @@ THREE.ColladaLoader = function () {
 	};
 
 	// Camera
-
 	function Camera() {
 
 		this.id = "";
@@ -3963,9 +3996,13 @@ THREE.ColladaLoader = function () {
 			switch ( child.nodeName ) {
 
 				case 'optics':
+
 					this.parseOptics( child );
 					break;
 
+				default:
+					break;
+
 			}
 
 		}
@@ -4095,8 +4132,17 @@ THREE.ColladaLoader = function () {
 			switch ( child.nodeName ) {
 
 				case 'technique_common':
+
+					this.parseCommon( child );
+					break;
+
+				case 'technique':
+
 					this.parseTechnique( child );
 					break;
+					
+				default:
+					break;
 
 			}
 
@@ -4106,43 +4152,71 @@ THREE.ColladaLoader = function () {
 
 	};
 
-	Light.prototype.parseTechnique = function ( element ) {
+	Light.prototype.parseCommon = function ( element ) {
 
 		for ( var i = 0; i < element.childNodes.length; i ++ ) {
 
-			var child = element.childNodes[ i ];
-
-			switch ( child.nodeName ) {
-
-				case 'ambient':
-				case 'point':
-				case 'directional':
-
-					this.technique = child.nodeName;
+			switch ( element.childNodes[ i ].nodeName ) 
+			{
+				case 'directional' :
+				case 'point' :
+				case 'spot' :
+				case 'ambient' :
+					
+					this.technique = element.childNodes[ i ].nodeName;
+					var light = element.childNodes[ i ];
+	
+					for ( var j = 0; j < light.childNodes.length; j ++ ) {
+	
+						var child = light.childNodes[j];
+						switch (child.nodeName)
+						{
+							case 'color' :
+								
+								var rgba = _floats( child.textContent );
+								this.color = new THREE.Color(0);
+								this.color.setRGB( rgba[0], rgba[1], rgba[2] );
+								this.color.a = rgba[3];
+								break;
+								
+							case 'falloff_angle' :
+								
+								this.falloff_angle = parseFloat( child.textContent );
+		
+								break;
+						}		
+					}
 
-					for ( var k = 0; k < child.childNodes.length; k ++ ) {
+			}
 
-						var param = child.childNodes[ k ];
+		}
 
-						switch ( param.nodeName ) {
+		return this;
 
-							case 'color':
-								var vector = new THREE.Vector3().fromArray( _floats( param.textContent ) );
-								this.color = new THREE.Color().setRGB( vector.x, vector.y, vector.z );
-								break;
+	};
 
-						}
+	Light.prototype.parseTechnique = function ( element ) {
 
-					}
+		this.profile = element.getAttribute('profile');
+		
+		for ( var i = 0; i < element.childNodes.length; i ++ ) {
 
-				break;
+			var child = element.childNodes[ i ];
+			switch ( child.nodeName ) 
+			{
+				case 'intensity' :
+					
+					this.intensity = parseFloat(child.textContent);
+					break;
 
 			}
 
 		}
 
-	};
+		return this;
 
+	};
+	
 	function InstanceLight() {
 
 		this.url = "";
@@ -4156,7 +4230,7 @@ THREE.ColladaLoader = function () {
 		return this;
 
 	};
-
+	
 	function _source( element ) {
 
 		var id = element.getAttribute( 'id' );