CmMeshManager.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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,
  16. MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
  17. {
  18. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>())
  19. Mesh(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType));
  20. mesh->setThisPtr(mesh);
  21. mesh->initialize();
  22. return mesh;
  23. }
  24. MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
  25. const MeshDataPtr& initialData, MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
  26. {
  27. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>())
  28. Mesh(numVertices, numIndices, vertexDesc, initialData, bufferType, drawOp, indexType));
  29. mesh->setThisPtr(mesh);
  30. mesh->initialize();
  31. return mesh;
  32. }
  33. MeshPtr MeshManager::create(const MeshDataPtr& initialData, MeshBufferType bufferType, DrawOperationType drawOp)
  34. {
  35. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh(initialData, bufferType, drawOp));
  36. mesh->setThisPtr(mesh);
  37. mesh->initialize();
  38. return mesh;
  39. }
  40. MeshPtr MeshManager::createEmpty()
  41. {
  42. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh());
  43. mesh->setThisPtr(mesh);
  44. return mesh;
  45. }
  46. void MeshManager::onStartUp()
  47. {
  48. VertexDataDescPtr vertexDesc = cm_shared_ptr<VertexDataDesc>();
  49. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  50. mDummyMeshData = cm_shared_ptr<MeshData>(1, 3, vertexDesc);
  51. auto vecIter = mDummyMeshData->getVec3DataIter(VES_POSITION);
  52. vecIter.setValue(Vector3(0, 0, 0));
  53. auto indices = mDummyMeshData->getIndices32();
  54. indices[0] = 0;
  55. indices[1] = 0;
  56. indices[2] = 0;
  57. SyncedCoreAccessor& coreAccessor = gMainSyncedCA();
  58. mDummyMesh = Mesh::create(mDummyMeshData);
  59. }
  60. }