Search code examples
three.jsblendershadowlight

Export painted model from Blender to Three.js


I tried to export GLTF model from Blender to Three.js. It works. But I have some artifacts on Three.js with lighting and painting. I have lines and squares in Three.js and I don't know why.

enter image description here

I used only Principled BSDF node in Blender to painting my model. If I set material in Three.js (MeshPhongMaterial) it works fine. But not with Principled BSDF node from Blender. Any ideas?

enter image description here

I'm trying to make the object cast a shadow and react to the lighting. This works well with MeshPhongMaterial and with Principled BSDF. But in the second option, I don't like these black stripes.

const INITIAL_MTL = new THREE.MeshPhongMaterial( { color: 0x575757, shininess: 10 } );
...
let theModel = gltf.scene;

        theModel.traverse((o) => {
            if (o.isMesh) {
                if (o.name == 'Foundation') {
                    o.material = INITIAL_MTL //Left part on screenshot with MeshPhongMaterial
                }
                o.castShadow = true;
                o.receiveShadow = true;
            }
        })

Solution

  • The usual approach to mitigate self-shadowing artifacts is to modulate the bias property of your shadow-casting light. Try it with:

    light.shadow.bias = - 0.002;