瀏覽代碼

Merge pull request #12265 from Mugen87/dev

VRMLLoader: Fix for #12209
Mr.doob 7 年之前
父節點
當前提交
c09304fdfa
共有 1 個文件被更改,包括 42 次插入32 次删除
  1. 42 32
      examples/js/loaders/VRMLLoader.js

+ 42 - 32
examples/js/loaders/VRMLLoader.js

@@ -633,14 +633,14 @@ THREE.VRMLLoader.prototype = {
 
 				}
 
-				if ( 'AmbientLight' === data.nodeType ) {
+				if ( data.nodeType === 'AmbientLight' ) {
 
 					object = new THREE.AmbientLight( l_color, l_intensity );
 					object.visible = l_visible;
 
 					parent.add( object );
 
-				} else if ( 'PointLight' === data.nodeType ) {
+				} else if ( data.nodeType === 'PointLight' ) {
 
 					var l_distance = 0;
 
@@ -655,7 +655,7 @@ THREE.VRMLLoader.prototype = {
 
 					parent.add( object );
 
-				} else if ( 'SpotLight' === data.nodeType ) {
+				} else if ( data.nodeType === 'SpotLight' ) {
 
 					var l_intensity = 1;
 					var l_distance = 0;
@@ -680,7 +680,7 @@ THREE.VRMLLoader.prototype = {
 
 					parent.add( object );
 
-				} else if ( 'Transform' === data.nodeType || 'Group' === data.nodeType ) {
+				} else if ( data.nodeType === 'Transform' || data.nodeType === 'Group' ) {
 
 					object = new THREE.Object3D();
 
@@ -691,7 +691,7 @@ THREE.VRMLLoader.prototype = {
 
 					}
 
-					if ( undefined !== data[ 'translation' ] ) {
+					if ( data.translation !== undefined ) {
 
 						var t = data.translation;
 
@@ -699,7 +699,7 @@ THREE.VRMLLoader.prototype = {
 
 					}
 
-					if ( undefined !== data.rotation ) {
+					if ( data.rotation !== undefined ) {
 
 						var r = data.rotation;
 
@@ -707,7 +707,7 @@ THREE.VRMLLoader.prototype = {
 
 					}
 
-					if ( undefined !== data.scale ) {
+					if ( data.scale !== undefined ) {
 
 						var s = data.scale;
 
@@ -717,7 +717,7 @@ THREE.VRMLLoader.prototype = {
 
 					parent.add( object );
 
-				} else if ( 'Shape' === data.nodeType ) {
+				} else if ( data.nodeType === 'Shape' ) {
 
 					object = new THREE.Mesh();
 
@@ -731,7 +731,7 @@ THREE.VRMLLoader.prototype = {
 
 					parent.add( object );
 
-				} else if ( 'Background' === data.nodeType ) {
+				} else if ( data.nodeType === 'Background' ) {
 
 					var segments = 20;
 
@@ -774,25 +774,25 @@ THREE.VRMLLoader.prototype = {
 
 				} else if ( /geometry/.exec( data.string ) ) {
 
-					if ( 'Box' === data.nodeType ) {
+					if ( data.nodeType === 'Box' ) {
 
 						var s = data.size;
 
 						parent.geometry = new THREE.BoxBufferGeometry( s.x, s.y, s.z );
 
-					} else if ( 'Cylinder' === data.nodeType ) {
+					} else if ( data.nodeType === 'Cylinder' ) {
 
 						parent.geometry = new THREE.CylinderBufferGeometry( data.radius, data.radius, data.height );
 
-					} else if ( 'Cone' === data.nodeType ) {
+					} else if ( data.nodeType === 'Cone' ) {
 
 						parent.geometry = new THREE.CylinderBufferGeometry( data.topRadius, data.bottomRadius, data.height );
 
-					} else if ( 'Sphere' === data.nodeType ) {
+					} else if ( data.nodeType === 'Sphere' ) {
 
 						parent.geometry = new THREE.SphereBufferGeometry( data.radius );
 
-					} else if ( 'IndexedFaceSet' === data.nodeType ) {
+					} else if ( data.nodeType === 'IndexedFaceSet' ) {
 
 						var geometry = new THREE.BufferGeometry();
 
@@ -809,7 +809,7 @@ THREE.VRMLLoader.prototype = {
 
 							// uvs
 
-							if ( 'TextureCoordinate' === child.nodeType ) {
+							if ( child.nodeType === 'TextureCoordinate' ) {
 
 								if ( child.points ) {
 
@@ -826,7 +826,7 @@ THREE.VRMLLoader.prototype = {
 
 							// positions
 
-							if ( 'Coordinate' === child.nodeType ) {
+							if ( child.nodeType === 'Coordinate' ) {
 
 								if ( child.points ) {
 
@@ -881,6 +881,8 @@ THREE.VRMLLoader.prototype = {
 
 								while ( indexes.length >= 3 && skip < ( indexes.length - 2 ) ) {
 
+									if ( data.ccw === undefined ) data.ccw = true; // ccw is true by default
+
 									var i1 = indexes[ 0 ];
 									var i2 = indexes[ skip + ( data.ccw ? 1 : 2 ) ];
 									var i3 = indexes[ skip + ( data.ccw ? 2 : 1 ) ];
@@ -959,11 +961,11 @@ THREE.VRMLLoader.prototype = {
 
 						var child = data.children[ i ];
 
-						if ( 'Material' === child.nodeType ) {
+						if ( child.nodeType === 'Material' ) {
 
 							var material = new THREE.MeshPhongMaterial();
 
-							if ( undefined !== child.diffuseColor ) {
+							if ( child.diffuseColor !== undefined ) {
 
 								var d = child.diffuseColor;
 
@@ -971,7 +973,7 @@ THREE.VRMLLoader.prototype = {
 
 							}
 
-							if ( undefined !== child.emissiveColor ) {
+							if ( child.emissiveColor !== undefined ) {
 
 								var e = child.emissiveColor;
 
@@ -979,7 +981,7 @@ THREE.VRMLLoader.prototype = {
 
 							}
 
-							if ( undefined !== child.specularColor ) {
+							if ( child.specularColor !== undefined ) {
 
 								var s = child.specularColor;
 
@@ -987,7 +989,7 @@ THREE.VRMLLoader.prototype = {
 
 							}
 
-							if ( undefined !== child.transparency ) {
+							if ( child.transparency !== undefined ) {
 
 								var t = child.transparency;
 
@@ -1010,7 +1012,7 @@ THREE.VRMLLoader.prototype = {
 
 						}
 
-						if ( 'ImageTexture' === child.nodeType ) {
+						if ( child.nodeType === 'ImageTexture' ) {
 
 							var textureName = /"([^"]+)"/.exec( child.children[ 0 ] );
 
@@ -1047,41 +1049,49 @@ THREE.VRMLLoader.prototype = {
 		var lines = data.split( '\n' );
 
 		// some lines do not have breaks
+
 		for ( var i = lines.length - 1; i > - 1; i -- ) {
 
+			var line = lines[ i ];
+
 			// split lines with {..{ or {..[ - some have both
-			if ( /{.*[{\[]/.test( lines[ i ] ) ) {
+			if ( /{.*[{\[]/.test( line ) ) {
 
-				var parts = lines[ i ].split( '{' ).join( '{\n' ).split( '\n' );
+				var parts = line.split( '{' ).join( '{\n' ).split( '\n' );
 				parts.unshift( 1 );
 				parts.unshift( i );
 				lines.splice.apply( lines, parts );
 
-			} else if ( /\].*}/.test( lines[ i ] ) ) {
+			} else if ( /\].*}/.test( line ) ) {
 
 				// split lines with ]..}
-				var parts = lines[ i ].split( ']' ).join( ']\n' ).split( '\n' );
+				var parts = line.split( ']' ).join( ']\n' ).split( '\n' );
 				parts.unshift( 1 );
 				parts.unshift( i );
 				lines.splice.apply( lines, parts );
 
 			}
 
-			if ( /}.*}/.test( lines[ i ] ) ) {
+			if ( /}.*}/.test( line ) ) {
 
 				// split lines with }..}
-
-				var parts = lines[ i ].split( '}' ).join( '}\n' ).split( '\n' );
+				var parts = line.split( '}' ).join( '}\n' ).split( '\n' );
 				parts.unshift( 1 );
 				parts.unshift( i );
 				lines.splice.apply( lines, parts );
 
 			}
 
-			// force the parser to create Coordinate node for empty coords
-			// coord USE something -> coord USE something Coordinate {}
+			if ( /^\b[^\s]+\b$/.test( line.trim() ) ) {
+
+				// prevent lines with single words like "coord" or "geometry", see #12209
+				lines[ i + 1 ] = line + ' ' + lines[ i + 1 ].trim();
+				lines.splice( i, 1 );
+
+			} else if ( ( line.indexOf( 'coord' ) > - 1 ) && ( line.indexOf( '[' ) < 0 ) && ( line.indexOf( '{' ) < 0 ) ) {
 
-			if ( ( lines[ i ].indexOf( 'coord' ) > - 1 ) && ( lines[ i ].indexOf( '[' ) < 0 ) && ( lines[ i ].indexOf( '{' ) < 0 ) ) {
+				// force the parser to create Coordinate node for empty coords
+				// coord USE something -> coord USE something Coordinate {}
 
 				lines[ i ] += ' Coordinate {}';