CmMeshManager.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "CmMeshManager.h"
  2. #include "CmCoreThreadAccessor.h"
  3. #include "CmApplication.h"
  4. #include "CmVector3.h"
  5. #include "CmMesh.h"
  6. #include "CmVertexDataDesc.h"
  7. namespace CamelotFramework
  8. {
  9. MeshManager::MeshManager()
  10. {
  11. }
  12. MeshManager::~MeshManager()
  13. {
  14. }
  15. MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
  16. {
  17. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh(numVertices, numIndices, vertexDesc, bufferType, indexType));
  18. mesh->setThisPtr(mesh);
  19. mesh->initialize();
  20. return mesh;
  21. }
  22. MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const MeshDataPtr& initialData,
  23. MeshBufferType bufferType, IndexBuffer::IndexType indexType)
  24. {
  25. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh(numVertices, numIndices, vertexDesc, initialData, bufferType, indexType));
  26. mesh->setThisPtr(mesh);
  27. mesh->initialize();
  28. return mesh;
  29. }
  30. MeshPtr MeshManager::create(const MeshDataPtr& initialData, MeshBufferType bufferType)
  31. {
  32. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh(initialData, bufferType));
  33. mesh->setThisPtr(mesh);
  34. mesh->initialize();
  35. return mesh;
  36. }
  37. MeshPtr MeshManager::createEmpty()
  38. {
  39. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh());
  40. mesh->setThisPtr(mesh);
  41. return mesh;
  42. }
  43. void MeshManager::onStartUp()
  44. {
  45. VertexDataDescPtr vertexDesc = cm_shared_ptr<VertexDataDesc>();
  46. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  47. mDummyMeshData = cm_shared_ptr<MeshData>(1, 3, vertexDesc);
  48. auto vecIter = mDummyMeshData->getVec3DataIter(VES_POSITION);
  49. vecIter.setValue(Vector3(0, 0, 0));
  50. auto indices = mDummyMeshData->getIndices32(0);
  51. indices[0] = 0;
  52. indices[1] = 0;
  53. indices[2] = 0;
  54. SyncedCoreAccessor& coreAccessor = gMainSyncedCA();
  55. mDummyMesh = Mesh::create(mDummyMeshData);
  56. }
  57. }