From: Daniel Hritzkiv Date: Fri, 1 Sep 2017 21:49:04 +0000 (-0400) Subject: reenable animation and skins exports X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab08a7c3cbc27add5c10ea44786018c9b5c8ff47;p=platform%2Fupstream%2Fassimp.git reenable animation and skins exports Currently incorrect, however. May need to be removed --- diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 1f9f48e..8e3a6dd 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -928,9 +928,11 @@ namespace glTF2 friend class AssetWriter; typedef typename std::gltf_unordered_map< unsigned int, unsigned int > Dict; + typedef typename std::gltf_unordered_map< std::string, unsigned int > IdDict; std::vector mObjs; //! The read objects Dict mObjsByOIndex; //! The read objects accessible by original index + IdDict mObjsById; //! The read objects accessible by id const char* mDictId; //! ID of the dictionary object const char* mExtId; //! ID of the extension defining the dictionary Value* mDict; //! JSON dictionary object @@ -951,6 +953,7 @@ namespace glTF2 Ref Retrieve(unsigned int i); Ref Get(unsigned int i); + Ref Get(const char* id); Ref Create(const char* id); Ref Create(const std::string& id) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index dd110eb..5316b5e 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -194,14 +194,6 @@ inline void LazyDict::DetachFromDocument() } template -Ref LazyDict::Get(unsigned int i) -{ - - return Ref(mObjs, i); - -} - -template Ref LazyDict::Retrieve(unsigned int i) { @@ -235,11 +227,33 @@ Ref LazyDict::Retrieve(unsigned int i) } template +Ref LazyDict::Get(unsigned int i) +{ + + return Ref(mObjs, i); + +} + +template +Ref LazyDict::Get(const char* id) +{ + id = T::TranslateId(mAsset, id); + + typename IdDict::iterator it = mObjsById.find(id); + if (it != mObjsById.end()) { // already created? + return Ref(mObjs, it->second); + } + + throw std::out_of_range("id \"" + std::string(id) + "\" Doesn't exist"); +} + +template Ref LazyDict::Add(T* obj) { unsigned int idx = unsigned(mObjs.size()); mObjs.push_back(obj); mObjsByOIndex[obj->oIndex] = idx; + mObjsById[obj->id] = idx; mAsset.mUsedIds[obj->id] = true; return Ref(mObjs, idx); } @@ -252,8 +266,10 @@ Ref LazyDict::Create(const char* id) throw DeadlyImportError("GLTF: two objects with the same ID exist"); } T* inst = new T(); + unsigned int idx = unsigned(mObjs.size()); inst->id = id; - inst->index = static_cast(mObjs.size()); + inst->index = idx; + inst->oIndex = idx; return Add(inst); } diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index ae610d1..164b559 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -121,7 +121,7 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportScene(); - //ExportAnimations(); + ExportAnimations(); AssetWriter writer(*mAsset); @@ -481,7 +481,7 @@ Ref FindSkeletonRootJoint(Ref& skinRef) return parentNodeRef; } -/*void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, Ref& bufferRef, Ref& skinRef, std::vector& inverseBindMatricesData) +void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, Ref& bufferRef, Ref& skinRef, std::vector& inverseBindMatricesData) { if (aimesh->mNumBones < 1) { return; @@ -558,7 +558,7 @@ Ref FindSkeletonRootJoint(Ref& skinRef) delete[] jointsPerVertex; delete[] vertexWeightData; delete[] vertexJointData; -}*/ +} void glTF2Exporter::ExportMeshes() { @@ -663,9 +663,9 @@ void glTF2Exporter::ExportMeshes() } /*************** Skins ****************/ - /*if(aim->HasBones()) { + if(aim->HasBones()) { ExportSkin(*mAsset, aim, m, b, skinRef, inverseBindMatricesData); - }*/ + } } //---------------------------------------- @@ -892,7 +892,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref bufferRef = mAsset->buffers.Get(unsigned (0)); @@ -961,7 +961,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref