reenable animation and skins exports
authorDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Fri, 1 Sep 2017 21:49:04 +0000 (17:49 -0400)
committerDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Mon, 11 Sep 2017 14:55:50 +0000 (10:55 -0400)
Currently incorrect, however. May need to be removed

code/glTF2Asset.h
code/glTF2Asset.inl
code/glTF2Exporter.cpp

index 1f9f48e..8e3a6dd 100644 (file)
@@ -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<T*>     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<T> Retrieve(unsigned int i);
 
         Ref<T> Get(unsigned int i);
+        Ref<T> Get(const char* id);
 
         Ref<T> Create(const char* id);
         Ref<T> Create(const std::string& id)
index dd110eb..5316b5e 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*
 Open Asset Import Library (assimp)
 ----------------------------------------------------------------------
 
@@ -194,14 +194,6 @@ inline void LazyDict<T>::DetachFromDocument()
 }
 
 template<class T>
-Ref<T> LazyDict<T>::Get(unsigned int i)
-{
-
-    return Ref<T>(mObjs, i);
-
-}
-
-template<class T>
 Ref<T> LazyDict<T>::Retrieve(unsigned int i)
 {
 
@@ -235,11 +227,33 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i)
 }
 
 template<class T>
+Ref<T> LazyDict<T>::Get(unsigned int i)
+{
+
+    return Ref<T>(mObjs, i);
+
+}
+
+template<class T>
+Ref<T> LazyDict<T>::Get(const char* id)
+{
+    id = T::TranslateId(mAsset, id);
+
+    typename IdDict::iterator it = mObjsById.find(id);
+    if (it != mObjsById.end()) { // already created?
+        return Ref<T>(mObjs, it->second);
+    }
+
+    throw std::out_of_range("id \"" + std::string(id) + "\" Doesn't exist");
+}
+
+template<class T>
 Ref<T> LazyDict<T>::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<T>(mObjs, idx);
 }
@@ -252,8 +266,10 @@ Ref<T> LazyDict<T>::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<int>(mObjs.size());
+    inst->index = idx;
+    inst->oIndex = idx;
     return Add(inst);
 }
 
index ae610d1..164b559 100644 (file)
@@ -121,7 +121,7 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
 
     ExportScene();
 
-    //ExportAnimations();
+    ExportAnimations();
 
     AssetWriter writer(*mAsset);
 
@@ -481,7 +481,7 @@ Ref<Node> FindSkeletonRootJoint(Ref<Skin>& skinRef)
     return parentNodeRef;
 }
 
-/*void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buffer>& bufferRef, Ref<Skin>& skinRef, std::vector<aiMatrix4x4>& inverseBindMatricesData)
+void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref<Mesh>& meshRef, Ref<Buffer>& bufferRef, Ref<Skin>& skinRef, std::vector<aiMatrix4x4>& inverseBindMatricesData)
 {
     if (aimesh->mNumBones < 1) {
         return;
@@ -558,7 +558,7 @@ Ref<Node> FindSkeletonRootJoint(Ref<Skin>& 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<Animati
     }
 }
 
-/* void glTF2Exporter::ExportAnimations()
+void glTF2Exporter::ExportAnimations()
 {
     Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
 
@@ -961,7 +961,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref<Animati
         // }
 
     } // End: for-loop mNumAnimations
-} */
+}
 
 
 #endif // ASSIMP_BUILD_NO_GLTF_EXPORTER