CmMeshManager.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(const MeshDataPtr& initialData, MeshBufferType bufferType)
  23. {
  24. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh(initialData, bufferType));
  25. mesh->setThisPtr(mesh);
  26. mesh->initialize();
  27. return mesh;
  28. }
  29. MeshPtr MeshManager::createEmpty()
  30. {
  31. MeshPtr mesh = cm_core_ptr<Mesh, PoolAlloc>(new (cm_alloc<Mesh, PoolAlloc>()) Mesh());
  32. mesh->setThisPtr(mesh);
  33. return mesh;
  34. }
  35. void MeshManager::onStartUp()
  36. {
  37. VertexDataDescPtr vertexDesc = cm_shared_ptr<VertexDataDesc>();
  38. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  39. mDummyMeshData = cm_shared_ptr<MeshData>(1, 3, vertexDesc);
  40. auto vecIter = mDummyMeshData->getVec3DataIter(VES_POSITION);
  41. vecIter.setValue(Vector3(0, 0, 0));
  42. auto indices = mDummyMeshData->getIndices32(0);
  43. indices[0] = 0;
  44. indices[1] = 0;
  45. indices[2] = 0;
  46. SyncedCoreAccessor& coreAccessor = gMainSyncedCA();
  47. mDummyMesh = Mesh::create(mDummyMeshData);
  48. }
  49. }