in GLTFSDK/Source/Serialize.cpp [85:128]
void SerializePropertyExtensions(const Document& doc, const glTFProperty& property, rapidjson::Value& propertyValue, rapidjson::Document::AllocatorType& a, const ExtensionSerializer& extensionSerializer)
{
auto registeredExtensions = property.GetExtensions();
if (!property.extensions.empty() || !registeredExtensions.empty())
{
rapidjson::Value& extensions = RapidJsonUtils::FindOrAddMember(propertyValue, "extensions", a);
// Add registered extensions
for (const auto& extension : registeredExtensions)
{
const auto extensionPair = extensionSerializer.Serialize(extension, property, doc);
if (property.HasUnregisteredExtension(extensionPair.name))
{
throw GLTFException("Registered extension '" + extensionPair.name + "' is also present as an unregistered extension.");
}
if (doc.extensionsUsed.find(extensionPair.name) == doc.extensionsUsed.end())
{
throw GLTFException("Registered extension '" + extensionPair.name + "' is not present in extensionsUsed");
}
const auto d = RapidJsonUtils::CreateDocumentFromString(extensionPair.value);//TODO: validate the returned document against the extension schema!
rapidjson::Value v(rapidjson::kObjectType);
v.CopyFrom(d, a);
extensions.AddMember(RapidJsonUtils::ToStringValue(extensionPair.name, a), v, a);
}
// Add unregistered extensions
for (const auto& extension : property.extensions)
{
if (doc.extensionsUsed.find(extension.first) == doc.extensionsUsed.end())
{
throw GLTFException("Unregistered extension '" + extension.first + "' is not present in extensionsUsed");
}
const auto d = RapidJsonUtils::CreateDocumentFromString(extension.second);//TODO: validate the returned document against the extension schema!
rapidjson::Value v(rapidjson::kObjectType);
v.CopyFrom(d, a);
extensions.AddMember(RapidJsonUtils::ToStringValue(extension.first, a), v, a);
}
}
}