I have the model โ.objโ and โ.mtlโ files and I upload it via OBJMTLLoader . ".mtl" sets the texture applied to the model, and the three.js model loads the model and makes it fine using the texture.
But here's the thing.
Once the object is loaded, I would like to apply a different texture to it. This is due to the fact that the first texture is the surface material of the object. And the second texture is a picture that I would like to position in a certain place on the model.
My question is: how to apply a second texture to an already loaded (and textured) object ?
I see that three.js creates an instance of THREE.Object3D , and this instance has an array of "children" with one instance of THREE.Mesh .
When I try to apply a texture to this mesh ( mesh.material.map = texture ), I lose the original texture.
I reviewed this question about applying multiple textures and JSONLoader , but did not find an answer.
I also tried using new THREE.MeshFaceMaterial( materials ) (as suggested in this answer ), but to no avail.
UPDATE
I tried @WestLangley's suggestion to use an object with multiple materials, but I still cannot display one material on top of another.
I did this simple demo adapted from three .js OBJLoader - http://dl.dropboxusercontent.com/u/822184/webgl_multiple_texture/index.html
I am using THREE.SceneUtils.createMultiMaterialObject as suggested, passing it the cloned geometry of the main mesh loaded from .obj. I also give him 2 textures - one for the entire surface, the other for the front surface of the model.
But that does not work. I added 2 flags that switch the โvisibleโ property of the corresponding materials. You can see that the materials are present, but I do not see the first of them below the second.
The essence of loading / rendering is as follows:
var texture = THREE.ImageUtils.loadTexture('fabric.jpg'); var texture2 = THREE.ImageUtils.loadTexture('table.jpg'); texture2.offset.set(-0.65, -2.5); texture2.repeat.set(4, 4); var loader = new THREE.OBJLoader(); loader.addEventListener( 'load', function ( event ) { var mainMesh = event.content.children[0].children[0]; multiMaterialObject = THREE.SceneUtils.createMultiMaterialObject( mainMesh.geometry.clone(), [ new THREE.MeshLambertMaterial({ map: texture2 }), new THREE.MeshLambertMaterial({ map: texture }) ]); multiMaterialObject.position.y = -80; scene.add(multiMaterialObject); }); loader.load( 'male02.obj' );
UPDATE # 2
At this point, I find it best to use THREE.ShaderMaterial to apply one texture to another. I see several examples of using the same texture , but still do not know how to display them in the superimposed state. I'm also not sure how to position the texture in a specific place on the grid.