BsMeshManager.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. SPtr<Mesh> MeshManager::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  18. int usage, DrawOperationType drawOp, IndexType indexType, const SPtr<Skeleton>& skeleton)
  19. {
  20. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>())
  21. Mesh(numVertices, numIndices, vertexDesc, usage, drawOp, indexType, skeleton));
  22. mesh->_setThisPtr(mesh);
  23. mesh->initialize();
  24. return mesh;
  25. }
  26. SPtr<Mesh> MeshManager::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  27. const Vector<SubMesh>& subMeshes, int usage, IndexType indexType, const SPtr<Skeleton>& skeleton)
  28. {
  29. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>())
  30. Mesh(numVertices, numIndices, vertexDesc, subMeshes, usage, indexType, skeleton));
  31. mesh->_setThisPtr(mesh);
  32. mesh->initialize();
  33. return mesh;
  34. }
  35. SPtr<Mesh> MeshManager::create(const SPtr<MeshData>& initialData, int usage, DrawOperationType drawOp,
  36. const SPtr<Skeleton>& skeleton)
  37. {
  38. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(initialData, usage, drawOp, skeleton));
  39. mesh->_setThisPtr(mesh);
  40. mesh->initialize();
  41. return mesh;
  42. }
  43. SPtr<Mesh> MeshManager::create(const SPtr<MeshData>& initialData, const Vector<SubMesh>& subMeshes, int usage,
  44. const SPtr<Skeleton>& skeleton)
  45. {
  46. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(initialData, subMeshes, usage, skeleton));
  47. mesh->_setThisPtr(mesh);
  48. mesh->initialize();
  49. return mesh;
  50. }
  51. SPtr<Mesh> MeshManager::createEmpty()
  52. {
  53. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh());
  54. mesh->_setThisPtr(mesh);
  55. return mesh;
  56. }
  57. void MeshManager::onStartUp()
  58. {
  59. SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
  60. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  61. mDummyMeshData = bs_shared_ptr_new<MeshData>(1, 3, vertexDesc);
  62. auto vecIter = mDummyMeshData->getVec3DataIter(VES_POSITION);
  63. vecIter.setValue(Vector3(0, 0, 0));
  64. auto indices = mDummyMeshData->getIndices32();
  65. indices[0] = 0;
  66. indices[1] = 0;
  67. indices[2] = 0;
  68. mDummyMesh = Mesh::create(mDummyMeshData);
  69. }
  70. }