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

pull/3955/head
Evangel 2021-06-12 11:44:28 +10:00
parent 2f4fba0703
commit 36c8cdf3de
3 changed files with 10 additions and 1 deletions

View File

@ -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);
};

View File

@ -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) {

View File

@ -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);
}
}
}