glTF2Exporter.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2017, 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_EXPORT
  34. #ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
  35. #include "glTF2Exporter.h"
  36. #include "Exceptional.h"
  37. #include "StringComparison.h"
  38. #include "ByteSwapper.h"
  39. #include "SplitLargeMeshes.h"
  40. #include <assimp/SceneCombiner.h>
  41. #include <assimp/version.h>
  42. #include <assimp/IOSystem.hpp>
  43. #include <assimp/Exporter.hpp>
  44. #include <assimp/material.h>
  45. #include <assimp/scene.h>
  46. // Header files, standart library.
  47. #include <memory>
  48. #include <inttypes.h>
  49. #include "glTF2AssetWriter.h"
  50. #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
  51. // Header files, Open3DGC.
  52. # include <Open3DGC/o3dgcSC3DMCEncoder.h>
  53. #endif
  54. using namespace rapidjson;
  55. using namespace Assimp;
  56. using namespace glTF2;
  57. namespace Assimp {
  58. // ------------------------------------------------------------------------------------------------
  59. // Worker function for exporting a scene to GLTF. Prototyped and registered in Exporter.cpp
  60. void ExportSceneGLTF2(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
  61. {
  62. // invoke the exporter
  63. glTF2Exporter exporter(pFile, pIOSystem, pScene, pProperties, false);
  64. }
  65. } // end of namespace Assimp
  66. glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene,
  67. const ExportProperties* pProperties, bool isBinary)
  68. : mFilename(filename)
  69. , mIOSystem(pIOSystem)
  70. , mProperties(pProperties)
  71. {
  72. aiScene* sceneCopy_tmp;
  73. SceneCombiner::CopyScene(&sceneCopy_tmp, pScene);
  74. std::unique_ptr<aiScene> sceneCopy(sceneCopy_tmp);
  75. SplitLargeMeshesProcess_Triangle tri_splitter;
  76. tri_splitter.SetLimit(0xffff);
  77. tri_splitter.Execute(sceneCopy.get());
  78. SplitLargeMeshesProcess_Vertex vert_splitter;
  79. vert_splitter.SetLimit(0xffff);
  80. vert_splitter.Execute(sceneCopy.get());
  81. mScene = sceneCopy.get();
  82. mAsset.reset( new Asset( pIOSystem ) );
  83. if (isBinary) {
  84. mAsset->SetAsBinary();
  85. }
  86. ExportMetadata();
  87. //for (unsigned int i = 0; i < pScene->mNumCameras; ++i) {}
  88. //for (unsigned int i = 0; i < pScene->mNumLights; ++i) {}
  89. ExportMaterials();
  90. if (mScene->mRootNode) {
  91. ExportNodeHierarchy(mScene->mRootNode);
  92. }
  93. ExportMeshes();
  94. //for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {}
  95. ExportScene();
  96. //ExportAnimations();
  97. AssetWriter writer(*mAsset);
  98. if (isBinary) {
  99. writer.WriteGLBFile(filename);
  100. } else {
  101. writer.WriteFile(filename);
  102. }
  103. }
  104. /*
  105. * Copy a 4x4 matrix from struct aiMatrix to typedef mat4.
  106. * Also converts from row-major to column-major storage.
  107. */
  108. static void CopyValue(const aiMatrix4x4& v, mat4& o)
  109. {
  110. o[ 0] = v.a1; o[ 1] = v.b1; o[ 2] = v.c1; o[ 3] = v.d1;
  111. o[ 4] = v.a2; o[ 5] = v.b2; o[ 6] = v.c2; o[ 7] = v.d2;
  112. o[ 8] = v.a3; o[ 9] = v.b3; o[10] = v.c3; o[11] = v.d3;
  113. o[12] = v.a4; o[13] = v.b4; o[14] = v.c4; o[15] = v.d4;
  114. }
  115. static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o)
  116. {
  117. o.a1 = v.a1; o.a2 = v.a2; o.a3 = v.a3; o.a4 = v.a4;
  118. o.b1 = v.b1; o.b2 = v.b2; o.b3 = v.b3; o.b4 = v.b4;
  119. o.c1 = v.c1; o.c2 = v.c2; o.c3 = v.c3; o.c4 = v.c4;
  120. o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4;
  121. }
  122. static void IdentityMatrix4(mat4& o)
  123. {
  124. o[ 0] = 1; o[ 1] = 0; o[ 2] = 0; o[ 3] = 0;
  125. o[ 4] = 0; o[ 5] = 1; o[ 6] = 0; o[ 7] = 0;
  126. o[ 8] = 0; o[ 9] = 0; o[10] = 1; o[11] = 0;
  127. o[12] = 0; o[13] = 0; o[14] = 0; o[15] = 1;
  128. }
  129. inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& buffer,
  130. unsigned int count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, bool isIndices = false)
  131. {
  132. if (!count || !data) return Ref<Accessor>();
  133. unsigned int numCompsIn = AttribType::GetNumComponents(typeIn);
  134. unsigned int numCompsOut = AttribType::GetNumComponents(typeOut);
  135. unsigned int bytesPerComp = ComponentTypeSize(compType);
  136. size_t offset = buffer->byteLength;
  137. // make sure offset is correctly byte-aligned, as required by spec
  138. size_t padding = offset % bytesPerComp;
  139. offset += padding;
  140. size_t length = count * numCompsOut * bytesPerComp;
  141. buffer->Grow(length + padding);
  142. // bufferView
  143. Ref<BufferView> bv = a.bufferViews.Create(a.FindUniqueID(meshName, "view"));
  144. bv->buffer = buffer;
  145. bv->byteOffset = unsigned(offset);
  146. bv->byteLength = length; //! The target that the WebGL buffer should be bound to.
  147. bv->target = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER;
  148. // accessor
  149. Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor"));
  150. acc->bufferView = bv;
  151. acc->byteOffset = 0;
  152. acc->byteStride = 0;
  153. acc->componentType = compType;
  154. acc->count = count;
  155. acc->type = typeOut;
  156. // calculate min and max values
  157. {
  158. // Allocate and initialize with large values.
  159. float float_MAX = 10000000000000.0f;
  160. for (unsigned int i = 0 ; i < numCompsOut ; i++) {
  161. acc->min.push_back( float_MAX);
  162. acc->max.push_back(-float_MAX);
  163. }
  164. // Search and set extreme values.
  165. float valueTmp;
  166. for (unsigned int i = 0 ; i < count ; i++) {
  167. for (unsigned int j = 0 ; j < numCompsOut ; j++) {
  168. if (numCompsOut == 1) {
  169. valueTmp = static_cast<unsigned short*>(data)[i];
  170. } else {
  171. valueTmp = static_cast<aiVector3D*>(data)[i][j];
  172. }
  173. if (valueTmp < acc->min[j]) {
  174. acc->min[j] = valueTmp;
  175. }
  176. if (valueTmp > acc->max[j]) {
  177. acc->max[j] = valueTmp;
  178. }
  179. }
  180. }
  181. }
  182. // copy the data
  183. acc->WriteData(count, data, numCompsIn*bytesPerComp);
  184. return acc;
  185. }
  186. void glTF2Exporter::GetTexSampler(const aiMaterial* mat, Ref<Texture> texture)
  187. {
  188. std::string samplerId = mAsset->FindUniqueID("", "sampler");
  189. texture->sampler = mAsset->samplers.Create(samplerId);
  190. aiTextureMapMode mapU, mapV;
  191. aiGetMaterialInteger(mat,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0),(int*)&mapU);
  192. aiGetMaterialInteger(mat,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0),(int*)&mapV);
  193. switch (mapU) {
  194. case aiTextureMapMode_Wrap:
  195. texture->sampler->wrapS = SamplerWrap_Repeat;
  196. break;
  197. case aiTextureMapMode_Clamp:
  198. texture->sampler->wrapS = SamplerWrap_Clamp_To_Edge;
  199. break;
  200. case aiTextureMapMode_Mirror:
  201. texture->sampler->wrapS = SamplerWrap_Mirrored_Repeat;
  202. break;
  203. case aiTextureMapMode_Decal:
  204. default:
  205. texture->sampler->wrapS = SamplerWrap_Repeat;
  206. break;
  207. };
  208. switch (mapV) {
  209. case aiTextureMapMode_Wrap:
  210. texture->sampler->wrapT = SamplerWrap_Repeat;
  211. break;
  212. case aiTextureMapMode_Clamp:
  213. texture->sampler->wrapT = SamplerWrap_Clamp_To_Edge;
  214. break;
  215. case aiTextureMapMode_Mirror:
  216. texture->sampler->wrapT = SamplerWrap_Mirrored_Repeat;
  217. break;
  218. case aiTextureMapMode_Decal:
  219. default:
  220. texture->sampler->wrapT = SamplerWrap_Repeat;
  221. break;
  222. };
  223. // Hard coded Texture filtering options because I do not know where to find them in the aiMaterial.
  224. texture->sampler->magFilter = SamplerMagFilter_Linear;
  225. texture->sampler->minFilter = SamplerMinFilter_Linear_Mipmap_Linear;
  226. }
  227. void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTextureType tt, unsigned int slot = 0)
  228. {
  229. aiString tex;
  230. if (mat->GetTextureCount(tt) > 0) {
  231. if (mat->Get(AI_MATKEY_TEXTURE(tt, slot), tex) == AI_SUCCESS) {
  232. std::string path = tex.C_Str();
  233. if (path.size() > 0) {
  234. if (path[0] != '*') {
  235. std::map<std::string, unsigned int>::iterator it = mTexturesByPath.find(path);
  236. if (it != mTexturesByPath.end()) {
  237. texture = mAsset->textures.Get(it->second);
  238. }
  239. }
  240. if (!texture) {
  241. std::string texId = mAsset->FindUniqueID("", "texture");
  242. texture = mAsset->textures.Create(texId);
  243. mTexturesByPath[path] = texture.GetIndex();
  244. std::string imgId = mAsset->FindUniqueID("", "image");
  245. texture->source = mAsset->images.Create(imgId);
  246. if (path[0] == '*') { // embedded
  247. aiTexture* tex = mScene->mTextures[atoi(&path[1])];
  248. uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
  249. texture->source->SetData(data, tex->mWidth, *mAsset);
  250. if (tex->achFormatHint[0]) {
  251. std::string mimeType = "image/";
  252. mimeType += (memcmp(tex->achFormatHint, "jpg", 3) == 0) ? "jpeg" : tex->achFormatHint;
  253. texture->source->mimeType = mimeType;
  254. }
  255. }
  256. else {
  257. texture->source->uri = path;
  258. }
  259. GetTexSampler(mat, texture);
  260. }
  261. }
  262. }
  263. }
  264. }
  265. void glTF2Exporter::GetMatColor(const aiMaterial* mat, vec4& prop, const char* propName, int type, int idx)
  266. {
  267. aiColor4D col;
  268. if (mat->Get(propName, type, idx, col) == AI_SUCCESS) {
  269. prop[0] = col.r; prop[1] = col.g; prop[2] = col.b; prop[3] = col.a;
  270. }
  271. }
  272. void glTF2Exporter::GetMatColor(const aiMaterial* mat, vec3& prop, const char* propName, int type, int idx)
  273. {
  274. aiColor3D col;
  275. if (mat->Get(propName, type, idx, col) == AI_SUCCESS) {
  276. prop[0] = col.r; prop[1] = col.g; prop[2] = col.b;
  277. }
  278. }
  279. void glTF2Exporter::ExportMaterials()
  280. {
  281. aiString aiName;
  282. for (unsigned int i = 0; i < mScene->mNumMaterials; ++i) {
  283. const aiMaterial* mat = mScene->mMaterials[i];
  284. std::string name;
  285. if (mat->Get(AI_MATKEY_NAME, aiName) == AI_SUCCESS) {
  286. name = aiName.C_Str();
  287. }
  288. name = mAsset->FindUniqueID(name, "material");
  289. Ref<Material> m = mAsset->materials.Create(name);
  290. GetMatTex(mat, m->baseColorTexture.texture, aiTextureType_DIFFUSE);
  291. GetMatTex(mat, m->metallicRoughnessTexture.texture, aiTextureType_UNKNOWN, 0);//get unknown slot
  292. GetMatTex(mat, m->emissiveTexture.texture, aiTextureType_EMISSIVE);
  293. GetMatTex(mat, m->normalTexture.texture, aiTextureType_NORMALS);
  294. GetMatTex(mat, m->occlusionTexture.texture, aiTextureType_LIGHTMAP);
  295. GetMatColor(mat, m->baseColorFactor, AI_MATKEY_COLOR_DIFFUSE);
  296. GetMatColor(mat, m->emissiveFactor, AI_MATKEY_COLOR_EMISSIVE);
  297. mat->Get(AI_MATKEY_TWOSIDED, m->doubleSided);
  298. mat->Get("$mat.gltf.alphaCutoff", 0, 0, m->alphaCutoff);
  299. mat->Get("$mat.gltf.metallicFactor", 0, 0, m->metallicFactor);
  300. mat->Get("$mat.gltf.roughnessFactor", 0, 0, m->roughnessFactor);
  301. mat->Get("$mat.gltf.alphaMode", 0, 0, m->alphaMode);
  302. }
  303. }
  304. /*
  305. * Search through node hierarchy and find the node containing the given meshID.
  306. * Returns true on success, and false otherwise.
  307. */
  308. bool FindMeshNode(Ref<Node>& nodeIn, Ref<Node>& meshNode, std::string meshID)
  309. {
  310. for (unsigned int i = 0; i < nodeIn->meshes.size(); ++i) {
  311. if (meshID.compare(nodeIn->meshes[i]->id) == 0) {
  312. meshNode = nodeIn;
  313. return true;
  314. }
  315. }
  316. for (unsigned int i = 0; i < nodeIn->children.size(); ++i) {
  317. if(FindMeshNode(nodeIn->children[i], meshNode, meshID)) {
  318. return true;
  319. }
  320. }
  321. return false;
  322. }
  323. /*
  324. * Find the root joint of the skeleton.
  325. * Starts will any joint node and traces up the tree,
  326. * until a parent is found that does not have a jointName.
  327. * Returns the first parent Ref<Node> found that does not have a jointName.
  328. */
  329. Ref<Node> FindSkeletonRootJoint(Ref<Skin>& skinRef)
  330. {
  331. Ref<Node> startNodeRef;
  332. Ref<Node> parentNodeRef;
  333. // Arbitrarily use the first joint to start the search.
  334. startNodeRef = skinRef->jointNames[0];
  335. parentNodeRef = skinRef->jointNames[0];
  336. do {
  337. startNodeRef = parentNodeRef;
  338. parentNodeRef = startNodeRef->parent;
  339. } while (!parentNodeRef->jointName.empty());
  340. return parentNodeRef;
  341. }
  342. /*void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buffer>& bufferRef, Ref<Skin>& skinRef, std::vector<aiMatrix4x4>& inverseBindMatricesData)
  343. {
  344. if (aimesh->mNumBones < 1) {
  345. return;
  346. }
  347. // Store the vertex joint and weight data.
  348. const size_t NumVerts( aimesh->mNumVertices );
  349. vec4* vertexJointData = new vec4[ NumVerts ];
  350. vec4* vertexWeightData = new vec4[ NumVerts ];
  351. int* jointsPerVertex = new int[ NumVerts ];
  352. for (size_t i = 0; i < NumVerts; ++i) {
  353. jointsPerVertex[i] = 0;
  354. for (size_t j = 0; j < 4; ++j) {
  355. vertexJointData[i][j] = 0;
  356. vertexWeightData[i][j] = 0;
  357. }
  358. }
  359. for (unsigned int idx_bone = 0; idx_bone < aimesh->mNumBones; ++idx_bone) {
  360. const aiBone* aib = aimesh->mBones[idx_bone];
  361. // aib->mName =====> skinRef->jointNames
  362. // Find the node with id = mName.
  363. Ref<Node> nodeRef = mAsset.nodes.Get(aib->mName.C_Str());
  364. nodeRef->jointName = nodeRef->name;
  365. unsigned int jointNamesIndex;
  366. bool addJointToJointNames = true;
  367. for ( unsigned int idx_joint = 0; idx_joint < skinRef->jointNames.size(); ++idx_joint) {
  368. if (skinRef->jointNames[idx_joint]->jointName.compare(nodeRef->jointName) == 0) {
  369. addJointToJointNames = false;
  370. jointNamesIndex = idx_joint;
  371. }
  372. }
  373. if (addJointToJointNames) {
  374. skinRef->jointNames.push_back(nodeRef);
  375. // aib->mOffsetMatrix =====> skinRef->inverseBindMatrices
  376. aiMatrix4x4 tmpMatrix4;
  377. CopyValue(aib->mOffsetMatrix, tmpMatrix4);
  378. inverseBindMatricesData.push_back(tmpMatrix4);
  379. jointNamesIndex = static_cast<unsigned int>(inverseBindMatricesData.size() - 1);
  380. }
  381. // aib->mWeights =====> vertexWeightData
  382. for (unsigned int idx_weights = 0; idx_weights < aib->mNumWeights; ++idx_weights) {
  383. unsigned int vertexId = aib->mWeights[idx_weights].mVertexId;
  384. float vertWeight = aib->mWeights[idx_weights].mWeight;
  385. // A vertex can only have at most four joint weights. Ignore all others.
  386. if (jointsPerVertex[vertexId] > 3) {
  387. continue;
  388. }
  389. vertexJointData[vertexId][jointsPerVertex[vertexId]] = jointNamesIndex;
  390. vertexWeightData[vertexId][jointsPerVertex[vertexId]] = vertWeight;
  391. jointsPerVertex[vertexId] += 1;
  392. }
  393. } // End: for-loop mNumMeshes
  394. Mesh::Primitive& p = meshRef->primitives.back();
  395. Ref<Accessor> vertexJointAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, vertexJointData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);
  396. if ( vertexJointAccessor ) {
  397. p.attributes.joint.push_back( vertexJointAccessor );
  398. }
  399. Ref<Accessor> vertexWeightAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, vertexWeightData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);
  400. if ( vertexWeightAccessor ) {
  401. p.attributes.weight.push_back( vertexWeightAccessor );
  402. }
  403. delete[] jointsPerVertex;
  404. delete[] vertexWeightData;
  405. delete[] vertexJointData;
  406. }*/
  407. void glTF2Exporter::ExportMeshes()
  408. {
  409. // Not for
  410. // using IndicesType = decltype(aiFace::mNumIndices);
  411. // But yes for
  412. // using IndicesType = unsigned short;
  413. // because "ComponentType_UNSIGNED_SHORT" used for indices. And it's a maximal type according to glTF specification.
  414. typedef unsigned short IndicesType;
  415. // Variables needed for compression. BEGIN.
  416. // Indices, not pointers - because pointer to buffer is changing while writing to it.
  417. size_t idx_srcdata_begin;// Index of buffer before writing mesh data. Also, index of begin of coordinates array in buffer.
  418. size_t idx_srcdata_normal = SIZE_MAX;// Index of begin of normals array in buffer. SIZE_MAX - mean that mesh has no normals.
  419. std::vector<size_t> idx_srcdata_tc;// Array of indices. Every index point to begin of texture coordinates array in buffer.
  420. size_t idx_srcdata_ind;// Index of begin of coordinates indices array in buffer.
  421. bool comp_allow;// Point that data of current mesh can be compressed.
  422. // Variables needed for compression. END.
  423. std::string fname = std::string(mFilename);
  424. std::string bufferIdPrefix = fname.substr(0, fname.rfind(".gltf"));
  425. std::string bufferId = mAsset->FindUniqueID("", bufferIdPrefix.c_str());
  426. Ref<Buffer> b = mAsset->GetBodyBuffer();
  427. if (!b) {
  428. b = mAsset->buffers.Create(bufferId);
  429. }
  430. //----------------------------------------
  431. // Initialize variables for the skin
  432. bool createSkin = false;
  433. for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
  434. const aiMesh* aim = mScene->mMeshes[idx_mesh];
  435. if(aim->HasBones()) {
  436. createSkin = true;
  437. break;
  438. }
  439. }
  440. Ref<Skin> skinRef;
  441. std::string skinName = mAsset->FindUniqueID("skin", "skin");
  442. std::vector<aiMatrix4x4> inverseBindMatricesData;
  443. if(createSkin) {
  444. skinRef = mAsset->skins.Create(skinName);
  445. skinRef->name = skinName;
  446. }
  447. //----------------------------------------
  448. for (unsigned int idx_mesh = 0; idx_mesh < mScene->mNumMeshes; ++idx_mesh) {
  449. const aiMesh* aim = mScene->mMeshes[idx_mesh];
  450. // Check if compressing requested and mesh can be encoded.
  451. #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
  452. comp_allow = mProperties->GetPropertyBool("extensions.Open3DGC.use", false);
  453. #else
  454. comp_allow = false;
  455. #endif
  456. if(comp_allow && (aim->mPrimitiveTypes == aiPrimitiveType_TRIANGLE) && (aim->mNumVertices > 0) && (aim->mNumFaces > 0))
  457. {
  458. idx_srcdata_tc.clear();
  459. idx_srcdata_tc.reserve(AI_MAX_NUMBER_OF_TEXTURECOORDS);
  460. }
  461. else
  462. {
  463. std::string msg;
  464. if(aim->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
  465. msg = "all primitives of the mesh must be a triangles.";
  466. else
  467. msg = "mesh must has vertices and faces.";
  468. DefaultLogger::get()->warn("GLTF: can not use Open3DGC-compression: " + msg);
  469. comp_allow = false;
  470. }
  471. std::string name = aim->mName.C_Str();
  472. std::string meshId = mAsset->FindUniqueID(name, "mesh");
  473. Ref<Mesh> m = mAsset->meshes.Create(meshId);
  474. m->primitives.resize(1);
  475. Mesh::Primitive& p = m->primitives.back();
  476. m->name = name;
  477. p.material = mAsset->materials.Get(aim->mMaterialIndex);
  478. /******************* Vertices ********************/
  479. // If compression is used then you need parameters of uncompressed region: begin and size. At this step "begin" is stored.
  480. if(comp_allow) idx_srcdata_begin = b->byteLength;
  481. Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
  482. if (v) p.attributes.position.push_back(v);
  483. /******************** Normals ********************/
  484. if(comp_allow && (aim->mNormals != 0)) idx_srcdata_normal = b->byteLength;// Store index of normals array.
  485. Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
  486. if (n) p.attributes.normal.push_back(n);
  487. /************** Texture coordinates **************/
  488. for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
  489. // Flip UV y coords
  490. if (aim -> mNumUVComponents[i] > 1) {
  491. for (unsigned int j = 0; j < aim->mNumVertices; ++j) {
  492. aim->mTextureCoords[i][j].y = 1 - aim->mTextureCoords[i][j].y;
  493. }
  494. }
  495. if (aim->mNumUVComponents[i] > 0) {
  496. AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3;
  497. if(comp_allow) idx_srcdata_tc.push_back(b->byteLength);// Store index of texture coordinates array.
  498. Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, false);
  499. if (tc) p.attributes.texcoord.push_back(tc);
  500. }
  501. }
  502. /*************** Vertices indices ****************/
  503. idx_srcdata_ind = b->byteLength;// Store index of indices array.
  504. if (aim->mNumFaces > 0) {
  505. std::vector<IndicesType> indices;
  506. unsigned int nIndicesPerFace = aim->mFaces[0].mNumIndices;
  507. indices.resize(aim->mNumFaces * nIndicesPerFace);
  508. for (size_t i = 0; i < aim->mNumFaces; ++i) {
  509. for (size_t j = 0; j < nIndicesPerFace; ++j) {
  510. indices[i*nIndicesPerFace + j] = uint16_t(aim->mFaces[i].mIndices[j]);
  511. }
  512. }
  513. p.indices = ExportData(*mAsset, meshId, b, unsigned(indices.size()), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_SHORT, true);
  514. }
  515. switch (aim->mPrimitiveTypes) {
  516. case aiPrimitiveType_POLYGON:
  517. p.mode = PrimitiveMode_TRIANGLES; break; // TODO implement this
  518. case aiPrimitiveType_LINE:
  519. p.mode = PrimitiveMode_LINES; break;
  520. case aiPrimitiveType_POINT:
  521. p.mode = PrimitiveMode_POINTS; break;
  522. default: // aiPrimitiveType_TRIANGLE
  523. p.mode = PrimitiveMode_TRIANGLES;
  524. }
  525. /*************** Skins ****************/
  526. /*if(aim->HasBones()) {
  527. ExportSkin(*mAsset, aim, m, b, skinRef, inverseBindMatricesData);
  528. }*/
  529. /****************** Compression ******************/
  530. ///TODO: animation: weights, joints.
  531. if(comp_allow)
  532. {
  533. #ifdef ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC
  534. // Only one type of compression supported at now - Open3DGC.
  535. //
  536. o3dgc::BinaryStream bs;
  537. o3dgc::SC3DMCEncoder<IndicesType> encoder;
  538. o3dgc::IndexedFaceSet<IndicesType> comp_o3dgc_ifs;
  539. o3dgc::SC3DMCEncodeParams comp_o3dgc_params;
  540. //
  541. // Fill data for encoder.
  542. //
  543. // Quantization
  544. unsigned quant_coord = mProperties->GetPropertyInteger("extensions.Open3DGC.quantization.POSITION", 12);
  545. unsigned quant_normal = mProperties->GetPropertyInteger("extensions.Open3DGC.quantization.NORMAL", 10);
  546. unsigned quant_texcoord = mProperties->GetPropertyInteger("extensions.Open3DGC.quantization.TEXCOORD", 10);
  547. // Prediction
  548. o3dgc::O3DGCSC3DMCPredictionMode prediction_position = o3dgc::O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION;
  549. o3dgc::O3DGCSC3DMCPredictionMode prediction_normal = o3dgc::O3DGC_SC3DMC_SURF_NORMALS_PREDICTION;
  550. o3dgc::O3DGCSC3DMCPredictionMode prediction_texcoord = o3dgc::O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION;
  551. // IndexedFacesSet: "Crease angle", "solid", "convex" are set to default.
  552. comp_o3dgc_ifs.SetCCW(true);
  553. comp_o3dgc_ifs.SetIsTriangularMesh(true);
  554. comp_o3dgc_ifs.SetNumFloatAttributes(0);
  555. // Coordinates
  556. comp_o3dgc_params.SetCoordQuantBits(quant_coord);
  557. comp_o3dgc_params.SetCoordPredMode(prediction_position);
  558. comp_o3dgc_ifs.SetNCoord(aim->mNumVertices);
  559. comp_o3dgc_ifs.SetCoord((o3dgc::Real* const)&b->GetPointer()[idx_srcdata_begin]);
  560. // Normals
  561. if(idx_srcdata_normal != SIZE_MAX)
  562. {
  563. comp_o3dgc_params.SetNormalQuantBits(quant_normal);
  564. comp_o3dgc_params.SetNormalPredMode(prediction_normal);
  565. comp_o3dgc_ifs.SetNNormal(aim->mNumVertices);
  566. comp_o3dgc_ifs.SetNormal((o3dgc::Real* const)&b->GetPointer()[idx_srcdata_normal]);
  567. }
  568. // Texture coordinates
  569. for(size_t num_tc = 0; num_tc < idx_srcdata_tc.size(); num_tc++)
  570. {
  571. size_t num = comp_o3dgc_ifs.GetNumFloatAttributes();
  572. comp_o3dgc_params.SetFloatAttributeQuantBits(static_cast<unsigned long>(num), quant_texcoord);
  573. comp_o3dgc_params.SetFloatAttributePredMode(static_cast<unsigned long>(num), prediction_texcoord);
  574. comp_o3dgc_ifs.SetNFloatAttribute(static_cast<unsigned long>(num), aim->mNumVertices);// number of elements.
  575. comp_o3dgc_ifs.SetFloatAttributeDim(static_cast<unsigned long>(num), aim->mNumUVComponents[num_tc]);// components per element: aiVector3D => x * float
  576. comp_o3dgc_ifs.SetFloatAttributeType(static_cast<unsigned long>(num), o3dgc::O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_TEXCOORD);
  577. comp_o3dgc_ifs.SetFloatAttribute(static_cast<unsigned long>(num), (o3dgc::Real* const)&b->GetPointer()[idx_srcdata_tc[num_tc]]);
  578. comp_o3dgc_ifs.SetNumFloatAttributes(static_cast<unsigned long>(num + 1));
  579. }
  580. // Coordinates indices
  581. comp_o3dgc_ifs.SetNCoordIndex(aim->mNumFaces);
  582. comp_o3dgc_ifs.SetCoordIndex((IndicesType* const)&b->GetPointer()[idx_srcdata_ind]);
  583. // Prepare to enconding
  584. comp_o3dgc_params.SetNumFloatAttributes(comp_o3dgc_ifs.GetNumFloatAttributes());
  585. if(mProperties->GetPropertyBool("extensions.Open3DGC.binary", true))
  586. comp_o3dgc_params.SetStreamType(o3dgc::O3DGC_STREAM_TYPE_BINARY);
  587. else
  588. comp_o3dgc_params.SetStreamType(o3dgc::O3DGC_STREAM_TYPE_ASCII);
  589. comp_o3dgc_ifs.ComputeMinMax(o3dgc::O3DGC_SC3DMC_MAX_ALL_DIMS);
  590. //
  591. // Encoding
  592. //
  593. encoder.Encode(comp_o3dgc_params, comp_o3dgc_ifs, bs);
  594. // Replace data in buffer.
  595. b->ReplaceData(idx_srcdata_begin, b->byteLength - idx_srcdata_begin, bs.GetBuffer(), bs.GetSize());
  596. //
  597. // Add information about extension to mesh.
  598. //
  599. // Create extension structure.
  600. Mesh::SCompression_Open3DGC* ext = new Mesh::SCompression_Open3DGC;
  601. // Fill it.
  602. ext->Buffer = b->id;
  603. ext->Offset = idx_srcdata_begin;
  604. ext->Count = b->byteLength - idx_srcdata_begin;
  605. ext->Binary = mProperties->GetPropertyBool("extensions.Open3DGC.binary");
  606. ext->IndicesCount = comp_o3dgc_ifs.GetNCoordIndex() * 3;
  607. ext->VerticesCount = comp_o3dgc_ifs.GetNCoord();
  608. // And assign to mesh.
  609. m->Extension.push_back(ext);
  610. #endif
  611. }// if(comp_allow)
  612. }// for (unsigned int i = 0; i < mScene->mNumMeshes; ++i)
  613. //----------------------------------------
  614. // Finish the skin
  615. // Create the Accessor for skinRef->inverseBindMatrices
  616. if (createSkin) {
  617. mat4* invBindMatrixData = new mat4[inverseBindMatricesData.size()];
  618. for ( unsigned int idx_joint = 0; idx_joint < inverseBindMatricesData.size(); ++idx_joint) {
  619. CopyValue(inverseBindMatricesData[idx_joint], invBindMatrixData[idx_joint]);
  620. }
  621. Ref<Accessor> invBindMatrixAccessor = ExportData(*mAsset, skinName, b, static_cast<unsigned int>(inverseBindMatricesData.size()), invBindMatrixData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT);
  622. if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor;
  623. // Identity Matrix =====> skinRef->bindShapeMatrix
  624. // Temporary. Hard-coded identity matrix here
  625. skinRef->bindShapeMatrix.isPresent = true;
  626. IdentityMatrix4(skinRef->bindShapeMatrix.value);
  627. // Find nodes that contain a mesh with bones and add "skeletons" and "skin" attributes to those nodes.
  628. Ref<Node> rootNode = mAsset->nodes.Get(unsigned(0));
  629. Ref<Node> meshNode;
  630. for (unsigned int meshIndex = 0; meshIndex < mAsset->meshes.Size(); ++meshIndex) {
  631. Ref<Mesh> mesh = mAsset->meshes.Get(meshIndex);
  632. bool hasBones = false;
  633. for (unsigned int i = 0; i < mesh->primitives.size(); ++i) {
  634. if (!mesh->primitives[i].attributes.weight.empty()) {
  635. hasBones = true;
  636. break;
  637. }
  638. }
  639. if (!hasBones) {
  640. continue;
  641. }
  642. std::string meshID = mesh->id;
  643. FindMeshNode(rootNode, meshNode, meshID);
  644. Ref<Node> rootJoint = FindSkeletonRootJoint(skinRef);
  645. meshNode->skeletons.push_back(rootJoint);
  646. meshNode->skin = skinRef;
  647. }
  648. }
  649. }
  650. /*
  651. * Export the root node of the node hierarchy.
  652. * Calls ExportNode for all children.
  653. */
  654. unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode* n)
  655. {
  656. Ref<Node> node = mAsset->nodes.Create(mAsset->FindUniqueID(n->mName.C_Str(), "node"));
  657. if (!n->mTransformation.IsIdentity()) {
  658. node->matrix.isPresent = true;
  659. CopyValue(n->mTransformation, node->matrix.value);
  660. }
  661. for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
  662. node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
  663. }
  664. for (unsigned int i = 0; i < n->mNumChildren; ++i) {
  665. unsigned int idx = ExportNode(n->mChildren[i], node);
  666. node->children.push_back(mAsset->nodes.Get(idx));
  667. }
  668. return node.GetIndex();
  669. }
  670. /*
  671. * Export node and recursively calls ExportNode for all children.
  672. * Since these nodes are not the root node, we also export the parent Ref<Node>
  673. */
  674. unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
  675. {
  676. std::string name = mAsset->FindUniqueID(n->mName.C_Str(), "node");
  677. Ref<Node> node = mAsset->nodes.Create(name);
  678. node->parent = parent;
  679. node->name = name;
  680. if (!n->mTransformation.IsIdentity()) {
  681. node->matrix.isPresent = true;
  682. CopyValue(n->mTransformation, node->matrix.value);
  683. }
  684. for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
  685. node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
  686. }
  687. for (unsigned int i = 0; i < n->mNumChildren; ++i) {
  688. unsigned int idx = ExportNode(n->mChildren[i], node);
  689. node->children.push_back(mAsset->nodes.Get(idx));
  690. }
  691. return node.GetIndex();
  692. }
  693. void glTF2Exporter::ExportScene()
  694. {
  695. const char* sceneName = "defaultScene";
  696. Ref<Scene> scene = mAsset->scenes.Create(sceneName);
  697. // root node will be the first one exported (idx 0)
  698. if (mAsset->nodes.Size() > 0) {
  699. scene->nodes.push_back(mAsset->nodes.Get(0u));
  700. }
  701. // set as the default scene
  702. mAsset->scene = scene;
  703. }
  704. void glTF2Exporter::ExportMetadata()
  705. {
  706. AssetMetadata& asset = mAsset->asset;
  707. asset.version = 2;
  708. char buffer[256];
  709. ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)",
  710. aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision());
  711. asset.generator = buffer;
  712. }
  713. inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animation>& animRef, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond)
  714. {
  715. // Loop over the data and check to see if it exactly matches an existing buffer.
  716. // If yes, then reference the existing corresponding accessor.
  717. // Otherwise, add to the buffer and create a new accessor.
  718. size_t counts[3] = {
  719. nodeChannel->mNumPositionKeys,
  720. nodeChannel->mNumScalingKeys,
  721. nodeChannel->mNumRotationKeys,
  722. };
  723. size_t numKeyframes = 1;
  724. for (int i = 0; i < 3; ++i) {
  725. if (counts[i] > numKeyframes) {
  726. numKeyframes = counts[i];
  727. }
  728. }
  729. //-------------------------------------------------------
  730. // Extract TIME parameter data.
  731. // Check if the timeStamps are the same for mPositionKeys, mRotationKeys, and mScalingKeys.
  732. if(nodeChannel->mNumPositionKeys > 0) {
  733. typedef float TimeType;
  734. std::vector<TimeType> timeData;
  735. timeData.resize(numKeyframes);
  736. for (size_t i = 0; i < numKeyframes; ++i) {
  737. size_t frameIndex = i * nodeChannel->mNumPositionKeys / numKeyframes;
  738. // mTime is measured in ticks, but GLTF time is measured in seconds, so convert.
  739. // Check if we have to cast type here. e.g. uint16_t()
  740. timeData[i] = nodeChannel->mPositionKeys[frameIndex].mTime / ticksPerSecond;
  741. }
  742. Ref<Accessor> timeAccessor = ExportData(mAsset, animId, buffer, static_cast<unsigned int>(numKeyframes), &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT);
  743. if (timeAccessor) animRef->Parameters.TIME = timeAccessor;
  744. }
  745. //-------------------------------------------------------
  746. // Extract translation parameter data
  747. if(nodeChannel->mNumPositionKeys > 0) {
  748. C_STRUCT aiVector3D* translationData = new aiVector3D[numKeyframes];
  749. for (size_t i = 0; i < numKeyframes; ++i) {
  750. size_t frameIndex = i * nodeChannel->mNumPositionKeys / numKeyframes;
  751. translationData[i] = nodeChannel->mPositionKeys[frameIndex].mValue;
  752. }
  753. Ref<Accessor> tranAccessor = ExportData(mAsset, animId, buffer, static_cast<unsigned int>(numKeyframes), translationData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
  754. if ( tranAccessor ) {
  755. animRef->Parameters.translation = tranAccessor;
  756. }
  757. delete[] translationData;
  758. }
  759. //-------------------------------------------------------
  760. // Extract scale parameter data
  761. if(nodeChannel->mNumScalingKeys > 0) {
  762. C_STRUCT aiVector3D* scaleData = new aiVector3D[numKeyframes];
  763. for (size_t i = 0; i < numKeyframes; ++i) {
  764. size_t frameIndex = i * nodeChannel->mNumScalingKeys / numKeyframes;
  765. scaleData[i] = nodeChannel->mScalingKeys[frameIndex].mValue;
  766. }
  767. Ref<Accessor> scaleAccessor = ExportData(mAsset, animId, buffer, static_cast<unsigned int>(numKeyframes), scaleData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
  768. if ( scaleAccessor ) {
  769. animRef->Parameters.scale = scaleAccessor;
  770. }
  771. delete[] scaleData;
  772. }
  773. //-------------------------------------------------------
  774. // Extract rotation parameter data
  775. if(nodeChannel->mNumRotationKeys > 0) {
  776. vec4* rotationData = new vec4[numKeyframes];
  777. for (size_t i = 0; i < numKeyframes; ++i) {
  778. size_t frameIndex = i * nodeChannel->mNumRotationKeys / numKeyframes;
  779. rotationData[i][0] = nodeChannel->mRotationKeys[frameIndex].mValue.x;
  780. rotationData[i][1] = nodeChannel->mRotationKeys[frameIndex].mValue.y;
  781. rotationData[i][2] = nodeChannel->mRotationKeys[frameIndex].mValue.z;
  782. rotationData[i][3] = nodeChannel->mRotationKeys[frameIndex].mValue.w;
  783. }
  784. Ref<Accessor> rotAccessor = ExportData(mAsset, animId, buffer, static_cast<unsigned int>(numKeyframes), rotationData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT);
  785. if ( rotAccessor ) {
  786. animRef->Parameters.rotation = rotAccessor;
  787. }
  788. delete[] rotationData;
  789. }
  790. }
  791. /* void glTF2Exporter::ExportAnimations()
  792. {
  793. Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
  794. for (unsigned int i = 0; i < mScene->mNumAnimations; ++i) {
  795. const aiAnimation* anim = mScene->mAnimations[i];
  796. std::string nameAnim = "anim";
  797. if (anim->mName.length > 0) {
  798. nameAnim = anim->mName.C_Str();
  799. }
  800. for (unsigned int channelIndex = 0; channelIndex < anim->mNumChannels; ++channelIndex) {
  801. const aiNodeAnim* nodeChannel = anim->mChannels[channelIndex];
  802. // It appears that assimp stores this type of animation as multiple animations.
  803. // where each aiNodeAnim in mChannels animates a specific node.
  804. std::string name = nameAnim + "_" + to_string(channelIndex);
  805. name = mAsset->FindUniqueID(name, "animation");
  806. Ref<Animation> animRef = mAsset->animations.Create(name);
  807. // Parameters
  808. ExtractAnimationData(*mAsset, name, animRef, bufferRef, nodeChannel, anim->mTicksPerSecond);
  809. for (unsigned int j = 0; j < 3; ++j) {
  810. std::string channelType;
  811. int channelSize;
  812. switch (j) {
  813. case 0:
  814. channelType = "rotation";
  815. channelSize = nodeChannel->mNumRotationKeys;
  816. break;
  817. case 1:
  818. channelType = "scale";
  819. channelSize = nodeChannel->mNumScalingKeys;
  820. break;
  821. case 2:
  822. channelType = "translation";
  823. channelSize = nodeChannel->mNumPositionKeys;
  824. break;
  825. }
  826. if (channelSize < 1) { continue; }
  827. Animation::AnimChannel tmpAnimChannel;
  828. Animation::AnimSampler tmpAnimSampler;
  829. tmpAnimChannel.sampler = static_cast<int>(animRef->Samplers.size());
  830. tmpAnimChannel.target.path = channelType;
  831. tmpAnimSampler.output = channelType;
  832. tmpAnimSampler.id = name + "_" + channelType;
  833. tmpAnimChannel.target.node = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str());
  834. tmpAnimSampler.input = "TIME";
  835. tmpAnimSampler.interpolation = "LINEAR";
  836. animRef->Channels.push_back(tmpAnimChannel);
  837. animRef->Samplers.push_back(tmpAnimSampler);
  838. }
  839. }
  840. // Assimp documentation staes this is not used (not implemented)
  841. // for (unsigned int channelIndex = 0; channelIndex < anim->mNumMeshChannels; ++channelIndex) {
  842. // const aiMeshAnim* meshChannel = anim->mMeshChannels[channelIndex];
  843. // }
  844. } // End: for-loop mNumAnimations
  845. } */
  846. #endif // ASSIMP_BUILD_NO_GLTF_EXPORTER
  847. #endif // ASSIMP_BUILD_NO_EXPORT