Skip to content

Commit d31b784

Browse files
authored
Merge pull request #16940 from Mugen87/dev36
VRMLLoader: Handle invalid geometry definitions.
2 parents 8ef029d + a62b6d4 commit d31b784

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

examples/js/loaders/VRMLLoader.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ THREE.VRMLLoader = ( function () {
929929

930930
var object;
931931

932-
if ( geometry ) {
932+
if ( geometry && geometry.attributes.position ) {
933933

934934
var type = geometry._type;
935935

@@ -1003,7 +1003,7 @@ THREE.VRMLLoader = ( function () {
10031003

10041004
object = new THREE.Object3D();
10051005

1006-
// if the geometry field is NULL the object is not drawn
1006+
// if the geometry field is NULL or no vertices are defined the object is not drawn
10071007

10081008
object.visible = false;
10091009

@@ -1353,6 +1353,14 @@ THREE.VRMLLoader = ( function () {
13531353

13541354
}
13551355

1356+
if ( coordIndex === undefined ) {
1357+
1358+
console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
1359+
1360+
return new THREE.BufferGeometry(); // handle VRML files with incomplete geometry definition
1361+
1362+
}
1363+
13561364
var triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
13571365

13581366
var positionAttribute;
@@ -1364,7 +1372,7 @@ THREE.VRMLLoader = ( function () {
13641372

13651373
if ( colorPerVertex === true ) {
13661374

1367-
if ( colorIndex.length > 0 ) {
1375+
if ( colorIndex && colorIndex.length > 0 ) {
13681376

13691377
// if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
13701378

@@ -1381,7 +1389,7 @@ THREE.VRMLLoader = ( function () {
13811389

13821390
} else {
13831391

1384-
if ( colorIndex.length > 0 ) {
1392+
if ( colorIndex && colorIndex.length > 0 ) {
13851393

13861394
// if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
13871395

@@ -1409,7 +1417,7 @@ THREE.VRMLLoader = ( function () {
14091417

14101418
// consider vertex normals
14111419

1412-
if ( normalIndex.length > 0 ) {
1420+
if ( normalIndex && normalIndex.length > 0 ) {
14131421

14141422
// if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
14151423

@@ -1428,7 +1436,7 @@ THREE.VRMLLoader = ( function () {
14281436

14291437
// consider face normals
14301438

1431-
if ( normalIndex.length > 0 ) {
1439+
if ( normalIndex && normalIndex.length > 0 ) {
14321440

14331441
// if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
14341442

@@ -1459,7 +1467,7 @@ THREE.VRMLLoader = ( function () {
14591467

14601468
// texture coordinates are always defined on vertex level
14611469

1462-
if ( texCoordIndex.length > 0 ) {
1470+
if ( texCoordIndex && texCoordIndex.length > 0 ) {
14631471

14641472
// if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
14651473

examples/jsm/loaders/VRMLLoader.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ var VRMLLoader = ( function () {
963963

964964
var object;
965965

966-
if ( geometry ) {
966+
if ( geometry && geometry.attributes.position ) {
967967

968968
var type = geometry._type;
969969

@@ -1037,7 +1037,7 @@ var VRMLLoader = ( function () {
10371037

10381038
object = new Object3D();
10391039

1040-
// if the geometry field is NULL the object is not drawn
1040+
// if the geometry field is NULL or no vertices are defined the object is not drawn
10411041

10421042
object.visible = false;
10431043

@@ -1387,6 +1387,14 @@ var VRMLLoader = ( function () {
13871387

13881388
}
13891389

1390+
if ( coordIndex === undefined ) {
1391+
1392+
console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
1393+
1394+
return new BufferGeometry(); // handle VRML files with incomplete geometry definition
1395+
1396+
}
1397+
13901398
var triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
13911399

13921400
var positionAttribute;
@@ -1398,7 +1406,7 @@ var VRMLLoader = ( function () {
13981406

13991407
if ( colorPerVertex === true ) {
14001408

1401-
if ( colorIndex.length > 0 ) {
1409+
if ( colorIndex && colorIndex.length > 0 ) {
14021410

14031411
// if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
14041412

@@ -1415,7 +1423,7 @@ var VRMLLoader = ( function () {
14151423

14161424
} else {
14171425

1418-
if ( colorIndex.length > 0 ) {
1426+
if ( colorIndex && colorIndex.length > 0 ) {
14191427

14201428
// if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
14211429

@@ -1443,7 +1451,7 @@ var VRMLLoader = ( function () {
14431451

14441452
// consider vertex normals
14451453

1446-
if ( normalIndex.length > 0 ) {
1454+
if ( normalIndex && normalIndex.length > 0 ) {
14471455

14481456
// if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
14491457

@@ -1462,7 +1470,7 @@ var VRMLLoader = ( function () {
14621470

14631471
// consider face normals
14641472

1465-
if ( normalIndex.length > 0 ) {
1473+
if ( normalIndex && normalIndex.length > 0 ) {
14661474

14671475
// if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
14681476

@@ -1493,7 +1501,7 @@ var VRMLLoader = ( function () {
14931501

14941502
// texture coordinates are always defined on vertex level
14951503

1496-
if ( texCoordIndex.length > 0 ) {
1504+
if ( texCoordIndex && texCoordIndex.length > 0 ) {
14971505

14981506
// if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
14991507

0 commit comments

Comments
 (0)