How to preserve UV mapping when uptdating map texture

Viewed 33

I've a GLTF model, I want to update its map texture but as soon as I do it, the new texture is displaying but the UV mapping of my model is not set anymore.

Is there a way to preserve the UV mapping when I load a new texture ? Here's the code I used to call a new map texture at some point in my website :

model.traverse(child => {
    if (
        child instanceof THREE.Mesh 
    ) {
        child.material.map = newTexture;
    }
})
1 Answers

When replacing color textures of a glTF asset, you need these two lines.

newTexture.encoding = THREE.sRGBEncoding; // color textures must be marked as sRGB
newTexture.flipY = false; // honor glTF's uv convention
Related