BsMeshManager.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsMeshManager.h"
  5. #include "BsCoreThreadAccessor.h"
  6. #include "BsCoreApplication.h"
  7. #include "BsVector3.h"
  8. #include "BsMesh.h"
  9. #include "BsVertexDataDesc.h"
  10. namespace BansheeEngine
  11. {
  12. MeshManager::MeshManager()
  13. {
  14. }
  15. MeshManager::~MeshManager()
  16. {
  17. }
  18. MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
  19. MeshBufferType bufferType, DrawOperationType drawOp, IndexBuffer::IndexType indexType)
  20. {
  21. MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>())
  22. Mesh(numVertices, numIndices, vertexDesc, bufferType, drawOp, indexType));
  23. mesh->_setThisPtr(mesh);
  24. mesh->initialize();
  25. return mesh;
  26. }
  27. MeshPtr MeshManager::create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc,
  28. const Vector<SubMesh>& subMeshes, MeshBufferType bufferType, IndexBuffer::IndexType indexType)
  29. {
  30. MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>())
  31. Mesh(numVertices, numIndices, vertexDesc, subMeshes, bufferType, indexType));
  32. mesh->_setThisPtr(mesh);
  33. mesh->initialize();
  34. return mesh;
  35. }
  36. MeshPtr MeshManager::create(const MeshDataPtr& initialData, MeshBufferType bufferType, DrawOperationType drawOp)
  37. {
  38. MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>()) Mesh(initialData, bufferType, drawOp));
  39. mesh->_setThisPtr(mesh);
  40. mesh->initialize();
  41. return mesh;
  42. }
  43. MeshPtr MeshManager::create(const MeshDataPtr& initialData, const Vector<SubMesh>& subMeshes, MeshBufferType bufferType)
  44. {
  45. MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>()) Mesh(initialData, subMeshes, bufferType));
  46. mesh->_setThisPtr(mesh);
  47. mesh->initialize();
  48. return mesh;
  49. }
  50. MeshPtr MeshManager::createEmpty()
  51. {
  52. MeshPtr mesh = bs_core_ptr<Mesh, PoolAlloc>(new (bs_alloc<Mesh, PoolAlloc>()) Mesh());
  53. mesh->_setThisPtr(mesh);
  54. return mesh;
  55. }
  56. void MeshManager::onStartUp()
  57. {
  58. VertexDataDescPtr vertexDesc = bs_shared_ptr<VertexDataDesc>();
  59. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  60. mDummyMeshData = bs_shared_ptr<MeshData>(1, 3, vertexDesc);
  61. auto vecIter = mDummyMeshData->getVec3DataIter(VES_POSITION);
  62. vecIter.setValue(Vector3(0, 0, 0));
  63. auto indices = mDummyMeshData->getIndices32();
  64. indices[0] = 0;
  65. indices[1] = 0;
  66. indices[2] = 0;
  67. mDummyMesh = Mesh::create(mDummyMeshData);
  68. }
  69. }