Add gltf scene parsing, change assert messages capitalization
This commit is contained in:
@@ -42,6 +42,18 @@ namespace Inferno {
|
||||
// Scene
|
||||
// ---------------------------------
|
||||
|
||||
if (Json::hasProperty(json, "scenes")) {
|
||||
|
||||
auto scenes = json["scenes"];
|
||||
ASSERT(scenes.is_array(), "GlTF model property 'scenes' invalid type");
|
||||
|
||||
for (auto& [key, object] : scenes.items()) {
|
||||
glTF::Scene scene;
|
||||
parseScene(&scene, key, object);
|
||||
m_model.scenes.emplace_back(std::move(scene));
|
||||
}
|
||||
}
|
||||
|
||||
// Node
|
||||
// ---------------------------------
|
||||
|
||||
@@ -110,18 +122,31 @@ namespace Inferno {
|
||||
{
|
||||
}
|
||||
|
||||
void Gltf::parseScene(glTF::Scene* scene, const std::string& key, const json& object)
|
||||
{
|
||||
auto nodes = Json::parseDoubleArrayProperty(object, "nodes", false);
|
||||
ASSERT(!nodes || nodes.value().size() > 0, "Gltf scene '{}' empty 'nodes' property", key);
|
||||
|
||||
auto name = Json::parseStringProperty(object, "name", false);
|
||||
|
||||
scene->name = name ? name.value() : key;
|
||||
}
|
||||
|
||||
void Gltf::parsePrimitive(glTF::Primitive* primitive, const std::string& key, const json& object)
|
||||
{
|
||||
auto attributes = Json::parseUnsignedObjectProperty(object, "attributes", true);
|
||||
ASSERT(attributes && attributes.value().size() > 0, "GlTF primitive '{}' invalid property 'attributes'", key);
|
||||
ASSERT(attributes && attributes.value().size() > 0, "Gltf primitive '{}' invalid property 'attributes'", key);
|
||||
|
||||
auto indices = Json::parseUnsignedProperty(object, "indices", false);
|
||||
|
||||
auto material = Json::parseUnsignedProperty(object, "material", false);
|
||||
|
||||
auto mode = Json::parseUnsignedProperty(object, "mode", false);
|
||||
|
||||
if (Json::hasProperty(object, "targets")) {
|
||||
|
||||
auto targets = object["targets"];
|
||||
ASSERT(targets.is_array(), "GlTF primitive '{}' property 'targets' invalid type", key);
|
||||
ASSERT(targets.is_array(), "Gltf primitive '{}' property 'targets' invalid type", key);
|
||||
|
||||
for (auto& targetObject : targets) {
|
||||
|
||||
@@ -132,7 +157,7 @@ namespace Inferno {
|
||||
if (value) target.emplace(std::move(key), value.value());
|
||||
}
|
||||
|
||||
ASSERT(target.size() > 0, "GlTF primitive '{}' empty 'target' object", key);
|
||||
ASSERT(target.size() > 0, "Gltf primitive '{}' empty 'target' object", key);
|
||||
primitive->targets.emplace_back(std::move(target));
|
||||
}
|
||||
}
|
||||
@@ -145,9 +170,10 @@ namespace Inferno {
|
||||
|
||||
void Gltf::parseMesh(glTF::Mesh* mesh, const std::string& key, const json& object)
|
||||
{
|
||||
ASSERT(Json::hasProperty(object, "primitives"), "GlTF mesh '{}' missing required property 'primitives'", key);
|
||||
ASSERT(Json::hasProperty(object, "primitives"), "Gltf mesh '{}' missing required property 'primitives'", key);
|
||||
auto primitives = object["primitives"];
|
||||
ASSERT(primitives.is_array(), "GlTF mesh '{}' property 'primitives' invalid type", key);
|
||||
ASSERT(primitives.is_array(), "Gltf mesh '{}' property 'primitives' invalid type", key);
|
||||
|
||||
for (auto& primitiveObject : primitives) {
|
||||
glTF::Primitive primitive;
|
||||
parsePrimitive(&primitive, key, primitiveObject);
|
||||
@@ -155,7 +181,7 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
auto weights = Json::parseDoubleArrayProperty(object, "weights", false);
|
||||
ASSERT(!weights || weights.value().size() > 0, "GlTF mesh '{}' empty 'weights' property", key);
|
||||
ASSERT(!weights || weights.value().size() > 0, "Gltf mesh '{}' empty 'weights' property", key);
|
||||
|
||||
auto name = Json::parseStringProperty(object, "name", false);
|
||||
|
||||
@@ -170,21 +196,21 @@ namespace Inferno {
|
||||
auto byteOffset = Json::parseUnsignedProperty(object, "byteOffset", false);
|
||||
|
||||
auto componentType = Json::parseUnsignedProperty(object, "componentType", true);
|
||||
ASSERT(componentType, "GlTF accessor '{}' missing required property 'componentType'", key);
|
||||
ASSERT(componentType, "Gltf accessor '{}' missing required property 'componentType'", key);
|
||||
|
||||
auto normalized = Json::parseBoolProperty(object, "normalized", false);
|
||||
|
||||
auto count = Json::parseUnsignedProperty(object, "count", true);
|
||||
ASSERT(count, "GlTF accessor '{}' missing required property 'count'", key);
|
||||
ASSERT(count, "Gltf accessor '{}' missing required property 'count'", key);
|
||||
|
||||
auto type = Json::parseStringProperty(object, "type", true);
|
||||
ASSERT(type, "GlTF accessor '{}' missing required property 'type'", key);
|
||||
ASSERT(type, "Gltf accessor '{}' missing required property 'type'", key);
|
||||
|
||||
auto max = Json::parseDoubleArrayProperty(object, "max", false);
|
||||
ASSERT(!max || max.value().size() > 0, "GlTF accessor '{}' empty 'max' property", key);
|
||||
ASSERT(!max || max.value().size() > 0, "Gltf accessor '{}' empty 'max' property", key);
|
||||
|
||||
auto min = Json::parseDoubleArrayProperty(object, "min", false);
|
||||
ASSERT(!min || min.value().size() > 0, "GlTF accessor '{}' empty 'min' property", key);
|
||||
ASSERT(!min || min.value().size() > 0, "Gltf accessor '{}' empty 'min' property", key);
|
||||
|
||||
auto name = Json::parseStringProperty(object, "name", false);
|
||||
|
||||
@@ -201,12 +227,12 @@ namespace Inferno {
|
||||
void Gltf::parseBufferView(glTF::BufferView* bufferView, const std::string& key, const json& object)
|
||||
{
|
||||
auto buffer = Json::parseUnsignedProperty(object, "buffer", false);
|
||||
ASSERT(buffer, "GlTF bufferView '{}' missing required property 'buffer'", key);
|
||||
ASSERT(buffer, "Gltf bufferView '{}' missing required property 'buffer'", key);
|
||||
|
||||
auto byteOffset = Json::parseUnsignedProperty(object, "byteOffset", false);
|
||||
|
||||
auto byteLength = Json::parseUnsignedProperty(object, "byteLength", true);
|
||||
ASSERT(byteLength, "GlTF bufferView '{}' missing required property 'byteLength'", key);
|
||||
ASSERT(byteLength, "Gltf bufferView '{}' missing required property 'byteLength'", key);
|
||||
|
||||
auto byteStride = Json::parseUnsignedProperty(object, "byteStride", false);
|
||||
|
||||
@@ -227,7 +253,7 @@ namespace Inferno {
|
||||
auto uri = Json::parseStringProperty(object, "buffer", false);
|
||||
|
||||
auto byteLength = Json::parseUnsignedProperty(object, "byteLength", true);
|
||||
ASSERT(byteLength, "GlTF buffer '{}' missing required property 'byteLength'", key);
|
||||
ASSERT(byteLength, "Gltf buffer '{}' missing required property 'byteLength'", key);
|
||||
|
||||
auto name = Json::parseStringProperty(object, "name", false);
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@ namespace Inferno {
|
||||
|
||||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#objects
|
||||
|
||||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scene
|
||||
struct Scene {
|
||||
std::vector<uint32_t> nodes;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-asset
|
||||
struct Asset {
|
||||
std::string copyright;
|
||||
@@ -73,6 +79,7 @@ namespace Inferno {
|
||||
struct Model {
|
||||
Asset asset;
|
||||
|
||||
std::vector<Scene> scenes;
|
||||
std::vector<Mesh> meshes;
|
||||
std::vector<Accessor> accessors;
|
||||
std::vector<BufferView> bufferViews;
|
||||
@@ -91,6 +98,7 @@ namespace Inferno {
|
||||
inline const glTF::Model& model() const { return m_model; }
|
||||
|
||||
private:
|
||||
static void parseScene(glTF::Scene* scene, const std::string& key, const json& object);
|
||||
static void parsePrimitive(glTF::Primitive* primitive, const std::string& key, const json& object);
|
||||
static void parseMesh(glTF::Mesh* mesh, const std::string& key, const json& object);
|
||||
static void parseAccessor(glTF::Accessor* accessor, const std::string& key, const json& object);
|
||||
|
||||
Reference in New Issue
Block a user