How to set individual material colors for Skinned Mesh

I am trying to set a specific color for each material in a skinned mesh. Having very strange behavior.

	mesh.traverse( function ( child ) {
	if ( child instanceof THREE.Object3D ) {
		if(child.material !== undefined){ 

			console.log("~ materials ~");
			console.log(child.material);
			child.material[5].emissive.setHex( 0xff0000 );
			child.material[5].emissiveIntensity = 0.1;
			child.material[5].color.setHex( 0xff0000 );
			child.material[5].needsUpdate = true;

		}
	}
});

child.material is an array of 7 materials. If I set the color for materials index 0-5, nothing happens. If I set the material for index 6 (last in array) then it applies globally for all the materials – making it impossible to specify individual material colors. Not quite sure what is going on…

03%20AM

^ I was able to turn the entire model red by setting material “RollerSkatesmat” to red.

Maybe I am missing something very basic here?

Can you please share the dae file in this thread?

Running (3).zip (1.0 MB)

There is something wrong with your model. I have imported it in Blender and changed the color of the material with name “Armsmat” to red. The entire mesh becomes red although more materials are defined (see screenshots). It looks like all materials are assigned to all faces of the geometry. So the first material in the list covers all other materials. In three.js it is the last material in the list.

You have to ensure that the materials are assigned to specific parts of the model. A material with name “Eyesmat” should probably be assigned to the eyes, “RollerSkatesmat” to the roller skates and so on…

image
image

34%20PM

Seems assigning colors of my OBJ/MTL is fine but as soon as I convert it to animated DAE it breaks.

Um sry, I’m just a casual Blender user so I don’t know why this happens :innocent:.

Maybe you find an answer in the Blender community.

You were right! It was an error with the child/parent structure of the original OBJ model. It’s fixed now!

42%20PM

^ don’t do this

2 Likes