glTFImporter.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef ASSIMP_BUILD_NO_GLTF_IMPORTER
  34. #include "glTFImporter.h"
  35. #include "StringComparison.h"
  36. #include "boost/scoped_ptr.hpp"
  37. #include <assimp/Importer.hpp>
  38. #include <assimp/scene.h>
  39. #include <assimp/ai_assert.h>
  40. #include <assimp/DefaultLogger.hpp>
  41. #include <boost/shared_ptr.hpp>
  42. #include "glTFAsset.h"
  43. using namespace Assimp;
  44. using namespace glTF;
  45. //
  46. // glTFImporter
  47. //
  48. static const aiImporterDesc desc = {
  49. "glTF Importer",
  50. "",
  51. "",
  52. "",
  53. aiImporterFlags_SupportTextFlavour | aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportCompressedFlavour
  54. | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental,
  55. 0,
  56. 0,
  57. 0,
  58. 0,
  59. "gltf glb"
  60. };
  61. glTFImporter::glTFImporter()
  62. : BaseImporter()
  63. , meshOffsets()
  64. , embeddedTexIdxs()
  65. , mScene( NULL ) {
  66. // empty
  67. }
  68. glTFImporter::~glTFImporter() {
  69. // empty
  70. }
  71. const aiImporterDesc* glTFImporter::GetInfo() const
  72. {
  73. return &desc;
  74. }
  75. bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
  76. {
  77. const std::string& extension = GetExtension(pFile);
  78. if (extension == "gltf" || extension == "glb")
  79. return true;
  80. if ((checkSig || !extension.length()) && pIOHandler) {
  81. char buffer[4];
  82. boost::scoped_ptr<IOStream> pStream(pIOHandler->Open(pFile));
  83. if (pStream && pStream->Read(buffer, sizeof(buffer), 1) == 1) {
  84. if (memcmp(buffer, AI_GLB_MAGIC_NUMBER, sizeof(buffer)) == 0) {
  85. return true; // Has GLB header
  86. }
  87. else if (memcmp(buffer, "{\r\n ", sizeof(buffer)) == 0
  88. || memcmp(buffer, "{\n ", sizeof(buffer)) == 0) {
  89. // seems a JSON file, and we're the only format that can read them
  90. return true;
  91. }
  92. }
  93. }
  94. return false;
  95. }
  96. //static void CopyValue(const glTF::vec3& v, aiColor3D& out)
  97. //{
  98. // out.r = v[0]; out.g = v[1]; out.b = v[2];
  99. //}
  100. static void CopyValue(const glTF::vec4& v, aiColor4D& out)
  101. {
  102. out.r = v[0]; out.g = v[1]; out.b = v[2]; out.a = v[3];
  103. }
  104. static void CopyValue(const glTF::vec4& v, aiColor3D& out)
  105. {
  106. out.r = v[0]; out.g = v[1]; out.b = v[2];
  107. }
  108. static void CopyValue(const glTF::vec3& v, aiVector3D& out)
  109. {
  110. out.x = v[0]; out.y = v[1]; out.z = v[2];
  111. }
  112. static void CopyValue(const glTF::vec4& v, aiQuaternion& out)
  113. {
  114. out.x = v[0]; out.y = v[1]; out.z = v[2]; out.w = v[3];
  115. }
  116. static void CopyValue(const glTF::mat4& v, aiMatrix4x4& o)
  117. {
  118. o.a1 = v[ 0]; o.b1 = v[ 1]; o.c1 = v[ 2]; o.d1 = v[ 3];
  119. o.a2 = v[ 4]; o.b2 = v[ 5]; o.c2 = v[ 6]; o.d2 = v[ 7];
  120. o.a3 = v[ 8]; o.b3 = v[ 9]; o.c3 = v[10]; o.d3 = v[11];
  121. o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
  122. }
  123. inline void SetMaterialColorProperty(std::vector<int>& embeddedTexIdxs, Asset& r, glTF::TexProperty prop, aiMaterial* mat,
  124. aiTextureType texType, const char* pKey, unsigned int type, unsigned int idx)
  125. {
  126. if (prop.texture) {
  127. if (prop.texture->source) {
  128. aiString uri(prop.texture->source->uri);
  129. int texIdx = embeddedTexIdxs[prop.texture->source.GetIndex()];
  130. if (texIdx != -1) { // embedded
  131. // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
  132. uri.data[0] = '*';
  133. uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx);
  134. }
  135. mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0);
  136. }
  137. }
  138. else {
  139. aiColor4D col;
  140. CopyValue(prop.color, col);
  141. if (col.r != 1.f || col.g != 1.f || col.b != 1.f || col.a != 1.f) {
  142. mat->AddProperty(&col, 1, pKey, type, idx);
  143. }
  144. }
  145. }
  146. void glTFImporter::ImportMaterials(glTF::Asset& r)
  147. {
  148. mScene->mNumMaterials = r.materials.Size();
  149. mScene->mMaterials = new aiMaterial*[mScene->mNumMaterials];
  150. for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) {
  151. aiMaterial* aimat = mScene->mMaterials[i] = new aiMaterial();
  152. Material& mat = r.materials[i];
  153. /*if (!mat.name.empty())*/ {
  154. aiString str(mat.id /*mat.name*/);
  155. aimat->AddProperty(&str, AI_MATKEY_NAME);
  156. }
  157. SetMaterialColorProperty(embeddedTexIdxs, r, mat.diffuse, aimat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE);
  158. SetMaterialColorProperty(embeddedTexIdxs, r, mat.specular, aimat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR);
  159. SetMaterialColorProperty(embeddedTexIdxs, r, mat.ambient, aimat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
  160. if (mat.shininess > 0.f) {
  161. aimat->AddProperty(&mat.shininess, 1, AI_MATKEY_SHININESS);
  162. }
  163. }
  164. if (mScene->mNumMaterials == 0) {
  165. mScene->mNumMaterials = 1;
  166. mScene->mMaterials = new aiMaterial*[1];
  167. mScene->mMaterials[0] = new aiMaterial();
  168. }
  169. }
  170. inline void SetFace(aiFace& face, int a)
  171. {
  172. face.mNumIndices = 1;
  173. face.mIndices = new unsigned int[1];
  174. face.mIndices[0] = a;
  175. }
  176. inline void SetFace(aiFace& face, int a, int b)
  177. {
  178. face.mNumIndices = 2;
  179. face.mIndices = new unsigned int[2];
  180. face.mIndices[0] = a;
  181. face.mIndices[1] = b;
  182. }
  183. inline void SetFace(aiFace& face, int a, int b, int c)
  184. {
  185. face.mNumIndices = 3;
  186. face.mIndices = new unsigned int[3];
  187. face.mIndices[0] = a;
  188. face.mIndices[1] = b;
  189. face.mIndices[2] = c;
  190. }
  191. void glTFImporter::ImportMeshes(glTF::Asset& r)
  192. {
  193. std::vector<aiMesh*> meshes;
  194. unsigned int k = 0;
  195. for (unsigned int m = 0; m < r.meshes.Size(); ++m) {
  196. Mesh& mesh = r.meshes[m];
  197. meshOffsets.push_back(k);
  198. k += mesh.primitives.size();
  199. for (unsigned int p = 0; p < mesh.primitives.size(); ++p) {
  200. Mesh::Primitive& prim = mesh.primitives[p];
  201. aiMesh* aim = new aiMesh();
  202. meshes.push_back(aim);
  203. aim->mName = mesh.id;
  204. if (mesh.primitives.size() > 1) {
  205. size_t& len = aim->mName.length;
  206. aim->mName.data[len] = '-';
  207. len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, MAXLEN - len - 1, p);
  208. }
  209. switch (prim.mode) {
  210. case PrimitiveMode_POINTS:
  211. aim->mPrimitiveTypes |= aiPrimitiveType_POINT;
  212. break;
  213. case PrimitiveMode_LINES:
  214. case PrimitiveMode_LINE_LOOP:
  215. case PrimitiveMode_LINE_STRIP:
  216. aim->mPrimitiveTypes |= aiPrimitiveType_LINE;
  217. break;
  218. case PrimitiveMode_TRIANGLES:
  219. case PrimitiveMode_TRIANGLE_STRIP:
  220. case PrimitiveMode_TRIANGLE_FAN:
  221. aim->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
  222. break;
  223. }
  224. Mesh::Primitive::Attributes& attr = prim.attributes;
  225. if (attr.position.size() > 0 && attr.position[0]) {
  226. aim->mNumVertices = attr.position[0]->count;
  227. attr.position[0]->ExtractData(aim->mVertices);
  228. }
  229. if (attr.normal.size() > 0 && attr.normal[0]) {
  230. attr.normal[0]->ExtractData(aim->mNormals);
  231. }
  232. for (size_t tc = 0; tc < attr.texcoord.size() && tc <= AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
  233. attr.texcoord[tc]->ExtractData(aim->mTextureCoords[tc]);
  234. aim->mNumUVComponents[tc] = attr.texcoord[tc]->GetNumComponents();
  235. }
  236. if (prim.indices) {
  237. aiFace* faces = 0;
  238. size_t nFaces = 0;
  239. unsigned int count = prim.indices->count;
  240. Accessor::Indexer data = prim.indices->GetIndexer();
  241. switch (prim.mode) {
  242. case PrimitiveMode_POINTS: {
  243. nFaces = count;
  244. faces = new aiFace[nFaces];
  245. for (unsigned int i = 0; i < count; ++i) {
  246. SetFace(faces[i], data.GetUInt(i));
  247. }
  248. break;
  249. }
  250. case PrimitiveMode_LINES: {
  251. nFaces = count / 2;
  252. faces = new aiFace[nFaces];
  253. for (unsigned int i = 0; i < count; i += 2) {
  254. SetFace(faces[i / 2], data.GetUInt(i), data.GetUInt(i + 1));
  255. }
  256. break;
  257. }
  258. case PrimitiveMode_LINE_LOOP:
  259. case PrimitiveMode_LINE_STRIP: {
  260. nFaces = count - ((prim.mode == PrimitiveMode_LINE_STRIP) ? 1 : 0);
  261. faces = new aiFace[nFaces];
  262. SetFace(faces[0], data.GetUInt(0), data.GetUInt(1));
  263. for (unsigned int i = 2; i < count; ++i) {
  264. SetFace(faces[i - 1], faces[i - 2].mIndices[1], data.GetUInt(i));
  265. }
  266. if (prim.mode == PrimitiveMode_LINE_LOOP) { // close the loop
  267. SetFace(faces[count - 1], faces[count - 2].mIndices[1], faces[0].mIndices[0]);
  268. }
  269. break;
  270. }
  271. case PrimitiveMode_TRIANGLES: {
  272. nFaces = count / 3;
  273. faces = new aiFace[nFaces];
  274. for (unsigned int i = 0; i < count; i += 3) {
  275. SetFace(faces[i / 3], data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2));
  276. }
  277. break;
  278. }
  279. case PrimitiveMode_TRIANGLE_STRIP: {
  280. nFaces = count - 2;
  281. faces = new aiFace[nFaces];
  282. SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
  283. for (unsigned int i = 3; i < count; ++i) {
  284. SetFace(faces[i - 2], faces[i - 1].mIndices[1], faces[i - 1].mIndices[2], data.GetUInt(i));
  285. }
  286. break;
  287. }
  288. case PrimitiveMode_TRIANGLE_FAN:
  289. nFaces = count - 2;
  290. faces = new aiFace[nFaces];
  291. SetFace(faces[0], data.GetUInt(0), data.GetUInt(1), data.GetUInt(2));
  292. for (unsigned int i = 3; i < count; ++i) {
  293. SetFace(faces[i - 2], faces[0].mIndices[0], faces[i - 1].mIndices[2], data.GetUInt(i));
  294. }
  295. break;
  296. }
  297. if (faces) {
  298. aim->mFaces = faces;
  299. aim->mNumFaces = nFaces;
  300. }
  301. }
  302. if (prim.material) {
  303. aim->mMaterialIndex = prim.material.GetIndex();
  304. }
  305. }
  306. }
  307. meshOffsets.push_back(k);
  308. CopyVector(meshes, mScene->mMeshes, mScene->mNumMeshes);
  309. }
  310. void glTFImporter::ImportCameras(glTF::Asset& r)
  311. {
  312. if (!r.cameras.Size()) return;
  313. mScene->mNumCameras = r.cameras.Size();
  314. mScene->mCameras = new aiCamera*[r.cameras.Size()];
  315. for (size_t i = 0; i < r.cameras.Size(); ++i) {
  316. Camera& cam = r.cameras[i];
  317. aiCamera* aicam = mScene->mCameras[i] = new aiCamera();
  318. if (cam.type == Camera::Perspective) {
  319. aicam->mAspect = cam.perspective.aspectRatio;
  320. aicam->mHorizontalFOV = cam.perspective.yfov * aicam->mAspect;
  321. aicam->mClipPlaneFar = cam.perspective.zfar;
  322. aicam->mClipPlaneNear = cam.perspective.znear;
  323. }
  324. else {
  325. // assimp does not support orthographic cameras
  326. }
  327. }
  328. }
  329. void glTFImporter::ImportLights(glTF::Asset& r)
  330. {
  331. if (!r.lights.Size()) return;
  332. mScene->mNumLights = r.lights.Size();
  333. mScene->mLights = new aiLight*[r.lights.Size()];
  334. for (size_t i = 0; i < r.lights.Size(); ++i) {
  335. Light& l = r.lights[i];
  336. aiLight* ail = mScene->mLights[i] = new aiLight();
  337. switch (l.type) {
  338. case Light::Type_directional:
  339. ail->mType = aiLightSource_DIRECTIONAL; break;
  340. case Light::Type_spot:
  341. ail->mType = aiLightSource_SPOT; break;
  342. case Light::Type_ambient:
  343. ail->mType = aiLightSource_AMBIENT; break;
  344. default: // Light::Type_point
  345. ail->mType = aiLightSource_POINT; break;
  346. }
  347. CopyValue(l.color, ail->mColorAmbient);
  348. CopyValue(l.color, ail->mColorDiffuse);
  349. CopyValue(l.color, ail->mColorSpecular);
  350. ail->mAngleOuterCone = l.falloffAngle;
  351. ail->mAngleInnerCone = l.falloffExponent; // TODO fix this, it does not look right at all
  352. ail->mAttenuationConstant = l.constantAttenuation;
  353. ail->mAttenuationLinear = l.linearAttenuation;
  354. ail->mAttenuationQuadratic = l.quadraticAttenuation;
  355. }
  356. }
  357. aiNode* ImportNode(aiScene* pScene, glTF::Asset& r, std::vector<unsigned int>& meshOffsets, glTF::Ref<glTF::Node>& ptr)
  358. {
  359. Node& node = *ptr;
  360. aiNode* ainode = new aiNode(node.id);
  361. if (!node.children.empty()) {
  362. ainode->mNumChildren = node.children.size();
  363. ainode->mChildren = new aiNode*[ainode->mNumChildren];
  364. for (unsigned int i = 0; i < ainode->mNumChildren; ++i) {
  365. aiNode* child = ImportNode(pScene, r, meshOffsets, node.children[i]);
  366. child->mParent = ainode;
  367. ainode->mChildren[i] = child;
  368. }
  369. }
  370. aiMatrix4x4 matrix = ainode->mTransformation;
  371. if (node.matrix.isPresent) {
  372. CopyValue(node.matrix.value, matrix);
  373. }
  374. else {
  375. if (node.translation.isPresent) {
  376. aiVector3D trans;
  377. CopyValue(node.translation.value, trans);
  378. aiMatrix4x4 t;
  379. aiMatrix4x4::Translation(trans, t);
  380. matrix = t * matrix;
  381. }
  382. if (node.scale.isPresent) {
  383. aiVector3D scal(1.f);
  384. CopyValue(node.scale.value, scal);
  385. aiMatrix4x4 s;
  386. aiMatrix4x4::Scaling(scal, s);
  387. matrix = s * matrix;
  388. }
  389. if (node.rotation.isPresent) {
  390. aiQuaternion rot;
  391. CopyValue(node.rotation.value, rot);
  392. matrix = aiMatrix4x4(rot.GetMatrix()) * matrix;
  393. }
  394. }
  395. if (!node.meshes.empty()) {
  396. int count = 0;
  397. for (size_t i = 0; i < node.meshes.size(); ++i) {
  398. int idx = node.meshes[i].GetIndex();
  399. count += meshOffsets[idx + 1] - meshOffsets[idx];
  400. }
  401. ainode->mNumMeshes = count;
  402. ainode->mMeshes = new unsigned int[count];
  403. int k = 0;
  404. for (size_t i = 0; i < node.meshes.size(); ++i) {
  405. int idx = node.meshes[i].GetIndex();
  406. for (size_t j = meshOffsets[idx]; j < meshOffsets[idx + 1]; ++j, ++k) {
  407. ainode->mMeshes[k] = j;
  408. }
  409. }
  410. }
  411. if (node.camera) {
  412. pScene->mCameras[node.camera.GetIndex()]->mName = ainode->mName;
  413. }
  414. if (node.light) {
  415. pScene->mLights[node.light.GetIndex()]->mName = ainode->mName;
  416. }
  417. return ainode;
  418. }
  419. void glTFImporter::ImportNodes(glTF::Asset& r)
  420. {
  421. if (!r.scene) return;
  422. std::vector< Ref<Node> > rootNodes = r.scene->nodes;
  423. // The root nodes
  424. unsigned int numRootNodes = rootNodes.size();
  425. if (numRootNodes == 1) { // a single root node: use it
  426. mScene->mRootNode = ImportNode(mScene, r, meshOffsets, rootNodes[0]);
  427. }
  428. else if (numRootNodes > 1) { // more than one root node: create a fake root
  429. aiNode* root = new aiNode("ROOT");
  430. root->mChildren = new aiNode*[numRootNodes];
  431. for (unsigned int i = 0; i < numRootNodes; ++i) {
  432. aiNode* node = ImportNode(mScene, r, meshOffsets, rootNodes[i]);
  433. node->mParent = root;
  434. root->mChildren[root->mNumChildren++] = node;
  435. }
  436. mScene->mRootNode = root;
  437. }
  438. //if (!mScene->mRootNode) {
  439. // mScene->mRootNode = new aiNode("EMPTY");
  440. //}
  441. }
  442. void glTFImporter::ImportEmbeddedTextures(glTF::Asset& r)
  443. {
  444. embeddedTexIdxs.resize(r.images.Size(), -1);
  445. int numEmbeddedTexs = 0;
  446. for (size_t i = 0; i < r.images.Size(); ++i) {
  447. if (r.images[i].HasData())
  448. numEmbeddedTexs += 1;
  449. }
  450. if (numEmbeddedTexs == 0)
  451. return;
  452. mScene->mTextures = new aiTexture*[numEmbeddedTexs];
  453. // Add the embedded textures
  454. for (size_t i = 0; i < r.images.Size(); ++i) {
  455. Image img = r.images[i];
  456. if (!img.HasData()) continue;
  457. int idx = mScene->mNumTextures++;
  458. embeddedTexIdxs[i] = idx;
  459. aiTexture* tex = mScene->mTextures[idx] = new aiTexture();
  460. size_t length = img.GetDataLength();
  461. void* data = img.StealData();
  462. tex->mWidth = static_cast<unsigned int>(length);
  463. tex->mHeight = 0;
  464. tex->pcData = reinterpret_cast<aiTexel*>(data);
  465. if (!img.mimeType.empty()) {
  466. const char* ext = strchr(img.mimeType.c_str(), '/') + 1;
  467. if (ext) {
  468. if (strcmp(ext, "jpeg") == 0) ext = "jpg";
  469. size_t len = strlen(ext);
  470. if (len <= 3) {
  471. strcpy(tex->achFormatHint, ext);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. void glTFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) {
  478. this->mScene = pScene;
  479. // read the asset file
  480. glTF::Asset asset(pIOHandler);
  481. asset.Load(pFile, GetExtension(pFile) == "glb");
  482. //
  483. // Copy the data out
  484. //
  485. ImportEmbeddedTextures(asset);
  486. ImportMaterials(asset);
  487. ImportMeshes(asset);
  488. ImportCameras(asset);
  489. ImportLights(asset);
  490. ImportNodes(asset);
  491. // TODO: it does not split the loaded vertices, should it?
  492. pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
  493. if (pScene->mNumMeshes == 0) {
  494. pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
  495. }
  496. }
  497. #endif // ASSIMP_BUILD_NO_GLTF_IMPORTER