donmccurdy / three-gltf-viewer

Drag-and-drop preview for glTF 2.0 models in WebGL using three.js.
https://gltf-viewer.donmccurdy.com/
MIT License
2.09k stars 534 forks source link

Z-index issue #285

Closed OhadBarda closed 2 years ago

OhadBarda commented 2 years ago

Hi,

For some reason the attached GLB file display wrong z-index in the viewer.

Example with the same camera angle view: image

Curve_gRIS.zip

donmccurdy commented 2 years ago

transparent meshes (also "alpha blend mode") are sorted based on the center of the mesh, and the depth buffer is not written. To fix this example I would suggest making both materials opaque in the model.

OhadBarda commented 2 years ago

So why when I load it in khronos I don't get 'flipped surfaced' like I get in Donmccurdy viewer? image

donmccurdy commented 2 years ago

There are different ways to sort transparent objects, none of which are perfect. If the Khronos Group viewer sorts in the same way as three.js (it may not) then it may still get a different result because sorting two objects occupying the same space may yield inconsistent results.

Because these materials are not actually transparent, they should not be using alpha blending as they are. This issue will not occur with opaque materials.

OhadBarda commented 2 years ago

Thank you. So how I can decide which method to use, when I want to display a semi transparent mesh?

donmccurdy commented 2 years ago

If the material is semi-transparent, use alpha blending. If not, it should be opaque. The rest is mostly up to the engine to decide. If two meshes occupy the same space, or are embedded in one another, transparency is likely to have problems.

OhadBarda commented 2 years ago

So what cause the problem in the file I've sent. Is it a case where two meshes occupy the same space ? Or embedded in one another?

donmccurdy commented 2 years ago

I can't tell which it is in this case sorry.

OhadBarda commented 2 years ago

What info is missing in order for you to tell which case is this? I mean you have the file.

donmccurdy commented 2 years ago

You would need to compare individual triangle data from each mesh to tell the difference, to see if they are the same mesh. Perhaps this could be done in Blender or another tool as well. It doesn't really matter anyway - the mesh doesn't use semi-transparency, so it shouldn't have alpha blending enabled. I do not plan to study this model further myself, as I have limited time to spend responding to questions.