void vHavokShapeFactory::GetHktDependencies(VResourceSnapshot &snapshot, VisBaseEntity_cl *pEntity) { VASSERT(pEntity != NULL); // Get wrapped rigid body vHavokRigidBody *pWrappedRigidBody = pEntity->Components().GetComponentOfType<vHavokRigidBody>(); if (pWrappedRigidBody == NULL) return; // Get shape vHavokPhysicsModule *pModule = vHavokPhysicsModule::GetInstance(); VASSERT(pModule != NULL); pModule->MarkForRead(); const hkpRigidBody *pRigidBody = pWrappedRigidBody->GetHkRigidBody(); if (pRigidBody == NULL) { pModule->UnmarkForRead(); return; } const hkpShape *pShape = pRigidBody->getCollidable()->getShape(); pModule->UnmarkForRead(); // Only convex/ mesh rigid bodies have a cached HKT file const hkClass* loadedClassType = hkVtableClassRegistry::getInstance().getClassFromVirtualInstance(pShape); if (loadedClassType!=&hkvConvexVerticesShapeClass && loadedClassType!=&hkvBvCompressedMeshShapeClass) return; // Get mesh VDynamicMesh *pMesh = pEntity->GetMesh(); if (pMesh == NULL) return; // Get scale hkvVec3 vScale = pEntity->GetScaling(); bool shrinkToFit = pWrappedRigidBody->Havok_TightFit; // Get HKT file dependency for convex/ mesh rigid body if (loadedClassType == &hkvConvexVerticesShapeClass) { VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); vHavokCachedShape::GetConvexShapePath(szCachedShapeName, vScale, shrinkToFit); IVFileInStream *pIn = Vision::File.Open(szCachedShapeName); if (pIn) { snapshot.AddFileDependency(pMesh, szCachedShapeName, pIn->GetSize() ); pIn->Close(); } } else if(loadedClassType == &hkvBvCompressedMeshShapeClass) { VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); vHavokCachedShape::GetMeshShapePath(szCachedShapeName, vScale, VisStaticMeshInstance_cl::VIS_COLLISION_BEHAVIOR_CUSTOM, (VisWeldingType_e)pWrappedRigidBody->Havok_WeldingType); IVFileInStream *pIn = Vision::File.Open(szCachedShapeName); if (pIn) { snapshot.AddFileDependency(pMesh, szCachedShapeName, pIn->GetSize() ); pIn->Close(); } } }
void vHavokShapeFactory::GetHktDependencies(VResourceSnapshot &snapshot, VTerrainSector *pSector) { VASSERT(pSector != NULL); // Return when no physics representation vHavokTerrain *pHavokTerrain = (vHavokTerrain*) pSector->GetPhysicsUserData(); if (pHavokTerrain == NULL) return; const VTerrainSector::VPhysicsType_e ePhysicsType = pSector->GetPhysicsType(); const bool bHasHoles = pSector->HasHoles(); // First get filename by specifying extension (hmap) to be able to retrieve the absolute path. // Afterwards remove extension. char szFilename[FS_MAX_PATH]; pSector->m_Config.GetSectorFilename(szFilename, pSector->m_iIndexX, pSector->m_iIndexY, "hmap", true); char szPath[FS_MAX_PATH]; bool bSuccess = VFileHelper::GetAbsolutePath(szFilename, szPath, Vision::File.GetManager()); VASSERT_MSG(bSuccess, "vHavokShapeFactory::GetHktDependencies: Failed to make the path to the sector hmap absolute, the file may not exist!"); VFileHelper::GetFilenameNoExt(szPath, szFilename); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(szPath); vHavokCachedShape::GetTerrainSectorShapePath(szCachedShapeName, ePhysicsType, bHasHoles); IVFileInStream *pIn = Vision::File.Open(szCachedShapeName); if (pIn) { snapshot.AddFileDependency(pSector, szCachedShapeName, pIn->GetSize() ); pIn->Close(); } }
void vHavokAiNavMeshResource::GetDependencies(VResourceSnapshot &snapshot) { IVFileInStream* pIn = Vision::File.Open(GetFilename()); if (pIn != NULL) { snapshot.AddFileDependency(this, GetFilename(), pIn->GetSize()); pIn->Close(); } VManagedResource::GetDependencies(snapshot); }
void vHavokShapeFactory::GetHktDependencies(VResourceSnapshot &snapshot, VisStaticMeshInstance_cl *pMeshInstance) { VASSERT(pMeshInstance != NULL); // Get scale hkvVec3 vScale(hkvNoInitialization); ExtractScaling(pMeshInstance->GetTransform(), vScale); // There is no real way to figure out if a convex or mesh shape is required and the filename is based on that. // So try them both. // Convex version { VStaticString<FS_MAX_PATH> szCachedShapeName(pMeshInstance->GetMesh()->GetFilename()); bool shrinkToFit = false; //how do if true / can it be true for static mesh? vHavokCachedShape::GetConvexShapePath(szCachedShapeName, vScale, shrinkToFit); IVFileInStream *pIn = Vision::File.Open(szCachedShapeName); if (pIn) { snapshot.AddFileDependency(pMeshInstance->GetMesh(), szCachedShapeName, pIn->GetSize() ); pIn->Close(); return; } } // Mesh version { VStaticString<FS_MAX_PATH> szCachedShapeName(pMeshInstance->GetMesh()->GetFilename()); vHavokCachedShape::GetMeshShapePath(szCachedShapeName, vScale, pMeshInstance->GetCollisionBehavior(), pMeshInstance->GetWeldingType()); IVFileInStream *pIn = Vision::File.Open(szCachedShapeName); if (pIn) { snapshot.AddFileDependency(pMeshInstance->GetMesh(), szCachedShapeName, pIn->GetSize() ); pIn->Close(); return; } } }