|
@@ -633,14 +633,14 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( 'AmbientLight' === data.nodeType ) {
|
|
|
|
|
|
+ if ( data.nodeType === 'AmbientLight' ) {
|
|
|
|
|
|
object = new THREE.AmbientLight( l_color, l_intensity );
|
|
object = new THREE.AmbientLight( l_color, l_intensity );
|
|
object.visible = l_visible;
|
|
object.visible = l_visible;
|
|
|
|
|
|
parent.add( object );
|
|
parent.add( object );
|
|
|
|
|
|
- } else if ( 'PointLight' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'PointLight' ) {
|
|
|
|
|
|
var l_distance = 0;
|
|
var l_distance = 0;
|
|
|
|
|
|
@@ -655,7 +655,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
parent.add( object );
|
|
parent.add( object );
|
|
|
|
|
|
- } else if ( 'SpotLight' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'SpotLight' ) {
|
|
|
|
|
|
var l_intensity = 1;
|
|
var l_intensity = 1;
|
|
var l_distance = 0;
|
|
var l_distance = 0;
|
|
@@ -680,7 +680,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
parent.add( object );
|
|
parent.add( object );
|
|
|
|
|
|
- } else if ( 'Transform' === data.nodeType || 'Group' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'Transform' || data.nodeType === 'Group' ) {
|
|
|
|
|
|
object = new THREE.Object3D();
|
|
object = new THREE.Object3D();
|
|
|
|
|
|
@@ -691,7 +691,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== data[ 'translation' ] ) {
|
|
|
|
|
|
+ if ( data.translation !== undefined ) {
|
|
|
|
|
|
var t = data.translation;
|
|
var t = data.translation;
|
|
|
|
|
|
@@ -699,7 +699,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== data.rotation ) {
|
|
|
|
|
|
+ if ( data.rotation !== undefined ) {
|
|
|
|
|
|
var r = data.rotation;
|
|
var r = data.rotation;
|
|
|
|
|
|
@@ -707,7 +707,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== data.scale ) {
|
|
|
|
|
|
+ if ( data.scale !== undefined ) {
|
|
|
|
|
|
var s = data.scale;
|
|
var s = data.scale;
|
|
|
|
|
|
@@ -717,7 +717,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
parent.add( object );
|
|
parent.add( object );
|
|
|
|
|
|
- } else if ( 'Shape' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'Shape' ) {
|
|
|
|
|
|
object = new THREE.Mesh();
|
|
object = new THREE.Mesh();
|
|
|
|
|
|
@@ -731,7 +731,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
parent.add( object );
|
|
parent.add( object );
|
|
|
|
|
|
- } else if ( 'Background' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'Background' ) {
|
|
|
|
|
|
var segments = 20;
|
|
var segments = 20;
|
|
|
|
|
|
@@ -774,25 +774,25 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
} else if ( /geometry/.exec( data.string ) ) {
|
|
} else if ( /geometry/.exec( data.string ) ) {
|
|
|
|
|
|
- if ( 'Box' === data.nodeType ) {
|
|
|
|
|
|
+ if ( data.nodeType === 'Box' ) {
|
|
|
|
|
|
var s = data.size;
|
|
var s = data.size;
|
|
|
|
|
|
parent.geometry = new THREE.BoxBufferGeometry( s.x, s.y, s.z );
|
|
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 );
|
|
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 );
|
|
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 );
|
|
parent.geometry = new THREE.SphereBufferGeometry( data.radius );
|
|
|
|
|
|
- } else if ( 'IndexedFaceSet' === data.nodeType ) {
|
|
|
|
|
|
+ } else if ( data.nodeType === 'IndexedFaceSet' ) {
|
|
|
|
|
|
var geometry = new THREE.BufferGeometry();
|
|
var geometry = new THREE.BufferGeometry();
|
|
|
|
|
|
@@ -809,7 +809,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
// uvs
|
|
// uvs
|
|
|
|
|
|
- if ( 'TextureCoordinate' === child.nodeType ) {
|
|
|
|
|
|
+ if ( child.nodeType === 'TextureCoordinate' ) {
|
|
|
|
|
|
if ( child.points ) {
|
|
if ( child.points ) {
|
|
|
|
|
|
@@ -826,7 +826,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
// positions
|
|
// positions
|
|
|
|
|
|
- if ( 'Coordinate' === child.nodeType ) {
|
|
|
|
|
|
+ if ( child.nodeType === 'Coordinate' ) {
|
|
|
|
|
|
if ( child.points ) {
|
|
if ( child.points ) {
|
|
|
|
|
|
@@ -881,6 +881,8 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
while ( indexes.length >= 3 && skip < ( indexes.length - 2 ) ) {
|
|
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 i1 = indexes[ 0 ];
|
|
var i2 = indexes[ skip + ( data.ccw ? 1 : 2 ) ];
|
|
var i2 = indexes[ skip + ( data.ccw ? 1 : 2 ) ];
|
|
var i3 = indexes[ skip + ( data.ccw ? 2 : 1 ) ];
|
|
var i3 = indexes[ skip + ( data.ccw ? 2 : 1 ) ];
|
|
@@ -959,11 +961,11 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
var child = data.children[ i ];
|
|
var child = data.children[ i ];
|
|
|
|
|
|
- if ( 'Material' === child.nodeType ) {
|
|
|
|
|
|
+ if ( child.nodeType === 'Material' ) {
|
|
|
|
|
|
var material = new THREE.MeshPhongMaterial();
|
|
var material = new THREE.MeshPhongMaterial();
|
|
|
|
|
|
- if ( undefined !== child.diffuseColor ) {
|
|
|
|
|
|
+ if ( child.diffuseColor !== undefined ) {
|
|
|
|
|
|
var d = child.diffuseColor;
|
|
var d = child.diffuseColor;
|
|
|
|
|
|
@@ -971,7 +973,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== child.emissiveColor ) {
|
|
|
|
|
|
+ if ( child.emissiveColor !== undefined ) {
|
|
|
|
|
|
var e = child.emissiveColor;
|
|
var e = child.emissiveColor;
|
|
|
|
|
|
@@ -979,7 +981,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== child.specularColor ) {
|
|
|
|
|
|
+ if ( child.specularColor !== undefined ) {
|
|
|
|
|
|
var s = child.specularColor;
|
|
var s = child.specularColor;
|
|
|
|
|
|
@@ -987,7 +989,7 @@ THREE.VRMLLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( undefined !== child.transparency ) {
|
|
|
|
|
|
+ if ( child.transparency !== undefined ) {
|
|
|
|
|
|
var t = child.transparency;
|
|
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 ] );
|
|
var textureName = /"([^"]+)"/.exec( child.children[ 0 ] );
|
|
|
|
|
|
@@ -1047,41 +1049,49 @@ THREE.VRMLLoader.prototype = {
|
|
var lines = data.split( '\n' );
|
|
var lines = data.split( '\n' );
|
|
|
|
|
|
// some lines do not have breaks
|
|
// some lines do not have breaks
|
|
|
|
+
|
|
for ( var i = lines.length - 1; i > - 1; i -- ) {
|
|
for ( var i = lines.length - 1; i > - 1; i -- ) {
|
|
|
|
|
|
|
|
+ var line = lines[ i ];
|
|
|
|
+
|
|
// split lines with {..{ or {..[ - some have both
|
|
// 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( 1 );
|
|
parts.unshift( i );
|
|
parts.unshift( i );
|
|
lines.splice.apply( lines, parts );
|
|
lines.splice.apply( lines, parts );
|
|
|
|
|
|
- } else if ( /\].*}/.test( lines[ i ] ) ) {
|
|
|
|
|
|
+ } else if ( /\].*}/.test( line ) ) {
|
|
|
|
|
|
// split lines with ]..}
|
|
// 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( 1 );
|
|
parts.unshift( i );
|
|
parts.unshift( i );
|
|
lines.splice.apply( lines, parts );
|
|
lines.splice.apply( lines, parts );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if ( /}.*}/.test( lines[ i ] ) ) {
|
|
|
|
|
|
+ if ( /}.*}/.test( line ) ) {
|
|
|
|
|
|
// split lines with }..}
|
|
// 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( 1 );
|
|
parts.unshift( i );
|
|
parts.unshift( i );
|
|
lines.splice.apply( lines, parts );
|
|
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 {}';
|
|
lines[ i ] += ' Coordinate {}';
|
|
|
|
|