CpuMeshResource.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Resource/CpuMeshResource.h>
  6. #include <AnKi/Resource/MeshBinaryLoader.h>
  7. #include <AnKi/Resource/ResourceManager.h>
  8. #include <AnKi/Physics2/PhysicsWorld.h>
  9. namespace anki {
  10. Error CpuMeshResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
  11. {
  12. MeshBinaryLoader loader(&ResourceMemoryPool::getSingleton());
  13. ANKI_CHECK(loader.load(filename));
  14. ANKI_CHECK(loader.storeIndicesAndPosition(loader.getHeader().m_lodCount - 1, m_indicesMaxLod, m_positionsMaxLod));
  15. m_isConvex = !!(loader.getHeader().m_flags & MeshBinaryFlag::kConvex);
  16. m_maxLod = U8(loader.getHeader().m_lodCount - 1);
  17. return Error::kNone;
  18. }
  19. const v2::PhysicsCollisionShapePtr& CpuMeshResource::getOrCreateCollisionShape(Bool isStatic, U32 lod) const
  20. {
  21. lod = min<U32>(lod, m_maxLod);
  22. ANKI_ASSERT(lod == m_maxLod && "Not supported ATM");
  23. LockGuard lock(m_shapeMtx);
  24. if(!m_collisionShape)
  25. {
  26. if(m_isConvex || !isStatic)
  27. {
  28. if(!m_isConvex && !isStatic)
  29. {
  30. ANKI_RESOURCE_LOGE("Requesting a non-static non-convex collision shape is not supported. Will create a convex hull instead");
  31. }
  32. m_collisionShape = v2::PhysicsWorld::getSingleton().newConvexHullShape(m_positionsMaxLod);
  33. }
  34. else
  35. {
  36. m_collisionShape = v2::PhysicsWorld::getSingleton().newStaticMeshShape(m_positionsMaxLod, m_indicesMaxLod);
  37. }
  38. }
  39. return m_collisionShape;
  40. }
  41. } // end namespace anki