Multiple Materials for a Single Mesh
Learn how to add different materials to the same mesh.
We'll cover the following...
Add different materials to a single mesh
When creating THREE.Mesh, we’ve used a single material. It is also possible to define a specific material for each of the faces of a geometry. For instance, if we have a cube that has 12 faces (remember, Three.js works with triangles), we can assign a different material (for example, with a different color) to each side of the cube. Doing this is straightforward, as shown in the following piece of code:
We create an array, named matArray (line 7), to hold all the materials and use that array to create THREE.Mesh. What we might notice is that we only create six materials (lines 1–6), even though we’ve got 12 faces.
To understand how this works, we have to look at how Three.js assigns a material to a ...