BsMesh.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsMesh.h"
  4. #include "BsMeshRTTI.h"
  5. #include "BsMeshData.h"
  6. #include "BsDebug.h"
  7. #include "BsHardwareBufferManager.h"
  8. #include "BsMeshManager.h"
  9. #include "BsCoreThread.h"
  10. #include "BsAsyncOp.h"
  11. #include "BsVertexDataDesc.h"
  12. #include "BsResources.h"
  13. #include "BsRenderAPI.h"
  14. namespace BansheeEngine
  15. {
  16. MESH_DESC MESH_DESC::DEFAULT = MESH_DESC();
  17. MeshCore::MeshCore(const SPtr<MeshData>& initialMeshData, const MESH_DESC& desc)
  18. : MeshCoreBase(desc.numVertices, desc.numIndices, desc.subMeshes), mVertexData(nullptr), mIndexBuffer(nullptr)
  19. , mVertexDesc(desc.vertexDesc), mUsage(desc.usage), mIndexType(desc.indexType)
  20. , mTempInitialMeshData(initialMeshData), mSkeleton(desc.skeleton), mMorphShapes(desc.morphShapes)
  21. { }
  22. MeshCore::~MeshCore()
  23. {
  24. THROW_IF_NOT_CORE_THREAD;
  25. mVertexData = nullptr;
  26. mIndexBuffer = nullptr;
  27. mVertexDesc = nullptr;
  28. mTempInitialMeshData = nullptr;
  29. }
  30. void MeshCore::initialize()
  31. {
  32. THROW_IF_NOT_CORE_THREAD;
  33. bool isDynamic = (mUsage & MU_DYNAMIC) != 0;
  34. mIndexBuffer = HardwareBufferCoreManager::instance().createIndexBuffer(mIndexType,
  35. mProperties.mNumIndices, isDynamic ? GBU_DYNAMIC : GBU_STATIC);
  36. mVertexData = SPtr<VertexData>(bs_new<VertexData>());
  37. mVertexData->vertexCount = mProperties.mNumVertices;
  38. mVertexData->vertexDeclaration = HardwareBufferCoreManager::instance().createVertexDeclaration(mVertexDesc);
  39. for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
  40. {
  41. if (!mVertexDesc->hasStream(i))
  42. continue;
  43. SPtr<VertexBufferCore> vertexBuffer = HardwareBufferCoreManager::instance().createVertexBuffer(
  44. mVertexData->vertexDeclaration->getProperties().getVertexSize(i),
  45. mVertexData->vertexCount,
  46. isDynamic ? GBU_DYNAMIC : GBU_STATIC);
  47. mVertexData->setBuffer(i, vertexBuffer);
  48. }
  49. // TODO Low priority - DX11 (and maybe OpenGL)? allow an optimization that allows you to set
  50. // buffer data upon buffer construction, instead of setting it in a second step like I do here
  51. if (mTempInitialMeshData != nullptr)
  52. {
  53. writeSubresource(0, *mTempInitialMeshData, isDynamic);
  54. mTempInitialMeshData = nullptr;
  55. }
  56. MeshCoreBase::initialize();
  57. }
  58. SPtr<VertexData> MeshCore::getVertexData() const
  59. {
  60. THROW_IF_NOT_CORE_THREAD;
  61. return mVertexData;
  62. }
  63. SPtr<IndexBufferCore> MeshCore::getIndexBuffer() const
  64. {
  65. THROW_IF_NOT_CORE_THREAD;
  66. return mIndexBuffer;
  67. }
  68. SPtr<VertexDataDesc> MeshCore::getVertexDesc() const
  69. {
  70. THROW_IF_NOT_CORE_THREAD;
  71. return mVertexDesc;
  72. }
  73. void MeshCore::writeSubresource(UINT32 subresourceIdx, const MeshData& meshData, bool discardEntireBuffer, bool performUpdateBounds)
  74. {
  75. THROW_IF_NOT_CORE_THREAD;
  76. if (discardEntireBuffer)
  77. {
  78. if ((mUsage & MU_STATIC) != 0)
  79. {
  80. LOGWRN("Buffer discard is enabled but buffer was not created as dynamic. Disabling discard.");
  81. discardEntireBuffer = false;
  82. }
  83. }
  84. else
  85. {
  86. if ((mUsage & MU_DYNAMIC) != 0)
  87. {
  88. LOGWRN("Buffer discard is not enabled but buffer was created as dynamic. Enabling discard.");
  89. discardEntireBuffer = true;
  90. }
  91. }
  92. // Indices
  93. const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
  94. UINT32 indicesSize = meshData.getIndexBufferSize();
  95. UINT8* srcIdxData = meshData.getIndexData();
  96. if (meshData.getIndexElementSize() != ibProps.getIndexSize())
  97. {
  98. LOGERR("Provided index size doesn't match meshes index size. Needed: " +
  99. toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
  100. return;
  101. }
  102. if (indicesSize > mIndexBuffer->getSizeInBytes())
  103. {
  104. indicesSize = mIndexBuffer->getSizeInBytes();
  105. LOGERR("Index buffer values are being written out of valid range.");
  106. }
  107. mIndexBuffer->writeData(0, indicesSize, srcIdxData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  108. // Vertices
  109. for (UINT32 i = 0; i <= mVertexDesc->getMaxStreamIdx(); i++)
  110. {
  111. if (!mVertexDesc->hasStream(i))
  112. continue;
  113. if (!meshData.getVertexDesc()->hasStream(i))
  114. continue;
  115. // Ensure both have the same sized vertices
  116. UINT32 myVertSize = mVertexDesc->getVertexStride(i);
  117. UINT32 otherVertSize = meshData.getVertexDesc()->getVertexStride(i);
  118. if (myVertSize != otherVertSize)
  119. {
  120. LOGERR("Provided vertex size for stream " + toString(i) + " doesn't match meshes vertex size. Needed: " +
  121. toString(myVertSize) + ". Got: " + toString(otherVertSize));
  122. continue;
  123. }
  124. SPtr<VertexBufferCore> vertexBuffer = mVertexData->getBuffer(i);
  125. UINT32 bufferSize = meshData.getStreamSize(i);
  126. UINT8* srcVertBufferData = meshData.getStreamData(i);
  127. if (bufferSize > vertexBuffer->getSizeInBytes())
  128. {
  129. bufferSize = vertexBuffer->getSizeInBytes();
  130. LOGERR("Vertex buffer values for stream \"" + toString(i) + "\" are being written out of valid range.");
  131. }
  132. if (RenderAPICore::instance().getAPIInfo().getVertexColorFlipRequired())
  133. {
  134. UINT8* bufferCopy = (UINT8*)bs_alloc(bufferSize);
  135. memcpy(bufferCopy, srcVertBufferData, bufferSize); // TODO Low priority - Attempt to avoid this copy
  136. UINT32 vertexStride = meshData.getVertexDesc()->getVertexStride(i);
  137. for (INT32 semanticIdx = 0; semanticIdx < VertexBuffer::MAX_SEMANTIC_IDX; semanticIdx++)
  138. {
  139. if (!meshData.getVertexDesc()->hasElement(VES_COLOR, semanticIdx, i))
  140. continue;
  141. UINT8* colorData = bufferCopy + mVertexDesc->getElementOffsetFromStream(VES_COLOR, semanticIdx, i);
  142. for (UINT32 j = 0; j < mVertexData->vertexCount; j++)
  143. {
  144. UINT32* curColor = (UINT32*)colorData;
  145. (*curColor) = ((*curColor) & 0xFF00FF00) | ((*curColor >> 16) & 0x000000FF) | ((*curColor << 16) & 0x00FF0000);
  146. colorData += vertexStride;
  147. }
  148. }
  149. vertexBuffer->writeData(0, bufferSize, bufferCopy, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  150. bs_free(bufferCopy);
  151. }
  152. else
  153. {
  154. vertexBuffer->writeData(0, bufferSize, srcVertBufferData, discardEntireBuffer ? BufferWriteType::Discard : BufferWriteType::Normal);
  155. }
  156. }
  157. if (performUpdateBounds)
  158. updateBounds(meshData);
  159. }
  160. void MeshCore::readSubresource(UINT32 subresourceIdx, MeshData& meshData)
  161. {
  162. THROW_IF_NOT_CORE_THREAD;
  163. IndexType indexType = IT_32BIT;
  164. if (mIndexBuffer)
  165. indexType = mIndexBuffer->getProperties().getType();
  166. if (mIndexBuffer)
  167. {
  168. const IndexBufferProperties& ibProps = mIndexBuffer->getProperties();
  169. if (meshData.getIndexElementSize() != ibProps.getIndexSize())
  170. {
  171. LOGERR("Provided index size doesn't match meshes index size. Needed: " +
  172. toString(ibProps.getIndexSize()) + ". Got: " + toString(meshData.getIndexElementSize()));
  173. return;
  174. }
  175. UINT8* idxData = static_cast<UINT8*>(mIndexBuffer->lock(GBL_READ_ONLY));
  176. UINT32 idxElemSize = ibProps.getIndexSize();
  177. UINT8* indices = nullptr;
  178. if (indexType == IT_16BIT)
  179. indices = (UINT8*)meshData.getIndices16();
  180. else
  181. indices = (UINT8*)meshData.getIndices32();
  182. UINT32 numIndicesToCopy = std::min(mProperties.mNumIndices, meshData.getNumIndices());
  183. UINT32 indicesSize = numIndicesToCopy * idxElemSize;
  184. if (indicesSize > meshData.getIndexBufferSize())
  185. {
  186. LOGERR("Provided buffer doesn't have enough space to store mesh indices.");
  187. return;
  188. }
  189. memcpy(indices, idxData, numIndicesToCopy * idxElemSize);
  190. mIndexBuffer->unlock();
  191. }
  192. if (mVertexData)
  193. {
  194. auto vertexBuffers = mVertexData->getBuffers();
  195. UINT32 streamIdx = 0;
  196. for (auto iter = vertexBuffers.begin(); iter != vertexBuffers.end(); ++iter)
  197. {
  198. if (!meshData.getVertexDesc()->hasStream(streamIdx))
  199. continue;
  200. SPtr<VertexBufferCore> vertexBuffer = iter->second;
  201. const VertexBufferProperties& vbProps = vertexBuffer->getProperties();
  202. // Ensure both have the same sized vertices
  203. UINT32 myVertSize = mVertexDesc->getVertexStride(streamIdx);
  204. UINT32 otherVertSize = meshData.getVertexDesc()->getVertexStride(streamIdx);
  205. if (myVertSize != otherVertSize)
  206. {
  207. LOGERR("Provided vertex size for stream " + toString(streamIdx) + " doesn't match meshes vertex size. Needed: " +
  208. toString(myVertSize) + ". Got: " + toString(otherVertSize));
  209. continue;
  210. }
  211. UINT32 numVerticesToCopy = meshData.getNumVertices();
  212. UINT32 bufferSize = vbProps.getVertexSize() * numVerticesToCopy;
  213. if (bufferSize > vertexBuffer->getSizeInBytes())
  214. {
  215. LOGERR("Vertex buffer values for stream \"" + toString(streamIdx) + "\" are being read out of valid range.");
  216. continue;
  217. }
  218. UINT8* vertDataPtr = static_cast<UINT8*>(vertexBuffer->lock(GBL_READ_ONLY));
  219. UINT8* dest = meshData.getStreamData(streamIdx);
  220. memcpy(dest, vertDataPtr, bufferSize);
  221. vertexBuffer->unlock();
  222. streamIdx++;
  223. }
  224. }
  225. }
  226. void MeshCore::updateBounds(const MeshData& meshData)
  227. {
  228. mProperties.mBounds = meshData.calculateBounds();
  229. // TODO - Sync this to sim-thread possibly?
  230. }
  231. SPtr<MeshCore> MeshCore::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  232. int usage, DrawOperationType drawOp, IndexType indexType)
  233. {
  234. MESH_DESC desc;
  235. desc.numVertices = numVertices;
  236. desc.numIndices = numIndices;
  237. desc.vertexDesc = vertexDesc;
  238. desc.subMeshes.push_back(SubMesh(0, numIndices, drawOp));
  239. desc.usage = usage;
  240. desc.indexType = indexType;
  241. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(nullptr, desc));
  242. mesh->_setThisPtr(mesh);
  243. mesh->initialize();
  244. return mesh;
  245. }
  246. SPtr<MeshCore> MeshCore::create(const MESH_DESC& desc)
  247. {
  248. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(nullptr, desc));
  249. mesh->_setThisPtr(mesh);
  250. mesh->initialize();
  251. return mesh;
  252. }
  253. SPtr<MeshCore> MeshCore::create(const SPtr<MeshData>& initialMeshData, const MESH_DESC& desc)
  254. {
  255. MESH_DESC descCopy = desc;
  256. descCopy.numVertices = initialMeshData->getNumVertices();
  257. descCopy.numIndices = initialMeshData->getNumIndices();
  258. descCopy.vertexDesc = initialMeshData->getVertexDesc();
  259. descCopy.indexType = initialMeshData->getIndexType();
  260. SPtr<MeshCore> mesh = bs_shared_ptr<MeshCore>(new (bs_alloc<MeshCore>()) MeshCore(initialMeshData, descCopy));
  261. mesh->_setThisPtr(mesh);
  262. mesh->initialize();
  263. return mesh;
  264. }
  265. Mesh::Mesh(const MESH_DESC& desc)
  266. :MeshBase(desc.numVertices, desc.numIndices, desc.subMeshes), mVertexDesc(desc.vertexDesc), mUsage(desc.usage),
  267. mIndexType(desc.indexType), mSkeleton(desc.skeleton), mMorphShapes(desc.morphShapes)
  268. {
  269. }
  270. Mesh::Mesh(const SPtr<MeshData>& initialMeshData, const MESH_DESC& desc)
  271. :MeshBase(initialMeshData->getNumVertices(), initialMeshData->getNumIndices(), desc.subMeshes),
  272. mCPUData(initialMeshData), mVertexDesc(initialMeshData->getVertexDesc()),
  273. mUsage(desc.usage), mIndexType(initialMeshData->getIndexType()), mSkeleton(desc.skeleton),
  274. mMorphShapes(desc.morphShapes)
  275. {
  276. }
  277. Mesh::Mesh()
  278. :MeshBase(0, 0, DOT_TRIANGLE_LIST), mUsage(MU_STATIC), mIndexType(IT_32BIT)
  279. {
  280. }
  281. Mesh::~Mesh()
  282. {
  283. }
  284. AsyncOp Mesh::writeSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const SPtr<MeshData>& data, bool discardEntireBuffer)
  285. {
  286. updateBounds(*data);
  287. updateCPUBuffer(subresourceIdx, *data);
  288. data->_lock();
  289. std::function<void(const SPtr<MeshCore>&, UINT32, const SPtr<MeshData>&, bool, AsyncOp&)> func =
  290. [&](const SPtr<MeshCore>& mesh, UINT32 _subresourceIdx, const SPtr<MeshData>& _meshData, bool _discardEntireBuffer, AsyncOp& asyncOp)
  291. {
  292. mesh->writeSubresource(_subresourceIdx, *_meshData, _discardEntireBuffer, false);
  293. _meshData->_unlock();
  294. asyncOp._completeOperation();
  295. };
  296. return accessor.queueReturnCommand(std::bind(func, getCore(), subresourceIdx,
  297. data, discardEntireBuffer, std::placeholders::_1));
  298. }
  299. AsyncOp Mesh::readSubresource(CoreAccessor& accessor, UINT32 subresourceIdx, const SPtr<MeshData>& data)
  300. {
  301. data->_lock();
  302. std::function<void(const SPtr<MeshCore>&, UINT32, const SPtr<MeshData>&, AsyncOp&)> func =
  303. [&](const SPtr<MeshCore>& mesh, UINT32 _subresourceIdx, const SPtr<MeshData>& _meshData, AsyncOp& asyncOp)
  304. {
  305. mesh->readSubresource(_subresourceIdx, *_meshData);
  306. _meshData->_unlock();
  307. asyncOp._completeOperation();
  308. };
  309. return accessor.queueReturnCommand(std::bind(func, getCore(), subresourceIdx,
  310. data, std::placeholders::_1));
  311. }
  312. SPtr<MeshData> Mesh::allocateSubresourceBuffer(UINT32 subresourceIdx) const
  313. {
  314. SPtr<MeshData> meshData = bs_shared_ptr_new<MeshData>(mProperties.mNumVertices, mProperties.mNumIndices, mVertexDesc, mIndexType);
  315. return meshData;
  316. }
  317. void Mesh::initialize()
  318. {
  319. if (mCPUData != nullptr)
  320. updateBounds(*mCPUData);
  321. MeshBase::initialize();
  322. if ((mUsage & MU_CPUCACHED) != 0 && mCPUData == nullptr)
  323. createCPUBuffer();
  324. }
  325. void Mesh::updateBounds(const MeshData& meshData)
  326. {
  327. mProperties.mBounds = meshData.calculateBounds();
  328. markCoreDirty();
  329. }
  330. SPtr<MeshCore> Mesh::getCore() const
  331. {
  332. return std::static_pointer_cast<MeshCore>(mCoreSpecific);
  333. }
  334. SPtr<CoreObjectCore> Mesh::createCore() const
  335. {
  336. MESH_DESC desc;
  337. desc.numVertices = mProperties.mNumVertices;
  338. desc.numIndices = mProperties.mNumIndices;
  339. desc.vertexDesc = mVertexDesc;
  340. desc.subMeshes = mProperties.mSubMeshes;
  341. desc.usage = mUsage;
  342. desc.indexType = mIndexType;
  343. desc.skeleton = mSkeleton;
  344. desc.morphShapes = mMorphShapes;
  345. MeshCore* obj = new (bs_alloc<MeshCore>()) MeshCore(mCPUData, desc);
  346. SPtr<CoreObjectCore> meshCore = bs_shared_ptr<MeshCore>(obj);
  347. meshCore->_setThisPtr(meshCore);
  348. if ((mUsage & MU_CPUCACHED) == 0)
  349. mCPUData = nullptr;
  350. return meshCore;
  351. }
  352. void Mesh::updateCPUBuffer(UINT32 subresourceIdx, const MeshData& pixelData)
  353. {
  354. if ((mUsage & MU_CPUCACHED) == 0)
  355. return;
  356. if (subresourceIdx > 0)
  357. {
  358. LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. 1.");
  359. return;
  360. }
  361. if (pixelData.getNumIndices() != mProperties.getNumIndices() ||
  362. pixelData.getNumVertices() != mProperties.getNumVertices() ||
  363. pixelData.getIndexType() != mIndexType ||
  364. pixelData.getVertexDesc()->getVertexStride() != mVertexDesc->getVertexStride())
  365. {
  366. LOGERR("Provided buffer is not of valid dimensions or format in order to update this mesh.");
  367. return;
  368. }
  369. if (mCPUData->getSize() != pixelData.getSize())
  370. BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
  371. UINT8* dest = mCPUData->getData();
  372. UINT8* src = pixelData.getData();
  373. memcpy(dest, src, pixelData.getSize());
  374. }
  375. void Mesh::readData(MeshData& dest)
  376. {
  377. if ((mUsage & MU_CPUCACHED) == 0)
  378. {
  379. LOGERR("Attempting to read CPU data from a mesh that is created without CPU caching.");
  380. return;
  381. }
  382. if (dest.getNumIndices() != mProperties.getNumIndices() ||
  383. dest.getNumVertices() != mProperties.getNumVertices() ||
  384. dest.getIndexType() != mIndexType ||
  385. dest.getVertexDesc()->getVertexStride() != mVertexDesc->getVertexStride())
  386. {
  387. LOGERR("Provided buffer is not of valid dimensions or format in order to read from this mesh.");
  388. return;
  389. }
  390. if (mCPUData->getSize() != dest.getSize())
  391. BS_EXCEPT(InternalErrorException, "Buffer sizes don't match.");
  392. UINT8* srcPtr = mCPUData->getData();
  393. UINT8* destPtr = dest.getData();
  394. memcpy(destPtr, srcPtr, dest.getSize());
  395. }
  396. void Mesh::createCPUBuffer()
  397. {
  398. mCPUData = allocateSubresourceBuffer(0);
  399. }
  400. HMesh Mesh::dummy()
  401. {
  402. return MeshManager::instance().getDummyMesh();
  403. }
  404. /************************************************************************/
  405. /* SERIALIZATION */
  406. /************************************************************************/
  407. RTTITypeBase* Mesh::getRTTIStatic()
  408. {
  409. return MeshRTTI::instance();
  410. }
  411. RTTITypeBase* Mesh::getRTTI() const
  412. {
  413. return Mesh::getRTTIStatic();
  414. }
  415. /************************************************************************/
  416. /* STATICS */
  417. /************************************************************************/
  418. HMesh Mesh::create(UINT32 numVertices, UINT32 numIndices, const SPtr<VertexDataDesc>& vertexDesc,
  419. int usage, DrawOperationType drawOp, IndexType indexType)
  420. {
  421. MESH_DESC desc;
  422. desc.numVertices = numVertices;
  423. desc.numIndices = numIndices;
  424. desc.vertexDesc = vertexDesc;
  425. desc.usage = usage;
  426. desc.subMeshes.push_back(SubMesh(0, numIndices, drawOp));
  427. desc.indexType = indexType;
  428. SPtr<Mesh> meshPtr = _createPtr(desc);
  429. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  430. }
  431. HMesh Mesh::create(const MESH_DESC& desc)
  432. {
  433. SPtr<Mesh> meshPtr = _createPtr(desc);
  434. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  435. }
  436. HMesh Mesh::create(const SPtr<MeshData>& initialMeshData, const MESH_DESC& desc)
  437. {
  438. SPtr<Mesh> meshPtr = _createPtr(initialMeshData, desc);
  439. return static_resource_cast<Mesh>(gResources()._createResourceHandle(meshPtr));
  440. }
  441. SPtr<Mesh> Mesh::_createPtr(const MESH_DESC& desc)
  442. {
  443. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(desc));
  444. mesh->_setThisPtr(mesh);
  445. mesh->initialize();
  446. return mesh;
  447. }
  448. SPtr<Mesh> Mesh::_createPtr(const SPtr<MeshData>& initialMeshData, const MESH_DESC& desc)
  449. {
  450. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh(initialMeshData, desc));
  451. mesh->_setThisPtr(mesh);
  452. mesh->initialize();
  453. return mesh;
  454. }
  455. SPtr<Mesh> Mesh::createEmpty()
  456. {
  457. SPtr<Mesh> mesh = bs_core_ptr<Mesh>(new (bs_alloc<Mesh>()) Mesh());
  458. mesh->_setThisPtr(mesh);
  459. return mesh;
  460. }
  461. }