Skip to content

MaterialXLoader: Only resolve loading promises when all sub-resources are loaded. - #34439

Merged
Mugen87 merged 14 commits into
mrdoob:devfrom
bhouston:materialx-loader-fix
Sep 11, 2026
Merged

Mugen87 merged 14 commits into
mrdoob:devfrom
bhouston:materialx-loader-fix

Conversation

@bhouston

@bhouston bhouston commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Currently, MaterialXLoader.load() calls onLoad after parsing and translating the MaterialX document, while image-backed nodes continue loading their textures. loadAsync() therefore resolves before those textures have image data.

Fix

This PR makes load() and loadAsync() wait for every resource request started during MaterialX translation. When either API reports completion, referenced textures have finished loading and the material is ready for immediate use.

The loader follows the resource lifecycle established by GLTFLoader:

  • onLoad and loadAsync() complete after dependent textures settle.
  • A root LoadingManager item remains active through parsing, resource loading, and the loader callback.
  • Loader failures call LoadingManager.itemError() and close the root item.
  • The loader's onProgress callback reports the MaterialX document transfer.
  • LoadingManager.onProgress reports dependent texture requests.

Direct calls to the synchronous parse() API retain their existing behavior.

Demo

Current behavior - totems appear without textures and then those pop in: https://threejs.org/examples/webgpu_loader_materialx.html

New behavior - clean display of each totems after its material is fully loaded: https://rawcdn.githack.com/mrdoob/three.js/de4e1a23eabfeef69224fdf5874abbdb98b99c37/examples/webgpu_loader_materialx.html

@bhouston
bhouston force-pushed the materialx-loader-fix branch from e6ee24c to abbc2df Compare September 2, 2026 18:08
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

πŸ–ΌοΈ E2E screenshot tests

βœ… All examples render correctly again (run).

Let callers await image-backed MaterialX texture loads and inspect the raw parsed graph without relying on loader internals or render-loop timing.
Keep the texture-readiness branch focused by removing raw graph access and texcoord compile-context indirection for separate review.
Attach parsed MaterialX graph handles to generated materials so tools can inspect authoring data after TSL translation.
Route MaterialX texcoord nodes through a compile-context hook so UV-space handling has one shared entry point.
@bhouston
bhouston force-pushed the materialx-loader-fix branch from 5c6d424 to de4e1a2 Compare September 9, 2026 15:09
Expose the parsed MaterialXDocument on the loader's result instead of
attaching graph references to each material. materials are keyed by
name, and document.getMaterialXNode(name) looks up the matching raw
graph node using that same name.
@bhouston bhouston changed the title Align MaterialXLoader with glTFLoader behavior: only resolve when all sub-resources are loaded Fix MaterialXLoader bug: Only resolve loading promises when all sub-resources are loaded Sep 9, 2026

const material = result.materials.test_material;

assert.false( 'texturesReady' in result, 'The result does not expose a separate readiness promise.' );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a left-over?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed.

Comment thread examples/webgpu_loader_materialx.html Resolved
Comment thread examples/webgpu_loader_materialx.html Resolved
Comment thread examples/jsm/loaders/MaterialXLoader.js Resolved
- Test: import LoadingManager from 'three' instead of the build bundle
- Test: drop the leftover 'texturesReady' assertion
- MaterialXDocument: stop exposing the raw document on parse() results
- MaterialXLog: TEXTURE_LOAD_FAILED is now a warning, matching GLTFLoader
- Example: restore the Calibration/Preview mesh GUI, remove window.TESTING
Downgrading TEXTURE_LOAD_FAILED to a warning (per review feedback) means
a failed texture no longer rejects load()/loadAsync() by default. Update
the test to assert the new GLTFLoader-like behavior instead of the old
throwOnErrors/rejection expectation, which was failing CI.
@Mugen87 Mugen87 added this to the r187 milestone Sep 11, 2026
@Mugen87 Mugen87 changed the title Fix MaterialXLoader bug: Only resolve loading promises when all sub-resources are loaded MaterialXLoader: Only resolve loading promises when all sub-resources are loaded. Sep 11, 2026
@Mugen87
Mugen87 merged commit 80a057a into mrdoob:dev Sep 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants