I’m importing an awd model in Away3d and trying to duplicate one of the materials that is applied to multiple meshes to create a unique ColourMaterial with a different alpha value.
The intent being on rollover I can change the alpha value of the target mesh by swapping the materials.
Not sure what you need help with. What did you try? What worked, and what didn’t work?!
If you want to duplicate / clone a material you can use this:
var newMaterial=material.clone();
If you want to alter an alpha value you can try this:
yourMesh.material.alpha=0.5;
Or do you have a problem with the submeshes? Maybe an imported Mesh has subMeshes so you might need to loop through them. (not tested but something like:)
for(i in yourMesh.subMeshes.length){
yourMesh.subMeshes[i].material = newMaterial;
}
ah ok. It is a ColorMaterial.Apparently there isn’t a clone method for this.
Well you might want to use this:
var newMaterial:ColorMaterial = new ColorMaterial();
newMaterial.color=yourImportMesh.material.color; (or using the subMesh technique from earlier)
newMaterial.alpha = 0.5;
Then apply this material to the mesh on the mouse over event (or whatever you need):
theMesh.material=newMaterial; // or the subMesh technique
Yeah indeed. I thought I would chip in how to get the color and alpha, but there could be other things set on the material. Lightpicker,shadowmethods etc…
You already mentioned Reflection and that might be a solution, but it would really be better if there was a built-in system for this.
Is my assumption correct that an imported mesh with texture materials use the clone() out of the box like you want?!
Yes mesh clone works fine, and is indeed what I’m doing on import, however the cloned mesh is still using the original material, I guess this is preferred anyway, there’s just no easy way to duplicate a material that I can see.