Skip to content

Instantly share code, notes, and snippets.

@gyakoo
Last active August 29, 2015 14:25
Show Gist options
  • Save gyakoo/bf7936c56acf9987e76f to your computer and use it in GitHub Desktop.
Save gyakoo/bf7936c56acf9987e76f to your computer and use it in GitHub Desktop.
Iterate through all materials in all static instances in a Zone in Havok Anarchy
// Iterate through all materials in all static instances in a Zone
{
VisZoneResourceManager_cl &mgr = VisZoneResourceManager_cl::GlobalManager();
// iterate through all zones
for (int i=mgr.GetResourceCount()-1; i >= 0; i--)
{
VisZoneResource_cl *pZone = mgr.GetZoneByIndex(i);
if (!pZone || !pZone->m_bHandleZone || pZone->IsMissing()) continue;
// for all objects in the zone
VisTypedEngineObject_cl* pObj=NULL;
for ( int z = 0; z < pZone->m_ZoneObjects.GetSize(); ++z )
{
pObj = pZone->m_ZoneObjects.Get(z);
if ( !pObj ) continue;
// if it's a static object... (can be others like VLogicGraph, vHavokResourceShape...)
if ( pObj->IsOfType(V_RUNTIME_CLASS(VisStaticMeshInstance_cl)) )
{
VisStaticMeshInstance_cl* meshInst = vstatic_cast<VisStaticMeshInstance_cl*>(pObj);
// for all materials in this static mesh
VisSurface_cl** materials = meshInst->GetMesh()->GetSurfaceArray();
int count = meshInst->GetMesh()->GetSurfaceCount();
for ( int s = 0; s < count; ++s )
{
VisSurface_cl* mat = materials[s];
// to do: inspect material!
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment