3MFConsortium / lib3mf

lib3mf is an implementation of the 3D Manufacturing Format file standard
http://3mf.io
BSD 2-Clause "Simplified" License
228 stars 92 forks source link

How to get all MaterialGroups of a model ? #347

Open gsohler opened 6 months ago

gsohler commented 6 months ago

I tried to read all BaseMaterialGroups when importing a 3MF Model

I tried this:

Lib3MF::PBaseMaterialGroupIterator basematerial_it = model->GetBaseMaterialGroups();
while (true) {
  if(!basematerial_it->MoveNext()) break;
  std::shared_ptr<Lib3MF::CResource> cr = basematerial_it->GetCurrent();
  std::shared_ptr<Lib3MF::CBaseMaterialGroup> mat = std::dynamic_pointer_cast<Lib3MF::CBaseMaterialGroup>(cr);
  if(mat != nullptr) {
      cout << "worked\n";
  } else cout << "Pointer cast not working\n";
}  

However, the dynamic_pointer_cast does not work even though, reading the header file, CBaseMaterialGroup is derived from CResource ?

So whats wrong in my strategy ? How can I get all MaterialGroups ?

class CBaseMaterialGroup : public CResource