STLLoader.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2022, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Implementation of the STL importer class */
  35. #ifndef ASSIMP_BUILD_NO_STL_IMPORTER
  36. #include "STLLoader.h"
  37. #include <assimp/ParsingUtils.h>
  38. #include <assimp/fast_atof.h>
  39. #include <assimp/importerdesc.h>
  40. #include <assimp/scene.h>
  41. #include <assimp/DefaultLogger.hpp>
  42. #include <assimp/IOSystem.hpp>
  43. #include <memory>
  44. namespace Assimp {
  45. namespace {
  46. static constexpr aiImporterDesc desc = {
  47. "Stereolithography (STL) Importer",
  48. "",
  49. "",
  50. "",
  51. aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportBinaryFlavour,
  52. 0,
  53. 0,
  54. 0,
  55. 0,
  56. "stl"
  57. };
  58. // A valid binary STL buffer should consist of the following elements, in order:
  59. // 1) 80 byte header
  60. // 2) 4 byte face count
  61. // 3) 50 bytes per face
  62. static bool IsBinarySTL(const char *buffer, size_t fileSize) {
  63. if (fileSize < 84) {
  64. return false;
  65. }
  66. const char *facecount_pos = buffer + 80;
  67. uint32_t faceCount(0);
  68. ::memcpy(&faceCount, facecount_pos, sizeof(uint32_t));
  69. const uint32_t expectedBinaryFileSize = faceCount * 50 + 84;
  70. return expectedBinaryFileSize == fileSize;
  71. }
  72. static const size_t BufferSize = 500;
  73. static const char UnicodeBoundary = 127;
  74. // An ascii STL buffer will begin with "solid NAME", where NAME is optional.
  75. // Note: The "solid NAME" check is necessary, but not sufficient, to determine
  76. // if the buffer is ASCII; a binary header could also begin with "solid NAME".
  77. static bool IsAsciiSTL(const char *buffer, size_t fileSize) {
  78. if (IsBinarySTL(buffer, fileSize))
  79. return false;
  80. const char *bufferEnd = buffer + fileSize;
  81. if (!SkipSpaces(&buffer)) {
  82. return false;
  83. }
  84. if (buffer + 5 >= bufferEnd) {
  85. return false;
  86. }
  87. bool isASCII(strncmp(buffer, "solid", 5) == 0);
  88. if (isASCII) {
  89. // A lot of importers are write solid even if the file is binary. So we have to check for ASCII-characters.
  90. if (fileSize >= BufferSize) {
  91. isASCII = true;
  92. for (unsigned int i = 0; i < BufferSize; i++) {
  93. if (buffer[i] > UnicodeBoundary) {
  94. isASCII = false;
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. return isASCII;
  101. }
  102. } // namespace
  103. // ------------------------------------------------------------------------------------------------
  104. // Constructor to be privately used by Importer
  105. STLImporter::STLImporter() :
  106. mBuffer(),
  107. mFileSize(0),
  108. mScene() {
  109. // empty
  110. }
  111. // ------------------------------------------------------------------------------------------------
  112. // Destructor, private as well
  113. STLImporter::~STLImporter() = default;
  114. // ------------------------------------------------------------------------------------------------
  115. // Returns whether the class can handle the format of the given file.
  116. bool STLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
  117. static const char *tokens[] = { "STL", "solid" };
  118. return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
  119. }
  120. // ------------------------------------------------------------------------------------------------
  121. const aiImporterDesc *STLImporter::GetInfo() const {
  122. return &desc;
  123. }
  124. void addFacesToMesh(aiMesh *pMesh) {
  125. pMesh->mFaces = new aiFace[pMesh->mNumFaces];
  126. for (unsigned int i = 0, p = 0; i < pMesh->mNumFaces; ++i) {
  127. aiFace &face = pMesh->mFaces[i];
  128. face.mIndices = new unsigned int[face.mNumIndices = 3];
  129. for (unsigned int o = 0; o < 3; ++o, ++p) {
  130. face.mIndices[o] = p;
  131. }
  132. }
  133. }
  134. // ------------------------------------------------------------------------------------------------
  135. // Imports the given file into the given scene structure.
  136. void STLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
  137. std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
  138. // Check whether we can read from the file
  139. if (file == nullptr) {
  140. throw DeadlyImportError("Failed to open STL file ", pFile, ".");
  141. }
  142. mFileSize = file->FileSize();
  143. // allocate storage and copy the contents of the file to a memory buffer
  144. // (terminate it with zero)
  145. std::vector<char> buffer2;
  146. TextFileToBuffer(file.get(), buffer2);
  147. mScene = pScene;
  148. mBuffer = &buffer2[0];
  149. // the default vertex color is light gray.
  150. mClrColorDefault.r = mClrColorDefault.g = mClrColorDefault.b = mClrColorDefault.a = (ai_real)0.6;
  151. // allocate a single node
  152. mScene->mRootNode = new aiNode();
  153. bool bMatClr = false;
  154. if (IsBinarySTL(mBuffer, mFileSize)) {
  155. bMatClr = LoadBinaryFile();
  156. } else if (IsAsciiSTL(mBuffer, mFileSize)) {
  157. LoadASCIIFile(mScene->mRootNode);
  158. } else {
  159. throw DeadlyImportError("Failed to determine STL storage representation for ", pFile, ".");
  160. }
  161. // create a single default material, using a white diffuse color for consistency with
  162. // other geometric types (e.g., PLY).
  163. aiMaterial *pcMat = new aiMaterial();
  164. aiString s;
  165. s.Set(AI_DEFAULT_MATERIAL_NAME);
  166. pcMat->AddProperty(&s, AI_MATKEY_NAME);
  167. aiColor4D clrDiffuse(ai_real(1.0), ai_real(1.0), ai_real(1.0), ai_real(1.0));
  168. if (bMatClr) {
  169. clrDiffuse = mClrColorDefault;
  170. }
  171. pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
  172. pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_SPECULAR);
  173. clrDiffuse = aiColor4D(ai_real(0.05), ai_real(0.05), ai_real(0.05), ai_real(1.0));
  174. pcMat->AddProperty(&clrDiffuse, 1, AI_MATKEY_COLOR_AMBIENT);
  175. mScene->mNumMaterials = 1;
  176. mScene->mMaterials = new aiMaterial *[1];
  177. mScene->mMaterials[0] = pcMat;
  178. mBuffer = nullptr;
  179. }
  180. // ------------------------------------------------------------------------------------------------
  181. // Read an ASCII STL file
  182. void STLImporter::LoadASCIIFile(aiNode *root) {
  183. std::vector<aiMesh *> meshes;
  184. std::vector<aiNode *> nodes;
  185. const char *sz = mBuffer;
  186. const char *bufferEnd = mBuffer + mFileSize;
  187. std::vector<aiVector3D> positionBuffer;
  188. std::vector<aiVector3D> normalBuffer;
  189. // try to guess how many vertices we could have
  190. // assume we'll need 160 bytes for each face
  191. size_t sizeEstimate = std::max(1ull, mFileSize / 160ull) * 3ull;
  192. positionBuffer.reserve(sizeEstimate);
  193. normalBuffer.reserve(sizeEstimate);
  194. while (IsAsciiSTL(sz, static_cast<unsigned int>(bufferEnd - sz))) {
  195. std::vector<unsigned int> meshIndices;
  196. aiMesh *pMesh = new aiMesh();
  197. pMesh->mMaterialIndex = 0;
  198. meshIndices.push_back((unsigned int)meshes.size());
  199. meshes.push_back(pMesh);
  200. aiNode *node = new aiNode;
  201. node->mParent = root;
  202. nodes.push_back(node);
  203. SkipSpaces(&sz);
  204. ai_assert(!IsLineEnd(sz));
  205. sz += 5; // skip the "solid"
  206. SkipSpaces(&sz);
  207. const char *szMe = sz;
  208. while (!IsSpaceOrNewLine(*sz)) {
  209. sz++;
  210. }
  211. size_t temp = (size_t)(sz - szMe);
  212. // setup the name of the node
  213. if (temp) {
  214. if (temp >= MAXLEN) {
  215. throw DeadlyImportError("STL: Node name too long");
  216. }
  217. std::string name(szMe, temp);
  218. node->mName.Set(name.c_str());
  219. pMesh->mName.Set(name.c_str());
  220. } else {
  221. mScene->mRootNode->mName.Set("<STL_ASCII>");
  222. }
  223. unsigned int faceVertexCounter = 3;
  224. for (;;) {
  225. // go to the next token
  226. if (!SkipSpacesAndLineEnd(&sz)) {
  227. // seems we're finished although there was no end marker
  228. ASSIMP_LOG_WARN("STL: unexpected EOF. \'endsolid\' keyword was expected");
  229. break;
  230. }
  231. // facet normal -0.13 -0.13 -0.98
  232. if (!strncmp(sz, "facet", 5) && IsSpaceOrNewLine(*(sz + 5)) && *(sz + 5) != '\0') {
  233. if (faceVertexCounter != 3) {
  234. ASSIMP_LOG_WARN("STL: A new facet begins but the old is not yet complete");
  235. }
  236. faceVertexCounter = 0;
  237. sz += 6;
  238. SkipSpaces(&sz);
  239. if (strncmp(sz, "normal", 6)) {
  240. ASSIMP_LOG_WARN("STL: a facet normal vector was expected but not found");
  241. } else {
  242. if (sz[6] == '\0') {
  243. throw DeadlyImportError("STL: unexpected EOF while parsing facet");
  244. }
  245. aiVector3D vn;
  246. sz += 7;
  247. SkipSpaces(&sz);
  248. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn.x);
  249. SkipSpaces(&sz);
  250. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn.y);
  251. SkipSpaces(&sz);
  252. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn.z);
  253. normalBuffer.emplace_back(vn);
  254. normalBuffer.emplace_back(vn);
  255. normalBuffer.emplace_back(vn);
  256. }
  257. } else if (!strncmp(sz, "vertex", 6) && IsSpaceOrNewLine(*(sz + 6))) { // vertex 1.50000 1.50000 0.00000
  258. if (faceVertexCounter >= 3) {
  259. ASSIMP_LOG_ERROR("STL: a facet with more than 3 vertices has been found");
  260. ++sz;
  261. } else {
  262. if (sz[6] == '\0') {
  263. throw DeadlyImportError("STL: unexpected EOF while parsing facet");
  264. }
  265. sz += 7;
  266. SkipSpaces(&sz);
  267. positionBuffer.emplace_back();
  268. aiVector3D *vn = &positionBuffer.back();
  269. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn->x);
  270. SkipSpaces(&sz);
  271. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn->y);
  272. SkipSpaces(&sz);
  273. sz = fast_atoreal_move<ai_real>(sz, (ai_real &)vn->z);
  274. faceVertexCounter++;
  275. }
  276. } else if (!::strncmp(sz, "endsolid", 8)) {
  277. do {
  278. ++sz;
  279. } while (!IsLineEnd(*sz));
  280. SkipSpacesAndLineEnd(&sz);
  281. // finished!
  282. break;
  283. } else { // else skip the whole identifier
  284. do {
  285. ++sz;
  286. } while (!IsSpaceOrNewLine(*sz));
  287. }
  288. }
  289. if (positionBuffer.empty()) {
  290. pMesh->mNumFaces = 0;
  291. ASSIMP_LOG_WARN("STL: mesh is empty or invalid; no data loaded");
  292. }
  293. if (positionBuffer.size() % 3 != 0) {
  294. pMesh->mNumFaces = 0;
  295. throw DeadlyImportError("STL: Invalid number of vertices");
  296. }
  297. if (normalBuffer.size() != positionBuffer.size()) {
  298. pMesh->mNumFaces = 0;
  299. throw DeadlyImportError("Normal buffer size does not match position buffer size");
  300. }
  301. // only process position buffer when filled, else exception when accessing with index operator
  302. // see line 353: only warning is triggered
  303. // see line 373(now): access to empty position buffer with index operator forced exception
  304. if (!positionBuffer.empty()) {
  305. pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
  306. pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
  307. pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
  308. for (size_t i = 0; i < pMesh->mNumVertices; ++i) {
  309. pMesh->mVertices[i].x = positionBuffer[i].x;
  310. pMesh->mVertices[i].y = positionBuffer[i].y;
  311. pMesh->mVertices[i].z = positionBuffer[i].z;
  312. }
  313. positionBuffer.clear();
  314. }
  315. // also only process normalBuffer when filled, else exception when accessing with index operator
  316. if (!normalBuffer.empty()) {
  317. pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
  318. for (size_t i = 0; i < pMesh->mNumVertices; ++i) {
  319. pMesh->mNormals[i].x = normalBuffer[i].x;
  320. pMesh->mNormals[i].y = normalBuffer[i].y;
  321. pMesh->mNormals[i].z = normalBuffer[i].z;
  322. }
  323. normalBuffer.clear();
  324. }
  325. // now copy faces
  326. addFacesToMesh(pMesh);
  327. // assign the meshes to the current node
  328. pushMeshesToNode(meshIndices, node);
  329. }
  330. // now add the loaded meshes
  331. mScene->mNumMeshes = (unsigned int)meshes.size();
  332. mScene->mMeshes = new aiMesh *[mScene->mNumMeshes];
  333. for (size_t i = 0; i < meshes.size(); i++) {
  334. mScene->mMeshes[i] = meshes[i];
  335. }
  336. root->mNumChildren = (unsigned int)nodes.size();
  337. root->mChildren = new aiNode *[root->mNumChildren];
  338. for (size_t i = 0; i < nodes.size(); ++i) {
  339. root->mChildren[i] = nodes[i];
  340. }
  341. }
  342. // ------------------------------------------------------------------------------------------------
  343. // Read a binary STL file
  344. bool STLImporter::LoadBinaryFile() {
  345. // allocate one mesh
  346. mScene->mNumMeshes = 1;
  347. mScene->mMeshes = new aiMesh *[1];
  348. aiMesh *pMesh = mScene->mMeshes[0] = new aiMesh();
  349. pMesh->mMaterialIndex = 0;
  350. // skip the first 80 bytes
  351. if (mFileSize < 84) {
  352. throw DeadlyImportError("STL: file is too small for the header");
  353. }
  354. bool bIsMaterialise = false;
  355. // search for an occurrence of "COLOR=" in the header
  356. const unsigned char *sz2 = (const unsigned char *)mBuffer;
  357. const unsigned char *const szEnd = sz2 + 80;
  358. while (sz2 < szEnd) {
  359. if ('C' == *sz2++ && 'O' == *sz2++ && 'L' == *sz2++ &&
  360. 'O' == *sz2++ && 'R' == *sz2++ && '=' == *sz2++) {
  361. // read the default vertex color for facets
  362. bIsMaterialise = true;
  363. ASSIMP_LOG_INFO("STL: Taking code path for Materialise files");
  364. const ai_real invByte = (ai_real)1.0 / (ai_real)255.0;
  365. mClrColorDefault.r = (*sz2++) * invByte;
  366. mClrColorDefault.g = (*sz2++) * invByte;
  367. mClrColorDefault.b = (*sz2++) * invByte;
  368. mClrColorDefault.a = (*sz2++) * invByte;
  369. break;
  370. }
  371. }
  372. const unsigned char *sz = (const unsigned char *)mBuffer + 80;
  373. // now read the number of facets
  374. mScene->mRootNode->mName.Set("<STL_BINARY>");
  375. pMesh->mNumFaces = *((uint32_t *)sz);
  376. sz += 4;
  377. if (mFileSize < 84ull + pMesh->mNumFaces * 50ull) {
  378. throw DeadlyImportError("STL: file is too small to hold all facets");
  379. }
  380. if (!pMesh->mNumFaces) {
  381. throw DeadlyImportError("STL: file is empty. There are no facets defined");
  382. }
  383. pMesh->mNumVertices = pMesh->mNumFaces * 3;
  384. aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
  385. aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
  386. aiVector3f *theVec;
  387. aiVector3f theVec3F;
  388. for (unsigned int i = 0; i < pMesh->mNumFaces; ++i) {
  389. // NOTE: Blender sometimes writes empty normals ... this is not
  390. // our fault ... the RemoveInvalidData helper step should fix that
  391. // There's one normal for the face in the STL; use it three times
  392. // for vertex normals
  393. theVec = (aiVector3f *)sz;
  394. ::memcpy(&theVec3F, theVec, sizeof(aiVector3f));
  395. vn->x = theVec3F.x;
  396. vn->y = theVec3F.y;
  397. vn->z = theVec3F.z;
  398. *(vn + 1) = *vn;
  399. *(vn + 2) = *vn;
  400. ++theVec;
  401. vn += 3;
  402. // vertex 1
  403. ::memcpy(&theVec3F, theVec, sizeof(aiVector3f));
  404. vp->x = theVec3F.x;
  405. vp->y = theVec3F.y;
  406. vp->z = theVec3F.z;
  407. ++theVec;
  408. ++vp;
  409. // vertex 2
  410. ::memcpy(&theVec3F, theVec, sizeof(aiVector3f));
  411. vp->x = theVec3F.x;
  412. vp->y = theVec3F.y;
  413. vp->z = theVec3F.z;
  414. ++theVec;
  415. ++vp;
  416. // vertex 3
  417. ::memcpy(&theVec3F, theVec, sizeof(aiVector3f));
  418. vp->x = theVec3F.x;
  419. vp->y = theVec3F.y;
  420. vp->z = theVec3F.z;
  421. ++theVec;
  422. ++vp;
  423. sz = (const unsigned char *)theVec;
  424. uint16_t color = *((uint16_t *)sz);
  425. sz += 2;
  426. if (color & (1 << 15)) {
  427. // seems we need to take the color
  428. if (!pMesh->mColors[0]) {
  429. pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
  430. for (unsigned int j = 0; j < pMesh->mNumVertices; ++j) {
  431. *pMesh->mColors[0]++ = mClrColorDefault;
  432. }
  433. pMesh->mColors[0] -= pMesh->mNumVertices;
  434. ASSIMP_LOG_INFO("STL: Mesh has vertex colors");
  435. }
  436. aiColor4D *clr = &pMesh->mColors[0][i * 3];
  437. clr->a = 1.0;
  438. const ai_real invVal((ai_real)1.0 / (ai_real)31.0);
  439. if (bIsMaterialise) // this is reversed
  440. {
  441. clr->r = (color & 0x1fu) * invVal;
  442. clr->g = ((color & (0x1fu << 5)) >> 5u) * invVal;
  443. clr->b = ((color & (0x1fu << 10)) >> 10u) * invVal;
  444. } else {
  445. clr->b = (color & 0x1fu) * invVal;
  446. clr->g = ((color & (0x1fu << 5)) >> 5u) * invVal;
  447. clr->r = ((color & (0x1fu << 10)) >> 10u) * invVal;
  448. }
  449. // assign the color to all vertices of the face
  450. *(clr + 1) = *clr;
  451. *(clr + 2) = *clr;
  452. }
  453. }
  454. // now copy faces
  455. addFacesToMesh(pMesh);
  456. aiNode *root = mScene->mRootNode;
  457. // allocate one node
  458. aiNode *node = new aiNode();
  459. node->mParent = root;
  460. root->mNumChildren = 1u;
  461. root->mChildren = new aiNode *[root->mNumChildren];
  462. root->mChildren[0] = node;
  463. // add all created meshes to the single node
  464. node->mNumMeshes = mScene->mNumMeshes;
  465. node->mMeshes = new unsigned int[mScene->mNumMeshes];
  466. for (unsigned int i = 0; i < mScene->mNumMeshes; ++i) {
  467. node->mMeshes[i] = i;
  468. }
  469. if (bIsMaterialise && !pMesh->mColors[0]) {
  470. // use the color as diffuse material color
  471. return true;
  472. }
  473. return false;
  474. }
  475. void STLImporter::pushMeshesToNode(std::vector<unsigned int> &meshIndices, aiNode *node) {
  476. ai_assert(nullptr != node);
  477. if (meshIndices.empty()) {
  478. return;
  479. }
  480. node->mNumMeshes = static_cast<unsigned int>(meshIndices.size());
  481. node->mMeshes = new unsigned int[meshIndices.size()];
  482. for (size_t i = 0; i < meshIndices.size(); ++i) {
  483. node->mMeshes[i] = meshIndices[i];
  484. }
  485. meshIndices.clear();
  486. }
  487. } // namespace Assimp
  488. #endif // !! ASSIMP_BUILD_NO_STL_IMPORTER