@needle-tools/three 0.162.9 → 0.162.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2318,6 +2318,8 @@ class GeometryParser {
|
|
|
2318
2318
|
// Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
|
|
2319
2319
|
parseVertexColors( ColorNode ) {
|
|
2320
2320
|
|
|
2321
|
+
if ( !ColorNode.Colors ) return undefined;
|
|
2322
|
+
|
|
2321
2323
|
const mappingType = ColorNode.MappingInformationType;
|
|
2322
2324
|
const referenceType = ColorNode.ReferenceInformationType;
|
|
2323
2325
|
const buffer = ColorNode.Colors.a;
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
Vector3,
|
|
15
15
|
Color
|
|
16
16
|
} from 'three';
|
|
17
|
+
import { MTLLoader } from './MTLLoader.js';
|
|
17
18
|
|
|
18
19
|
// o object_name | g group_name
|
|
19
20
|
const _object_pattern = /^[og]\s*(.+)?/;
|
|
@@ -440,6 +441,7 @@ class OBJLoader extends Loader {
|
|
|
440
441
|
super( manager );
|
|
441
442
|
|
|
442
443
|
this.materials = null;
|
|
444
|
+
this.materialsLoader = new MTLLoader( manager );
|
|
443
445
|
|
|
444
446
|
}
|
|
445
447
|
|
|
@@ -451,11 +453,30 @@ class OBJLoader extends Loader {
|
|
|
451
453
|
loader.setPath( this.path );
|
|
452
454
|
loader.setRequestHeader( this.requestHeader );
|
|
453
455
|
loader.setWithCredentials( this.withCredentials );
|
|
454
|
-
loader.load( url, function ( text ) {
|
|
456
|
+
loader.load( url, async function ( text ) {
|
|
455
457
|
|
|
456
458
|
try {
|
|
457
459
|
|
|
458
|
-
|
|
460
|
+
const state = scope.parse( text, true );
|
|
461
|
+
|
|
462
|
+
for ( let i = 0, l = state.materialLibraries.length; i < l; i ++ ) {
|
|
463
|
+
|
|
464
|
+
const mtlfile = state.materialLibraries[ i ];
|
|
465
|
+
|
|
466
|
+
const newUrl = new URL( mtlfile, url );
|
|
467
|
+
|
|
468
|
+
await (new Promise((resolve, reject) => {
|
|
469
|
+
scope.materialsLoader.load( newUrl.toString(), creator => {
|
|
470
|
+
|
|
471
|
+
scope.setMaterials( creator );
|
|
472
|
+
resolve();
|
|
473
|
+
|
|
474
|
+
}, null, reject );
|
|
475
|
+
}));
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
onLoad( scope.createObjects( state ) );
|
|
459
480
|
|
|
460
481
|
} catch ( e ) {
|
|
461
482
|
|
|
@@ -477,6 +498,14 @@ class OBJLoader extends Loader {
|
|
|
477
498
|
|
|
478
499
|
}
|
|
479
500
|
|
|
501
|
+
setMTLLoader ( loader ) {
|
|
502
|
+
|
|
503
|
+
this.materialsLoader = loader;
|
|
504
|
+
|
|
505
|
+
return this;
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
|
|
480
509
|
setMaterials( materials ) {
|
|
481
510
|
|
|
482
511
|
this.materials = materials;
|
|
@@ -485,7 +514,7 @@ class OBJLoader extends Loader {
|
|
|
485
514
|
|
|
486
515
|
}
|
|
487
516
|
|
|
488
|
-
parse( text ) {
|
|
517
|
+
parse( text, parseOnly = false ) {
|
|
489
518
|
|
|
490
519
|
const state = new ParserState();
|
|
491
520
|
|
|
@@ -715,6 +744,16 @@ class OBJLoader extends Loader {
|
|
|
715
744
|
|
|
716
745
|
state.finalize();
|
|
717
746
|
|
|
747
|
+
// If the method is called from the load() function we do first load materials before creating the objects
|
|
748
|
+
// This is to not modify the functionality of parse() e.g. by making it async
|
|
749
|
+
if ( parseOnly ) return state;
|
|
750
|
+
|
|
751
|
+
return this.createObjects(state);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
createObjects ( state ) {
|
|
756
|
+
|
|
718
757
|
const container = new Group();
|
|
719
758
|
container.materialLibraries = [].concat( state.materialLibraries );
|
|
720
759
|
|
|
@@ -897,9 +936,7 @@ class OBJLoader extends Loader {
|
|
|
897
936
|
}
|
|
898
937
|
|
|
899
938
|
return container;
|
|
900
|
-
|
|
901
939
|
}
|
|
902
|
-
|
|
903
940
|
}
|
|
904
941
|
|
|
905
942
|
export { OBJLoader };
|