Need an example of applying a different texture to each face of a BoxMesh

Working on a proof-of-concept project that is my first venture into 3D. So basically I’m dumb on 3D topics and my brain is old.

I am using MeshInstance3D with a BoxMesh. I need to apply a separate texture to each face of the BoxMesh in code. I’m using GDScript.

BoxMesh documenation says The box's UV layout is arranged in a 3×2 layout that allows texturing each face individually.

What I can’t find is an example of how to texture each face individually.

Can someone provide a brief example of how to do this?

Many thanks.

1 Like

If you add a MeshInstance3D with a BoxMesh and click on the toolbar “Mesh” icon and “View UV1” you can see the 3x2 UV layout.

That is how the BoxMesh applies the material texture to its triangle faces.

So what you do is design a texture that way so that the texture colors map to the faces that you want.

You only use one texture for all faces, not multiple textures for each face.

If you need to use a different texture for each single face you need to write a custom shader that allows for multiple texture uniforms or change the entire mesh surfaces procedual, e.g. adding a new surface for each single face with either the SurfaceTool or the ArrayMesh API.

4 Likes

Thank you! That’s exactly what I needed!