Added CustomExtension to glTF2::Object so that all subclasses have it instead of doing it piecemeal.
parent
6d413444b5
commit
5be2330fbb
|
@ -356,6 +356,51 @@ struct Nullable {
|
||||||
isPresent(true) {}
|
isPresent(true) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CustomExtension {
|
||||||
|
//
|
||||||
|
// A struct containing custom extension data added to a glTF2 file
|
||||||
|
// Has to contain Object, Array, String, Double, Uint64, and Int64 at a minimum
|
||||||
|
// String, Double, Uint64, and Int64 are stored in the Nullables
|
||||||
|
// Object and Array are stored in the std::vector
|
||||||
|
//
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
Nullable<std::string> mStringValue;
|
||||||
|
Nullable<double> mDoubleValue;
|
||||||
|
Nullable<uint64_t> mUint64Value;
|
||||||
|
Nullable<int64_t> mInt64Value;
|
||||||
|
Nullable<bool> mBoolValue;
|
||||||
|
|
||||||
|
// std::vector<CustomExtension> handles both Object and Array
|
||||||
|
Nullable<std::vector<CustomExtension>> mValues;
|
||||||
|
|
||||||
|
operator bool() const {
|
||||||
|
return Size() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Size() const {
|
||||||
|
if (mValues.isPresent) {
|
||||||
|
return mValues.value.size();
|
||||||
|
} else if (mStringValue.isPresent || mDoubleValue.isPresent || mUint64Value.isPresent || mInt64Value.isPresent || mBoolValue.isPresent) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomExtension() = default;
|
||||||
|
|
||||||
|
CustomExtension(const CustomExtension &other)
|
||||||
|
: name(other.name)
|
||||||
|
, mStringValue(other.mStringValue)
|
||||||
|
, mDoubleValue(other.mDoubleValue)
|
||||||
|
, mUint64Value(other.mUint64Value)
|
||||||
|
, mInt64Value(other.mInt64Value)
|
||||||
|
, mBoolValue(other.mBoolValue)
|
||||||
|
, mValues(other.mValues)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//! Base class for all glTF top-level objects
|
//! Base class for all glTF top-level objects
|
||||||
struct Object {
|
struct Object {
|
||||||
int index; //!< The index of this object within its property container
|
int index; //!< The index of this object within its property container
|
||||||
|
@ -363,6 +408,8 @@ struct Object {
|
||||||
std::string id; //!< The globally unique ID used to reference this object
|
std::string id; //!< The globally unique ID used to reference this object
|
||||||
std::string name; //!< The user-defined name of this object
|
std::string name; //!< The user-defined name of this object
|
||||||
|
|
||||||
|
CustomExtension extensions;
|
||||||
|
|
||||||
//! Objects marked as special are not exported (used to emulate the binary body buffer)
|
//! Objects marked as special are not exported (used to emulate the binary body buffer)
|
||||||
virtual bool IsSpecial() const { return false; }
|
virtual bool IsSpecial() const { return false; }
|
||||||
|
|
||||||
|
@ -834,50 +881,6 @@ struct Mesh : public Object {
|
||||||
void Read(Value &pJSON_Object, Asset &pAsset_Root);
|
void Read(Value &pJSON_Object, Asset &pAsset_Root);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CustomExtension : public Object {
|
|
||||||
//
|
|
||||||
// A struct containing custom extension data added to a glTF2 file
|
|
||||||
// Has to contain Object, Array, String, Double, Uint64, and Int64 at a minimum
|
|
||||||
// String, Double, Uint64, and Int64 are stored in the Nullables
|
|
||||||
// Object and Array are stored in the std::vector
|
|
||||||
//
|
|
||||||
|
|
||||||
Nullable<std::string> mStringValue;
|
|
||||||
Nullable<double> mDoubleValue;
|
|
||||||
Nullable<uint64_t> mUint64Value;
|
|
||||||
Nullable<int64_t> mInt64Value;
|
|
||||||
Nullable<bool> mBoolValue;
|
|
||||||
|
|
||||||
// std::vector<CustomExtension> handles both Object and Array
|
|
||||||
Nullable<std::vector<CustomExtension>> mValues;
|
|
||||||
|
|
||||||
operator bool() const {
|
|
||||||
return Size() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Size() const {
|
|
||||||
if (mValues.isPresent) {
|
|
||||||
return mValues.value.size();
|
|
||||||
} else if (mStringValue.isPresent || mDoubleValue.isPresent || mUint64Value.isPresent || mInt64Value.isPresent || mBoolValue.isPresent) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomExtension() = default;
|
|
||||||
|
|
||||||
CustomExtension(const CustomExtension &other)
|
|
||||||
: Object(other)
|
|
||||||
, mStringValue(other.mStringValue)
|
|
||||||
, mDoubleValue(other.mDoubleValue)
|
|
||||||
, mUint64Value(other.mUint64Value)
|
|
||||||
, mInt64Value(other.mInt64Value)
|
|
||||||
, mBoolValue(other.mBoolValue)
|
|
||||||
, mValues(other.mValues)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Node : public Object {
|
struct Node : public Object {
|
||||||
std::vector<Ref<Node>> children;
|
std::vector<Ref<Node>> children;
|
||||||
std::vector<Ref<Mesh>> meshes;
|
std::vector<Ref<Mesh>> meshes;
|
||||||
|
@ -896,8 +899,6 @@ struct Node : public Object {
|
||||||
|
|
||||||
Ref<Node> parent; //!< This is not part of the glTF specification. Used as a helper.
|
Ref<Node> parent; //!< This is not part of the glTF specification. Used as a helper.
|
||||||
|
|
||||||
CustomExtension extensions;
|
|
||||||
|
|
||||||
Node() {}
|
Node() {}
|
||||||
void Read(Value &obj, Asset &r);
|
void Read(Value &obj, Asset &r);
|
||||||
};
|
};
|
||||||
|
@ -922,8 +923,6 @@ struct Scene : public Object {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<Ref<Node>> nodes;
|
std::vector<Ref<Node>> nodes;
|
||||||
|
|
||||||
CustomExtension extensions;
|
|
||||||
|
|
||||||
Scene() {}
|
Scene() {}
|
||||||
void Read(Value &obj, Asset &r);
|
void Read(Value &obj, Asset &r);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue