Got rid of gltf2::ExtrasValue and used gltf2::CustomExtension instead
parent
cb4d0ab7aa
commit
da58fbe8fb
|
@ -378,36 +378,9 @@ struct CustomExtension {
|
|||
CustomExtension& operator=(const CustomExtension&) = default;
|
||||
};
|
||||
|
||||
//! Represents a union of metadata values. Only one nullable is supposed to be set.
|
||||
struct ExtrasValue {
|
||||
std::string name;
|
||||
|
||||
Nullable<bool> mBoolValue;
|
||||
Nullable<int32_t> mInt32Value;
|
||||
Nullable<uint64_t> mUint64Value;
|
||||
Nullable<float> mFloatValue;
|
||||
Nullable<double> mDoubleValue;
|
||||
Nullable<std::string> mStringValue;
|
||||
Nullable<std::vector<ExtrasValue>> mMetadataValue;
|
||||
|
||||
ExtrasValue() = default;
|
||||
~ExtrasValue() = default;
|
||||
|
||||
ExtrasValue(const ExtrasValue& other) :
|
||||
name(other.name),
|
||||
mStringValue(other.mStringValue),
|
||||
mFloatValue(other.mFloatValue),
|
||||
mDoubleValue(other.mDoubleValue),
|
||||
mUint64Value(other.mUint64Value),
|
||||
mInt32Value(other.mInt32Value),
|
||||
mBoolValue(other.mBoolValue),
|
||||
mMetadataValue(other.mMetadataValue) {
|
||||
}
|
||||
};
|
||||
|
||||
//! Represents metadata in an glTF2 object
|
||||
struct Extras {
|
||||
std::vector<ExtrasValue> mValues;
|
||||
std::vector<CustomExtension> mValues;
|
||||
|
||||
inline bool HasExtras() const {
|
||||
return mValues.size() != 0;
|
||||
|
|
|
@ -139,45 +139,13 @@ inline CustomExtension ReadExtensions(const char *name, Value &obj) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline ExtrasValue ReadExtrasValue(const char *name, Value &obj) {
|
||||
ExtrasValue ret;
|
||||
ret.name = name;
|
||||
|
||||
if (obj.IsObject()) {
|
||||
ret.mMetadataValue.value.reserve(obj.MemberCount());
|
||||
ret.mMetadataValue.isPresent = true;
|
||||
for (auto it = obj.MemberBegin(); it != obj.MemberEnd(); ++it) {
|
||||
auto &val = it->value;
|
||||
ret.mMetadataValue.value.push_back(ReadExtrasValue(it->name.GetString(), val));
|
||||
}
|
||||
} else if (obj.IsNumber()) {
|
||||
if (obj.IsUint64()) {
|
||||
ret.mUint64Value.value = obj.GetUint64();
|
||||
ret.mUint64Value.isPresent = true;
|
||||
} else if (obj.IsInt()) {
|
||||
ret.mInt32Value.value = obj.GetInt64();
|
||||
ret.mInt32Value.isPresent = true;
|
||||
} else if (obj.IsDouble()) {
|
||||
ret.mDoubleValue.value = obj.GetDouble();
|
||||
ret.mDoubleValue.isPresent = true;
|
||||
}
|
||||
} else if (obj.IsString()) {
|
||||
ReadValue(obj, ret.mStringValue);
|
||||
ret.mStringValue.isPresent = true;
|
||||
} else if (obj.IsBool()) {
|
||||
ret.mBoolValue.value = obj.GetBool();
|
||||
ret.mBoolValue.isPresent = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline Extras ReadExtras(Value &obj) {
|
||||
Extras ret;
|
||||
|
||||
ret.mValues.reserve(obj.MemberCount());
|
||||
for (auto it = obj.MemberBegin(); it != obj.MemberEnd(); ++it) {
|
||||
auto &val = it->value;
|
||||
ret.mValues.push_back(ReadExtrasValue(it->name.GetString(), val));
|
||||
ret.mValues.push_back(ReadExtensions(it->name.GetString(), val));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -620,7 +620,7 @@ namespace glTF2 {
|
|||
}
|
||||
}
|
||||
|
||||
inline void WriteExtrasValue(Value &parent, const ExtrasValue &value, AssetWriter &w) {
|
||||
inline void WriteExtrasValue(Value &parent, const CustomExtension &value, AssetWriter &w) {
|
||||
Value valueNode;
|
||||
|
||||
if (value.mStringValue.isPresent) {
|
||||
|
@ -629,13 +629,13 @@ namespace glTF2 {
|
|||
MakeValue(valueNode, value.mDoubleValue.value, w.mAl);
|
||||
} else if (value.mUint64Value.isPresent) {
|
||||
MakeValue(valueNode, value.mUint64Value.value, w.mAl);
|
||||
} else if (value.mInt32Value.isPresent) {
|
||||
MakeValue(valueNode, value.mInt32Value.value, w.mAl);
|
||||
} else if (value.mInt64Value.isPresent) {
|
||||
MakeValue(valueNode, value.mInt64Value.value, w.mAl);
|
||||
} else if (value.mBoolValue.isPresent) {
|
||||
MakeValue(valueNode, value.mBoolValue.value, w.mAl);
|
||||
} else if (value.mMetadataValue.isPresent) {
|
||||
} else if (value.mValues.isPresent) {
|
||||
valueNode.SetObject();
|
||||
for (auto const &subvalue : value.mMetadataValue.value) {
|
||||
for (auto const &subvalue : value.mValues.value) {
|
||||
WriteExtrasValue(valueNode, subvalue, w);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -445,7 +445,7 @@ inline Ref<Accessor> ExportData(Asset &a, std::string &meshName, Ref<Buffer> &bu
|
|||
return acc;
|
||||
}
|
||||
|
||||
inline void ExportNodeExtras(const aiMetadataEntry &metadataEntry, aiString name, ExtrasValue &value) {
|
||||
inline void ExportNodeExtras(const aiMetadataEntry &metadataEntry, aiString name, CustomExtension &value) {
|
||||
|
||||
value.name = name.C_Str();
|
||||
switch (metadataEntry.mType) {
|
||||
|
@ -454,17 +454,13 @@ inline void ExportNodeExtras(const aiMetadataEntry &metadataEntry, aiString name
|
|||
value.mBoolValue.isPresent = true;
|
||||
break;
|
||||
case AI_INT32:
|
||||
value.mInt32Value.value = *static_cast<int32_t *>(metadataEntry.mData);
|
||||
value.mInt32Value.isPresent = true;
|
||||
value.mInt64Value.value = *static_cast<int32_t *>(metadataEntry.mData);
|
||||
value.mInt64Value.isPresent = true;
|
||||
break;
|
||||
case AI_UINT64:
|
||||
value.mUint64Value.value = *static_cast<uint64_t *>(metadataEntry.mData);
|
||||
value.mUint64Value.isPresent = true;
|
||||
break;
|
||||
case AI_FLOAT:
|
||||
value.mFloatValue.value = *static_cast<double *>(metadataEntry.mData);
|
||||
value.mFloatValue.isPresent = true;
|
||||
break;
|
||||
case AI_DOUBLE:
|
||||
value.mDoubleValue.value = *static_cast<double *>(metadataEntry.mData);
|
||||
value.mDoubleValue.isPresent = true;
|
||||
|
@ -475,11 +471,11 @@ inline void ExportNodeExtras(const aiMetadataEntry &metadataEntry, aiString name
|
|||
break;
|
||||
case AI_AIMETADATA:
|
||||
const aiMetadata *subMetadata = static_cast<aiMetadata *>(metadataEntry.mData);
|
||||
value.mMetadataValue.value.resize(subMetadata->mNumProperties);
|
||||
value.mMetadataValue.isPresent = true;
|
||||
value.mValues.value.resize(subMetadata->mNumProperties);
|
||||
value.mValues.isPresent = true;
|
||||
|
||||
for (unsigned i = 0; i < subMetadata->mNumProperties; ++i) {
|
||||
ExportNodeExtras(subMetadata->mValues[i], subMetadata->mKeys[i], value.mMetadataValue.value.at(i));
|
||||
ExportNodeExtras(subMetadata->mValues[i], subMetadata->mKeys[i], value.mValues.value.at(i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1033,33 +1033,9 @@ void ParseExtensions(aiMetadata *metadata, const CustomExtension &extension) {
|
|||
}
|
||||
}
|
||||
|
||||
void ParseExtrasValue(aiMetadata *metadata, const ExtrasValue &value) {
|
||||
|
||||
if (value.mBoolValue.isPresent) {
|
||||
metadata->Add(value.name, value.mBoolValue.value);
|
||||
} else if (value.mInt32Value.isPresent) {
|
||||
metadata->Add(value.name, value.mInt32Value.value);
|
||||
} else if (value.mUint64Value.isPresent) {
|
||||
metadata->Add(value.name, value.mUint64Value.value);
|
||||
} else if (value.mFloatValue.isPresent) {
|
||||
metadata->Add(value.name, value.mFloatValue.value);
|
||||
} else if (value.mDoubleValue.isPresent) {
|
||||
metadata->Add(value.name, value.mDoubleValue.value);
|
||||
} else if (value.mStringValue.isPresent) {
|
||||
metadata->Add(value.name, aiString(value.mStringValue.value));
|
||||
} else if (value.mMetadataValue.isPresent) {
|
||||
aiMetadata subMetadata;
|
||||
for (auto const &subValue : value.mMetadataValue.value) {
|
||||
ParseExtrasValue(&subMetadata, subValue);
|
||||
}
|
||||
|
||||
metadata->Add(value.name, subMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
void ParseExtras(aiMetadata* metadata, const Extras& extras) {
|
||||
for (auto const &value : extras.mValues) {
|
||||
ParseExtrasValue(metadata, value);
|
||||
ParseExtensions(metadata, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue