I want to change the type of material used on mesh. Say for example it is MeshBasicMaterial and I want to change it to MeshPhongMaterial, but ONLY the type, so colors, maps setting etc stay the same. For example, I load a picture and put on a flat plane. The material type is phong. I have a picture frame mesh and it 'stype is basic, How can I change the material to phong to match the picture?
I tried changing .type but that did not seem to work but is listed when I look in console
The type
property is only intended for serialization/deserialization.
You can only solve this issue by creating a new instance of MeshPhongMaterial
and copy over all compatible material properties. So don’t do phongMaterial.copy( basicMaterial );
. This approach is only supported if both material objects are from the same type.
Something like this will cover most common properties:
const targetMaterial = new MeshPhongMaterial();
MeshBasicMaterial.prototype.copy.call( targetMaterial, sourceMaterial );
2 Likes
Thanks will give it a try.