Skip to content

Commit 154e145

Browse files
committed
MaterialXLoader: Use ImageBitmapLoader to prevent blocking.
1 parent 7527f40 commit 154e145

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

examples/jsm/loaders/MaterialXLoader.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
FileLoader, Loader, TextureLoader, RepeatWrapping, MeshBasicNodeMaterial,
2+
FileLoader, Loader, ImageBitmapLoader, Texture, RepeatWrapping, MeshBasicNodeMaterial,
33
MeshPhysicalNodeMaterial, DoubleSide,
44
} from 'three/webgpu';
55

@@ -410,9 +410,15 @@ class MaterialXNode {
410410
getTexture() {
411411

412412
const filePrefix = this.getRecursiveAttribute( 'fileprefix' ) || '';
413+
const uri = filePrefix + this.value;
414+
415+
if ( this.materialX.textureCache.has( uri ) ) {
416+
417+
return this.materialX.textureCache.get( uri );
418+
419+
}
413420

414421
let loader = this.materialX.textureLoader;
415-
const uri = filePrefix + this.value;
416422

417423
if ( uri ) {
418424

@@ -421,10 +427,19 @@ class MaterialXNode {
421427

422428
}
423429

424-
const texture = loader.load( uri );
430+
const texture = new Texture();
425431
texture.wrapS = texture.wrapT = RepeatWrapping;
426432
texture.flipY = false;
427433

434+
this.materialX.textureCache.set( uri, texture );
435+
436+
loader.load( uri, function ( imageBitmap ) {
437+
438+
texture.image = imageBitmap;
439+
texture.needsUpdate = true;
440+
441+
} );
442+
428443
return texture;
429444

430445
}
@@ -1030,7 +1045,10 @@ class MaterialX {
10301045
this.nodesXLib = new Map();
10311046
//this.nodesXRefLib = new WeakMap();
10321047

1033-
this.textureLoader = new TextureLoader( manager );
1048+
this.textureLoader = new ImageBitmapLoader( manager );
1049+
this.textureLoader.setOptions( { imageOrientation: 'flipY' } );
1050+
1051+
this.textureCache = new Map();
10341052

10351053
}
10361054

0 commit comments

Comments
 (0)