Pārlūkot izejas kodu

Add scene metadata for glTF2 files as allowed by the glTF2 specification.

Evangel 4 gadi atpakaļ
vecāks
revīzija
36c8cdf3de

+ 2 - 0
code/AssetLib/glTF2/glTF2Asset.h

@@ -922,6 +922,8 @@ struct Scene : public Object {
     std::string name;
     std::vector<Ref<Node>> nodes;
 
+    CustomExtension extensions;
+
     Scene() {}
     void Read(Value &obj, Asset &r);
 };

+ 3 - 0
code/AssetLib/glTF2/glTF2Asset.inl

@@ -1803,6 +1803,9 @@ inline void Scene::Read(Value &obj, Asset &r) {
                 this->nodes.push_back(node);
         }
     }
+    if (Value *extensions = FindObject(obj, "extensions")) {
+        this->extensions = ReadExtensions("extensions", *extensions);
+    }
 }
 
 inline void Skin::Read(Value &obj, Asset &r) {

+ 5 - 1
code/AssetLib/glTF2/glTF2Importer.cpp

@@ -1498,7 +1498,8 @@ void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) {
     const bool hasVersion = !a.asset.version.empty();
     const bool hasGenerator = !a.asset.generator.empty();
     const bool hasCopyright = !a.asset.copyright.empty();
-    if (hasVersion || hasGenerator || hasCopyright) {
+    const bool hasSceneMetadata = a.scene->extensions;
+    if (hasVersion || hasGenerator || hasCopyright || hasSceneMetadata) {
         mScene->mMetaData = new aiMetadata;
         if (hasVersion) {
             mScene->mMetaData->Add(AI_METADATA_SOURCE_FORMAT_VERSION, aiString(a.asset.version));
@@ -1509,6 +1510,9 @@ void glTF2Importer::ImportCommonMetadata(glTF2::Asset& a) {
         if (hasCopyright) {
             mScene->mMetaData->Add(AI_METADATA_SOURCE_COPYRIGHT, aiString(a.asset.copyright));
         }
+        if (hasSceneMetadata) {
+            ParseExtensions(mScene->mMetaData, a.scene->extensions);
+        }
     }
 }