fixes for physics
This commit is contained in:
@@ -93,6 +93,7 @@ public:
|
||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||
|
||||
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||
CAssetArc<FunnyMesh_t, MAX_MODEL_COUNT> m_meshes = {};
|
||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||
|
||||
};
|
||||
@@ -108,6 +109,7 @@ FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
||||
|
||||
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
||||
{
|
||||
return m_meshes.GetObjectPtr(uIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +181,30 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName )
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
bool bHasBeenCreated = false;
|
||||
HFunnyMesh hAsset = m_meshes.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||
if (!bHasBeenCreated)
|
||||
return hAsset;
|
||||
FunnyMesh_t *pMesh = m_meshes.GetObjectPtr(hAsset);
|
||||
|
||||
IFileHandle *hMesh = filesystem->Open(szName, FILEMODE_READ);
|
||||
if ( hMesh == NULL )
|
||||
{
|
||||
V_printf("Failed to load %s\n", szName);
|
||||
m_meshes.UnrefObject(hAsset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
pMesh->m_nPositionCount = filesystem->Size(hMesh)/4;
|
||||
pMesh->m_pfPositions = new float[pMesh->m_nPositionCount];
|
||||
filesystem->Read( hMesh, pMesh->m_pfPositions, filesystem->Size(hMesh));
|
||||
pMesh->m_nIndiciesCount = 0;
|
||||
pMesh->m_puIndicies = 0;
|
||||
|
||||
|
||||
return hAsset;
|
||||
|
||||
}
|
||||
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
||||
@@ -231,8 +256,25 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
}
|
||||
if (szType == "Triangles")
|
||||
if (szType == "TriangleMesh")
|
||||
{
|
||||
V_printf("hi\n");
|
||||
IJSONValue *pMeshValue = pMainObject->GetValue("Mesh");
|
||||
V_printf("hi\n");
|
||||
if (!pMeshValue)
|
||||
{
|
||||
|
||||
V_printf("\"Mesh\" must be specified\n");
|
||||
m_physics.UnrefObject(hPhysics);
|
||||
return 0;
|
||||
}
|
||||
CUtlString szMesh = pMeshValue->GetStringValue();
|
||||
V_printf("%s\n", szMesh.GetString());
|
||||
HFunnyMesh hMesh = LoadMesh(szMesh);
|
||||
FunnyMesh_t *pMesh = GetMeshByIndex(hMesh);
|
||||
pPhysics->m_hShape = g_pPhysics->CreateTriangleMesh({pMesh->m_pfPositions, pMesh->m_nPositionCount});
|
||||
V_printf("%p\n", pPhysics->m_hShape);
|
||||
pPhysics->m_hMesh = hMesh;
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
|
||||
Reference in New Issue
Block a user