浏览代码

reenable animation and skins exports

Currently incorrect, however. May need to be removed
Daniel Hritzkiv 8 年之前
父节点
当前提交
ab08a7c3cb
共有 3 个文件被更改,包括 36 次插入17 次删除
  1. 3 0
      code/glTF2Asset.h
  2. 26 10
      code/glTF2Asset.inl
  3. 7 7
      code/glTF2Exporter.cpp

+ 3 - 0
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<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)

+ 26 - 10
code/glTF2Asset.inl

@@ -1,4 +1,4 @@
-/*
+/*
 Open Asset Import Library (assimp)
 ----------------------------------------------------------------------
 
@@ -193,14 +193,6 @@ inline void LazyDict<T>::DetachFromDocument()
     mDict = 0;
 }
 
-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)
 {
@@ -234,12 +226,34 @@ Ref<T> LazyDict<T>::Retrieve(unsigned int i)
     return Add(inst);
 }
 
+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);
 }
 

+ 7 - 7
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<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