2
0

STLLoader.cpp 20 KB

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