CpuMeshResource.cpp 1.2 KB

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