CpuMeshResource.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2009-2021, 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/Physics/PhysicsWorld.h>
  9. namespace anki
  10. {
  11. CpuMeshResource::CpuMeshResource(ResourceManager* manager)
  12. : ResourceObject(manager)
  13. {
  14. }
  15. CpuMeshResource::~CpuMeshResource()
  16. {
  17. m_indices.destroy(getAllocator());
  18. m_positions.destroy(getAllocator());
  19. }
  20. Error CpuMeshResource::load(const ResourceFilename& filename, Bool async)
  21. {
  22. MeshBinaryLoader loader(&getManager());
  23. ANKI_CHECK(loader.load(filename));
  24. DynamicArrayAuto<Vec3> tempPositions(getAllocator());
  25. DynamicArrayAuto<U32> tempIndices(getAllocator());
  26. ANKI_CHECK(loader.storeIndicesAndPosition(tempIndices, tempPositions));
  27. m_indices = std::move(tempIndices);
  28. m_positions = std::move(tempPositions);
  29. // Create the collision shape
  30. const Bool convex = !!(loader.getHeader().m_flags & MeshBinaryFlag::CONVEX);
  31. m_physicsShape = getManager().getPhysicsWorld().newInstance<PhysicsTriangleSoup>(m_positions, m_indices, convex);
  32. return Error::NONE;
  33. }
  34. } // end namespace anki