warrenm / GLTFKit2

A glTF 2.0 asset loader and exporter for Objective-C and Swift.
MIT License
150 stars 26 forks source link

The model transparency is not working correctly #33

Closed kourion11 closed 9 months ago

kourion11 commented 10 months ago

Hi, I'm facing this problem. This is how the model should look like:

Снимок экрана 2023-09-15 в 11 28 44

This is what it looks like:

Снимок экрана 2023-09-15 в 11 29 41

Model - https://cdn.web-ar.studio/templates/3d_models/was/holidays/Christmas%20Ball/Christmas%20Ball.glb

warrenm commented 10 months ago

You seem to be trying to modulate the transparency of the glass surface by setting the alpha component of the intensity of the material's base color property. That won't work with SceneKit, which doesn't support vector-valued intensities.

You're likely to have a better time authoring the opacity of the glass itself (which maps to the opacity property of the node rather than a material property). If this is a one-off situation, or you can't make the change in a modeling tool, you can make the change at runtime by locating the glass node and applying the change manually (perhaps also enabling dual-layer rendering at the same time to avoid Z-buffer artifacts):

if let glassNode = scene?.rootNode.childNode(withName: "glass", recursively: true) {
    glassNode.opacity = 0.468
    glassNode.geometry?.firstMaterial?.transparencyMode = .dualLayer
}
image
kourion11 commented 10 months ago

Thank you! I'll try this

warrenm commented 10 months ago

This issue will be automatically closed in 7 days if no further reply is received.

warrenm commented 9 months ago

Closing due to inactivity.