Certain gltf models display incorrectly in three.js
See original GitHub issueDescribe the bug
Certain models now display incorrectly. These models used to display correctly. I noticed the change when updating from 0.108.0 to 0.121.1, however the issue appears to still happen in the latest three.js version. Some gLTF models display incorrectly in three.js since a recent update.
To Reproduce
Open this model in this three.js based gLTF viewer to see the problem.
The model displays fine in this alternate gLTF viewer.
Code
// code goes here
Platform:
- Device: Desktop
- OS: Windows
- Browser: Chrome
- Three.js version: latest
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Textures map incorrectly to gltf object - Questions - three.js forum
The model with embedded texture is showing correctly, but when I explicitly assing this texture to material, it starts showing incorrectly.
Read more >Incorrect bounds for glTF models with normalized positions ...
... it looks like three.js (as well as babylon.js, actually) is using the POSITION attribute's .min and .max property to infer bounds of...
Read more >GLTF model rendering incorrectly when aframe-effects added ...
That's probably caused by the postprocessing effects you're applying and how they combine. It's not related to the model. – Diego Marcos. Nov...
Read more >Three.js Loading a .GLTF File
At some level loading and displaying a gLTF file is simpler than an .OBJ file. ... <script src="resources/threejs/r105/js/loaders/GLTFLoader.js"></script>.
Read more >Three.js Import Model in GLTF/GLB Format From Blender ...
In this video, we learn how to import a 3D model into our Three. js project. The model in the video is one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/mrdoob/three.js/pull/18235 is the relevant change here. Despite the result you’re seeing here, it was a necessary and correct change. The model attached has two materials (output from
gltf-transform inspect car.gltf
) …Material #582
window
… note that both, not just the window material, are using alpha blending (or
material.transparent = true
). The change above fixed a number of issues with materials that are actually transparent, while unfortunately making it much more obvious when something that isn’t really transparent is marked for the alpha blend pass anyway, because it can create sorting issues.Fortunately the workarounds are pretty easy:
.transparent = false
, or…Fixed version attached:
car-patched.glb.zip
Yeah, the file contains a TGA texture, which glTF doesn’t allow. I’m not sure why it says the “recognized image format” is PNG. Appears to be a bug in the Babylon.JS 3DS Max exporter not converting that.
I think it’s still best to do so. Or at least to recommend it as the default choice, and to enable it automatically in GLTFLoader. Certainly there are cases where the user might want to switch to
depthWrite=true
, and that’s fine. Another common case wheredepthWrite=false
makes a difference is two geometries centered at the same point, or interlocking in some way. Sorting by the AABB rather than the center might help with the former.