Hello Members,
I’ve loaded an object(Man Body) file. On that object I want load different texture, suppose on Shirt red color, and on pant blue color and on hair black color. So how to fetch specific part of an object(child ) . see example.
Here I fetch one Child object Torus, now How to apply manual color to that child object See Code
var loader = new THREE.OBJMTLLoader();
loader.load( 'meshes/objNmtl/sign3.obj', 'meshes/objNmtl/sign3.mtl', function ( object ) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Object3D ) {
if(child.name=='Torus'){
alert("torus");//
///here i need to add color
}
}
} );
scene.add( object );
} );
Don’t you really see the type of your object??
It’s not THREE.Mesh(), it’s THREE.Object3D(). Of course, you can’t apply any colour, because it has no material. You need to look in its children, they are of THREE.Mesh().
See image, Suppose in this image three lights are there, 2 sphere and 1 Tours. Now I want to change color of torus grammatically. .
I fetch the torus
var loader = new THREE.OBJMTLLoader();
loader.load( ‘meshes/objNmtl/sign3.obj’, ‘meshes/objNmtl/sign3.mtl’, function ( object ) {
Do you really think your posts with poor-formatted code are readable?
I already understood, what you want in the result. But could you, please, do something yourself in your project? Set different colour to a different child object of your model, so you will know what is what.
object.getObjectByName( "Torus" ).children[0].material.color.setHex( 0xff0000 ); object.getObjectByName( "Torus" ).children[1].material.color.setHex( 0x00ff00 );
and so on.
I am doing sir, but at loading time error is coming… now same color came to Torus and sphere , previous also I got this solution. But I need sphere and torus different color