I have an OBJ that uses four textures. The UVs defined in the file range from (0, 0) to (2, 2), such that (0.5, 0.5) refers to a coordinate in the first texture, (0.5, 1.5) is a UV coordinate in the second texture, (1.5, 0.5) is a coordinate in the third texture, and (1.5, 1.5) is a coordinate in the last texture.
I already have the correct three.js geometry or object. However, I now need to be able to apply the correct texture maps to these objects.
In code:
I have a THREE.Mesh
with the correct geometry (with UVs coords such that U = [0, 2], V = [0, 2]) and a dummy placeholder material. I currently load a single texture like so:
var texture = new THREE.TextureLoader().load('tex_u1_v1.png', function() {
object.material.map = texture;
object.material.map.needsUpdate = true;
});
As expected, one fourth of the mesh is textured correctly. I have three more texture files, tex_u1_v2.png
, tex_u2_v1.png
, and tex_u2_v2.png
. I want to be able to apply these textures as well to object
(the THREE.js mesh), such that there is a texture for every valid UV in the mesh.
However, I do not know how to add multiple materials to object
after it has been created. Moreover, I do not know how to specify to the mesh that tex_u1_v2.png
, for example, should be used for UVs in range (U = [0, 2], V = [1, 2]).
object.material
withonBeforeCompile
, but it's clunky. – pailhead