Pārlūkot izejas kodu

Merge pull request #12462 from looeee/FBXLoader_consistent_property_type_parsing

FBXLoader consistent property type parsing
Mr.doob 7 gadi atpakaļ
vecāks
revīzija
ad5c0eb52e
1 mainītis faili ar 38 papildinājumiem un 60 dzēšanām
  1. 38 60
      examples/js/loaders/FBXLoader.js

+ 38 - 60
examples/js/loaders/FBXLoader.js

@@ -383,12 +383,6 @@
 
 
 			var values = textureNode.properties.Scaling.value;
 			var values = textureNode.properties.Scaling.value;
 
 
-			if ( typeof values === 'string' ) {
-
-				values = parseFloatArray( values );
-
-			}
-
 			texture.repeat.x = values[ 0 ];
 			texture.repeat.x = values[ 0 ];
 			texture.repeat.y = values[ 1 ];
 			texture.repeat.y = values[ 1 ];
 
 
@@ -497,7 +491,7 @@
 
 
 		if ( properties.BumpFactor ) {
 		if ( properties.BumpFactor ) {
 
 
-			parameters.bumpScale = parseFloat( properties.BumpFactor.value );
+			parameters.bumpScale = properties.BumpFactor.value;
 
 
 		}
 		}
 		if ( properties.Diffuse ) {
 		if ( properties.Diffuse ) {
@@ -507,12 +501,12 @@
 		}
 		}
 		if ( properties.DisplacementFactor ) {
 		if ( properties.DisplacementFactor ) {
 
 
-			parameters.displacementScale = parseFloat( properties.DisplacementFactor.value );
+			parameters.displacementScale = properties.DisplacementFactor.value;
 
 
 		}
 		}
 		if ( properties.ReflectionFactor ) {
 		if ( properties.ReflectionFactor ) {
 
 
-			parameters.reflectivity = parseFloat( properties.ReflectionFactor.value );
+			parameters.reflectivity = properties.ReflectionFactor.value;
 
 
 		}
 		}
 		if ( properties.Specular ) {
 		if ( properties.Specular ) {
@@ -522,7 +516,7 @@
 		}
 		}
 		if ( properties.Shininess ) {
 		if ( properties.Shininess ) {
 
 
-			parameters.shininess = parseFloat( properties.Shininess.value );
+			parameters.shininess = properties.Shininess.value;
 
 
 		}
 		}
 		if ( properties.Emissive ) {
 		if ( properties.Emissive ) {
@@ -1481,7 +1475,7 @@
 						} else {
 						} else {
 
 
 							var type = 0;
 							var type = 0;
-							if ( cameraAttribute.CameraProjectionType !== undefined && ( cameraAttribute.CameraProjectionType.value === '1' || cameraAttribute.CameraProjectionType.value === 1 ) ) {
+							if ( cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1 ) {
 
 
 								type = 1;
 								type = 1;
 
 
@@ -1507,8 +1501,8 @@
 
 
 							if ( cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined ) {
 							if ( cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined ) {
 
 
-								width = parseFloat( cameraAttribute.AspectWidth.value );
-								height = parseFloat( cameraAttribute.AspectHeight.value );
+								width = cameraAttribute.AspectWidth.value;
+								height = cameraAttribute.AspectHeight.value;
 
 
 							}
 							}
 
 
@@ -1517,19 +1511,17 @@
 							var fov = 45;
 							var fov = 45;
 							if ( cameraAttribute.FieldOfView !== undefined ) {
 							if ( cameraAttribute.FieldOfView !== undefined ) {
 
 
-								fov = parseFloat( cameraAttribute.FieldOfView.value );
+								fov = cameraAttribute.FieldOfView.value;
 
 
 							}
 							}
 
 
 							switch ( type ) {
 							switch ( type ) {
 
 
-								case '0': // Perspective
-								case 0:
+								case 0: // Perspective
 									model = new THREE.PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
 									model = new THREE.PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
 									break;
 									break;
 
 
-								case '1': // Orthographic
-								case 1:
+								case 1: // Orthographic
 									model = new THREE.OrthographicCamera( - width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane );
 									model = new THREE.OrthographicCamera( - width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane );
 									break;
 									break;
 
 
@@ -1591,20 +1583,14 @@
 
 
 							if ( lightAttribute.Color !== undefined ) {
 							if ( lightAttribute.Color !== undefined ) {
 
 
-								var temp = lightAttribute.Color.value.split( ',' );
-
-								var r = parseFloat( temp[ 0 ] );
-								var g = parseFloat( temp[ 1 ] );
-								var b = parseFloat( temp[ 1 ] );
-
-								color = new THREE.Color( r, g, b );
+								color = parseColor( lightAttribute.Color.value );
 
 
 							}
 							}
 
 
 							var intensity = ( lightAttribute.Intensity === undefined ) ? 1 : lightAttribute.Intensity.value / 100;
 							var intensity = ( lightAttribute.Intensity === undefined ) ? 1 : lightAttribute.Intensity.value / 100;
 
 
 							// light disabled
 							// light disabled
-							if ( lightAttribute.CastLightOnObject !== undefined && ( lightAttribute.CastLightOnObject.value === '0' || lightAttribute.CastLightOnObject.value === 0 ) ) {
+							if ( lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0 ) {
 
 
 								intensity = 0;
 								intensity = 0;
 
 
@@ -1613,7 +1599,7 @@
 							var distance = 0;
 							var distance = 0;
 							if ( lightAttribute.FarAttenuationEnd !== undefined ) {
 							if ( lightAttribute.FarAttenuationEnd !== undefined ) {
 
 
-								if ( lightAttribute.EnableFarAttenuation !== undefined && ( lightAttribute.EnableFarAttenuation.value === '0' || lightAttribute.EnableFarAttenuation.value === 0 ) ) {
+								if ( lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0 ) {
 
 
 									distance = 0;
 									distance = 0;
 
 
@@ -1631,18 +1617,15 @@
 
 
 							switch ( type ) {
 							switch ( type ) {
 
 
-								case '0': // Point
-								case 0:
+								case 0: // Point
 									model = new THREE.PointLight( color, intensity, distance, decay );
 									model = new THREE.PointLight( color, intensity, distance, decay );
 									break;
 									break;
 
 
-								case '1': // Directional
-								case 1:
+								case 1: // Directional
 									model = new THREE.DirectionalLight( color, intensity );
 									model = new THREE.DirectionalLight( color, intensity );
 									break;
 									break;
 
 
-								case '2': // Spot
-								case 2:
+								case 2: // Spot
 									var angle = Math.PI / 3;
 									var angle = Math.PI / 3;
 
 
 									if ( lightAttribute.InnerAngle !== undefined ) {
 									if ( lightAttribute.InnerAngle !== undefined ) {
@@ -1672,7 +1655,7 @@
 
 
 							}
 							}
 
 
-							if ( lightAttribute.CastShadows !== undefined && ( lightAttribute.CastShadows.value === '1' || lightAttribute.CastShadows.value === 1 ) ) {
+							if ( lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1 ) {
 
 
 								model.castShadow = true;
 								model.castShadow = true;
 
 
@@ -1798,13 +1781,13 @@
 
 
 			if ( 'Lcl_Translation' in node.properties ) {
 			if ( 'Lcl_Translation' in node.properties ) {
 
 
-				model.position.fromArray( parseFloatArray( node.properties.Lcl_Translation.value ) );
+				model.position.fromArray( node.properties.Lcl_Translation.value );
 
 
 			}
 			}
 
 
 			if ( 'Lcl_Rotation' in node.properties ) {
 			if ( 'Lcl_Rotation' in node.properties ) {
 
 
-				var rotation = parseFloatArray( node.properties.Lcl_Rotation.value ).map( degreeToRadian );
+				var rotation = node.properties.Lcl_Rotation.value.map( degreeToRadian );
 				rotation.push( 'ZYX' );
 				rotation.push( 'ZYX' );
 				model.rotation.fromArray( rotation );
 				model.rotation.fromArray( rotation );
 
 
@@ -1812,7 +1795,7 @@
 
 
 			if ( 'Lcl_Scaling' in node.properties ) {
 			if ( 'Lcl_Scaling' in node.properties ) {
 
 
-				model.scale.fromArray( parseFloatArray( node.properties.Lcl_Scaling.value ) );
+				model.scale.fromArray( node.properties.Lcl_Scaling.value );
 
 
 			}
 			}
 
 
@@ -1857,11 +1840,7 @@
 
 
 						if ( 'Lcl_Translation' in lookAtTarget.properties ) {
 						if ( 'Lcl_Translation' in lookAtTarget.properties ) {
 
 
-							var pos = lookAtTarget.properties.Lcl_Translation.value.split( ',' ).map( function ( val ) {
-
-								return parseFloat( val );
-
-							} );
+							var pos = lookAtTarget.properties.Lcl_Translation.value;
 
 
 							// DirectionalLight, SpotLight
 							// DirectionalLight, SpotLight
 							if ( model.target !== undefined ) {
 							if ( model.target !== undefined ) {
@@ -2083,7 +2062,7 @@
 
 
 				if ( 'CustomFrameRate' in FBXTree.GlobalSettings.properties ) {
 				if ( 'CustomFrameRate' in FBXTree.GlobalSettings.properties ) {
 
 
-					fps = parseFloat( FBXTree.GlobalSettings.properties.CustomFrameRate.value );
+					fps = FBXTree.GlobalSettings.properties.CustomFrameRate.value;
 
 
 					fps = ( fps === - 1 ) ? 30 : fps;
 					fps = ( fps === - 1 ) ? 30 : fps;
 
 
@@ -4166,7 +4145,6 @@
 
 
 		parseNodeBegin: function ( line, nodeName, nodeAttrs ) {
 		parseNodeBegin: function ( line, nodeName, nodeAttrs ) {
 
 
-			// var nodeName = match[1];
 			var node = { 'name': nodeName, properties: {}, 'subNodes': {} };
 			var node = { 'name': nodeName, properties: {}, 'subNodes': {} };
 			var attrs = this.parseNodeAttr( nodeAttrs );
 			var attrs = this.parseNodeAttr( nodeAttrs );
 			var currentNode = this.getCurrentNode();
 			var currentNode = this.getCurrentNode();
@@ -4176,11 +4154,9 @@
 
 
 				this.allNodes.add( nodeName, node );
 				this.allNodes.add( nodeName, node );
 
 
-			} else {
-
-				// a subnode
+			} else { // a subnode
 
 
-				// already exists subnode, then append it
+				// if the subnode already exists, append it
 				if ( nodeName in currentNode.subNodes ) {
 				if ( nodeName in currentNode.subNodes ) {
 
 
 					var tmp = currentNode.subNodes[ nodeName ];
 					var tmp = currentNode.subNodes[ nodeName ];
@@ -4226,6 +4202,7 @@
 
 
 			}
 			}
 
 
+
 			// for this		  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 			// for this		  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 			// NodeAttribute: 1001463072, "NodeAttribute::", "LimbNode" {
 			// NodeAttribute: 1001463072, "NodeAttribute::", "LimbNode" {
 			if ( nodeAttrs ) {
 			if ( nodeAttrs ) {
@@ -4275,8 +4252,8 @@
 			var currentNode = this.getCurrentNode();
 			var currentNode = this.getCurrentNode();
 			var parentName = currentNode.name;
 			var parentName = currentNode.name;
 
 
-			// special case parent node's is like "Properties70"
-			// these children nodes must treat with careful
+			// special case where the parent node is something like "Properties70"
+			// these children nodes must treated carefully
 			if ( parentName !== undefined ) {
 			if ( parentName !== undefined ) {
 
 
 				var propMatch = parentName.match( /Properties(\d)+/ );
 				var propMatch = parentName.match( /Properties(\d)+/ );
@@ -4289,7 +4266,7 @@
 
 
 			}
 			}
 
 
-			// special case Connections
+			// Connections
 			if ( propName === 'C' ) {
 			if ( propName === 'C' ) {
 
 
 				var connProps = propValue.split( ',' ).slice( 1 );
 				var connProps = propValue.split( ',' ).slice( 1 );
@@ -4316,7 +4293,7 @@
 
 
 			}
 			}
 
 
-			// special case Connections
+			// Node
 			if ( propName === 'Node' ) {
 			if ( propName === 'Node' ) {
 
 
 				var id = parseInt( propValue );
 				var id = parseInt( propValue );
@@ -4341,7 +4318,6 @@
 
 
 			} else {
 			} else {
 
 
-				// console.log( propName + ":  " + propValue );
 				if ( Array.isArray( currentNode.properties[ propName ] ) ) {
 				if ( Array.isArray( currentNode.properties[ propName ] ) ) {
 
 
 					currentNode.properties[ propName ].push( propValue );
 					currentNode.properties[ propName ].push( propValue );
@@ -4391,19 +4367,27 @@
 			}
 			}
 			*/
 			*/
 
 
-			// cast value in its type
+			// cast value to its type
 			switch ( innerPropType1 ) {
 			switch ( innerPropType1 ) {
 
 
 				case 'int':
 				case 'int':
+				case 'enum':
+				case 'bool':
+				case 'ULongLong':
 					innerPropValue = parseInt( innerPropValue );
 					innerPropValue = parseInt( innerPropValue );
 					break;
 					break;
 
 
 				case 'double':
 				case 'double':
+				case 'Number':
+				case 'FieldOfView':
 					innerPropValue = parseFloat( innerPropValue );
 					innerPropValue = parseFloat( innerPropValue );
 					break;
 					break;
 
 
 				case 'ColorRGB':
 				case 'ColorRGB':
 				case 'Vector3D':
 				case 'Vector3D':
+				case 'Lcl_Translation':
+				case 'Lcl_Rotation':
+				case 'Lcl_Scaling':
 					innerPropValue = parseFloatArray( innerPropValue );
 					innerPropValue = parseFloatArray( innerPropValue );
 					break;
 					break;
 
 
@@ -4655,12 +4639,6 @@
 
 
 					}
 					}
 
 
-					if ( innerPropType1.indexOf( 'Lcl_' ) === 0 ) {
-
-						innerPropValue = innerPropValue.toString();
-
-					}
-
 					// this will be copied to parent. see above.
 					// this will be copied to parent. see above.
 					properties[ innerPropName ] = {
 					properties[ innerPropName ] = {