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(); } } }
bool vHavokCachedShape::SaveTerrainSectorShape(const VTerrainSector *pSector, const hkpShape *pShape) { #ifndef SUPPORTS_HKT return false; #else VASSERT(pSector!=NULL && pShape!=NULL); // 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); VFileAccessManager::NativePathResult sectorNativeResult; if (VFileAccessManager::GetInstance()->MakePathNative(szFilename, sectorNativeResult, VFileSystemAccessMode::READ, VFileSystemElementType::FILE) != HKV_SUCCESS) { VASSERT_MSG(FALSE, "vHavokShapeFactory::GetHktDependencies: Failed to determine the native path to the sector hmap; the file may not exist!"); return false; } VFileHelper::GetFilenameNoExt(szFilename, sectorNativeResult.m_sNativePath); // Build the shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(szFilename); GetTerrainSectorShapePath(szCachedShapeName, pSector->GetPhysicsType(), pSector->HasHoles()); const hkClass* pClassType = hkVtableClassRegistry::getInstance().getClassFromVirtualInstance(pShape); return SaveShape(szCachedShapeName, *pClassType, pShape); #endif }
bool vHavokCachedShape::SaveMeshShape(const VBaseMesh *pMesh, const hkvVec3& vScale, VisStaticMeshInstance_cl::VisCollisionBehavior_e eCollisionBehavior, VisWeldingType_e eWeldingType, const hkvBvCompressedMeshShape *pShape) { #ifndef SUPPORTS_HKT return false; #else VASSERT(pMesh!=NULL && pShape!=NULL); VFileAccessManager::NativePathResult meshNativeResult; if (VFileAccessManager::GetInstance()->MakePathNative(pMesh->GetFilename(), meshNativeResult, VFileSystemAccessMode::READ, VFileSystemElementType::FILE) != HKV_SUCCESS) { VASSERT_MSG(FALSE, "vHavokCachedShape::SaveConvexShape: Failed to determine the native mesh path; the file may not exist!"); return false; } VStaticString<FS_MAX_PATH> szCachedShapeDirname(meshNativeResult.m_sNativePath); szCachedShapeDirname += "_data"; if (!VFileHelper::ExistsDir(szCachedShapeDirname)) VFileHelper::MkDir(szCachedShapeDirname); // Build the shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(meshNativeResult.m_sNativePath); GetMeshShapePath(szCachedShapeName, vScale, eCollisionBehavior, eWeldingType); return SaveShape(szCachedShapeName, hkvBvCompressedMeshShapeClass, pShape); #endif }
hkpShape* vHavokCachedShape::LoadTerrainSectorShape(const VTerrainSector *pSector) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pSector != NULL); 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); VFileAccessManager::NativePathResult sectorNativeResult; if (VFileAccessManager::GetInstance()->MakePathNative(szFilename, sectorNativeResult, VFileSystemAccessMode::READ, VFileSystemElementType::FILE) != HKV_SUCCESS) { VASSERT_MSG(FALSE, "vHavokShapeFactory::GetHktDependencies: Failed to determine the native path to the sector hmap; the file may not exist!"); return NULL; } VFileHelper::GetFilenameNoExt(szFilename, sectorNativeResult.m_sNativePath); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(szFilename); GetTerrainSectorShapePath(szCachedShapeName, ePhysicsType, bHasHoles); if (ePhysicsType == VTerrainSector::VPHYSICSTYPE_APPROXIMATE) return LoadShape(szCachedShapeName, hkvSampledHeightFieldShapeClass); else if (bHasHoles) return LoadShape(szCachedShapeName, hkvTriSampledHeightFieldBvTreeShapeClass); else return LoadShape(szCachedShapeName, hkpTriSampledHeightFieldBvTreeShapeClass); #endif }
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 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; } } }
hkvConvexVerticesShape* vHavokCachedShape::LoadConvexShape(VBaseMesh *pMesh, const hkvVec3& vScale, bool bShrinkToFit) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pMesh != NULL); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); GetConvexShapePath(szCachedShapeName, vScale, bShrinkToFit); hkvConvexVerticesShape *pShape = (hkvConvexVerticesShape*)LoadShape(szCachedShapeName, hkvConvexVerticesShapeClass); if ((Vision::Editor.IsInEditor() || IsHktUpToDateCheckingEnabled()) && pShape!=HK_NULL) { if (!IsHktUpToDate(pMesh, pShape, hkvConvexVerticesShapeClass)) return HK_NULL; } return pShape; #endif }
hkvBvCompressedMeshShape* vHavokCachedShape::LoadMeshShape(VBaseMesh *pMesh, const hkvVec3& vScale, VisStaticMeshInstance_cl::VisCollisionBehavior_e eCollisionBehavior, VisWeldingType_e eWeldingType) { #ifndef SUPPORTS_HKT return HK_NULL; #else VASSERT(pMesh != NULL); // Build the cached shape filename VStaticString<FS_MAX_PATH> szCachedShapeName(pMesh->GetFilename()); GetMeshShapePath(szCachedShapeName, vScale, eCollisionBehavior, eWeldingType); hkvBvCompressedMeshShape *pShape = (hkvBvCompressedMeshShape*)LoadShape(szCachedShapeName, hkvBvCompressedMeshShapeClass); if ((Vision::Editor.IsInEditor() || IsHktUpToDateCheckingEnabled()) && pShape!=HK_NULL) { if (!IsHktUpToDate(pMesh, pShape, hkvBvCompressedMeshShapeClass)) return HK_NULL; } return pShape; #endif }