BsMeshManager.cpp 2.5 KB

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