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
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)
-/*
+/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
}
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)
{
}
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);
}
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);
}
ExportScene();
- //ExportAnimations();
+ ExportAnimations();
AssetWriter writer(*mAsset);
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;
delete[] jointsPerVertex;
delete[] vertexWeightData;
delete[] vertexJointData;
-}*/
+}
void glTF2Exporter::ExportMeshes()
{
}
/*************** Skins ****************/
- /*if(aim->HasBones()) {
+ if(aim->HasBones()) {
ExportSkin(*mAsset, aim, m, b, skinRef, inverseBindMatricesData);
- }*/
+ }
}
//----------------------------------------
}
}
-/* void glTF2Exporter::ExportAnimations()
+void glTF2Exporter::ExportAnimations()
{
Ref<Buffer> bufferRef = mAsset->buffers.Get(unsigned (0));
// }
} // End: for-loop mNumAnimations
-} */
+}
#endif // ASSIMP_BUILD_NO_GLTF_EXPORTER