I am developing a plugin to read a Rhino File. Now I am a bit stuck with the materials, because I dont understand the behavior.
I am getting the materialtable with “File3dm.AllMaterials” but instead of getting the materials of the file like they are in rhino, I get a material per object. So 5 objects with the same material, will result in 5 materials in the materialtable instead of one (what I would have expected)
Is this a wanted behavior? And if so, is there another way to only get those materials once as they are in the material browser? Because it also seems as they are really different objects (different GUID). The only way I see for now is to check via the name of the material.
thanks for looking in to it, but sadly this doesnt apply for the Rhino3dm library. You dont have access to RenderMaterials as far as I can see, like in RhinoCommon.
For now, while generating my own materiallist, I check if the MaterialName already exists and then get the Materialname for the object from the index of the MaterialTable, because the ObjectAttributes only have a MaterialIndex and not a name. It works, but feels like just a workaround…
The old Materials table is currently the only way to access materials, but unfortunately it isn’t the best way. As you noticed it essentially records material assignments, not materials themselves.
Work was done to get access to RenderMaterials table, but that hasn’t landed in rhino3dm yet - it requires the underlying OpenNURBS be updated to the version in Rhino 8 WIP. But since that is still WIP it will probably be some time before those changes and the added support find their way to rhino3dm (is my guess anyway).
Since the fix is a long way off. How do you parse that list to sort out the dups or instances?
Like I said in my post you end up with thousands of materials and worse if you bake out and undo the list fills with nulls. Can’t we get a quick component that filters out the dups as a workaround for now must be doable in Gh python?
Your issue in all likelihood is not related to this topic. I showed how it works for me, but if I can’t reproduce the issue then I can’t help any further. Please continue the discussion related to your issue in your thread.
Thank you for your answer, Nathan. So I’ll stick to the workaround. Maybe a simple improvement of rhino3dm would be the possiblity to get the MaterialName out of the ObjectAttributes. That would simplify the process.