fix(viewer): preserve GLTF materials in ItemRenderer#246
Open
b9llach wants to merge 1 commit intopascalorg:mainfrom
Open
fix(viewer): preserve GLTF materials in ItemRenderer#246b9llach wants to merge 1 commit intopascalorg:mainfrom
b9llach wants to merge 1 commit intopascalorg:mainfrom
Conversation
`getMaterialForOriginal` returns `baseMaterial` (`#f2f0ed`, roughness 0.5) for every mesh regardless of its source material. The GLTF's original colors, textures, PBR properties, and per-mesh material variation are all thrown away. Every loaded model renders as a uniform cream-coloured shape. The intent was to convert `MeshStandardMaterial` (from GLTFLoader) to `MeshStandardNodeMaterial` (required by the WebGPU/TSL pipeline). The implementation returned a shared constant instead of converting. This rewrites the converter to build a real `MeshStandardNodeMaterial` from each original material, copying base color, roughness, metalness, emissive properties, opacity, side, vertex colors, and all texture maps. Properties are assigned explicitly after construction rather than passed through the constructor — `Material.setValues` silently drops certain fields on NodeMaterial subclasses (observed: `color` being ignored, producing white output for GLTFs whose material relies solely on `baseColorFactor`). Results are cached per original material via `WeakMap`. A double- conversion guard detects materials already replaced on a previous render and returns them as-is.
b8b1be8 to
f4676cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`getMaterialForOriginal` in `ItemRenderer` returns `baseMaterial` (`#f2f0ed`, roughness 0.5) for every mesh regardless of its source material. The GLTF's original colors, textures, PBR properties, and per-mesh material variation are all thrown away — every loaded model renders as a uniform cream-coloured shape with no visual distinction between parts.
The intent was to convert regular `MeshStandardMaterial` (from GLTFLoader) to `MeshStandardNodeMaterial` (required by the WebGPU/TSL pipeline). The implementation just returned a shared constant instead of actually converting the material's properties.
Fix
Rewrites `getMaterialForOriginal` to build a real `MeshStandardNodeMaterial` from each original material, copying:
Properties are assigned explicitly after construction rather than passed through the constructor — `Material.setValues` silently drops certain fields on NodeMaterial subclasses (observed: `color` being ignored, producing white output for GLTFs whose material relies solely on `baseColorFactor` like Kenney's low-poly kits).
Results are cached per original material via `WeakMap`. A double-conversion guard detects materials that have already been replaced with a NodeMaterial on a previous render and returns them as-is.
Scope
How to test
Checklist