Cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace the material in JtkShape?

I read an existing JT file using JT Open Toolkit, change the data in memory, save the file, then read it again and look at the result. The task is to change the colors of shapes.

 

In the original file, JtkHierarchy objects (assemblies and parts) don't have materials, and only JtkShape objects do. Each shape has one material, I retrieve it using JtkShape::getAttrib(index, ptr, JtkEntity::JtkMATERIAL). When I try to modify or replace this material, strange things start happening.

 

  • When I modify the material (JtkMaterial::setSpecularColor), in the saved file each shape ends up with two materials, the original one and the modified one. Why does it happen? I did not add the material again.
  • When I create a new material (JtkEntityFactory::createMaterial) and use JtkShape::setMaterial, in the saved file each shape ends up with two materials, the original one and the new one. Why is the original material kept? I supposed setMaterial should replace it.
  • When I remove the original material using JtkShape::deleteAttrib, create a new material and add it using JtkShape::addAttrib, in the saved file each shape ends up with two materials, the original one and the new one. Why is the original material kept? Interestingly, after invoking JtkShape::deleteAttrib, JtkShape::numAttribs(JtkEntity::JtkMATERIAL) reports 0, so apparently it has been successfully deleted, but in the saved file it appears again.

What should I do to remove the original material or to change it in place?