question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Certain gltf models display incorrectly in three.js

See original GitHub issue

Describe 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

car.zip

Open this model in this three.js based gLTF viewer to see the problem. brave_bwuQfrrkDJ

The model displays fine in this alternate gLTF viewer. brave_T9LKSNQ3xz

Code

// code goes here

Platform:

  • Device: Desktop
  • OS: Windows
  • Browser: Chrome
  • Three.js version: latest

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
donmccurdycommented, Jun 16, 2021

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) …

# name instances textures alphaMode doubleSided
0 Material #582 1 baseColorTexture BLEND
1 window 1 baseColorTexture BLEND

… 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:

  • A. In Blender, switch from “Alpha Blend” to “Opaque” for these materials, or…
  • B. In three.js, manually set .transparent = false, or…
  • C. Use a script to patch the file…
import { NodeIO } from '@gltf-transform/core';

const io = new NodeIO();
const document = io.read('car.gltf');

for (const material of document.getRoot().listMaterials()) {
	if (material.getName() !== 'window') {
		material.setAlphaMode('OPAQUE');
	}
}

io.write('car-patched.glb', document);

Fixed version attached:

car-patched.glb.zip

Screen Shot 2021-06-16 at 12 48 22 AM

1reaction
donmccurdycommented, Jun 16, 2021

… I guess you saw it already but car-patched.glb gets [‘image/tga’ error]

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.

Do we still need to set depthWrite = false after #21967?

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 where depthWrite=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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found