Apply clang-format.

This commit is contained in:
Syoyo Fujita 2018-06-04 18:40:16 +09:00
parent 0067a9e43a
commit 4769b1ca37

View File

@ -4,7 +4,8 @@
// //
// The MIT License (MIT) // The MIT License (MIT)
// //
// Copyright (c) 2015 - 2017 Syoyo Fujita, Aurélien Chatelain and many contributors. // Copyright (c) 2015 - 2017 Syoyo Fujita, Aurélien Chatelain and many
// contributors.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -288,27 +289,20 @@ typedef std::map<std::string, Parameter> ParameterMap;
struct AnimationChannel { struct AnimationChannel {
int sampler; // required int sampler; // required
int target_node; // required (index of the node to target) int target_node; // required (index of the node to target)
std::string target_path; // required in ["translation", "rotation", "scale", "weights"] std::string target_path; // required in ["translation", "rotation", "scale",
// "weights"]
Value extras; Value extras;
AnimationChannel() AnimationChannel() : sampler(-1), target_node(-1) {}
: sampler(-1)
, target_node(-1)
{
}
}; };
struct AnimationSampler { struct AnimationSampler {
int input; // required int input; // required
int output; // required int output; // required
std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE", "CUBICSPLINE"], default "LINEAR" std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE",
// "CUBICSPLINE"], default "LINEAR"
AnimationSampler() AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {}
: input(-1)
, output(-1)
, interpolation("LINEAR")
{
}
}; };
typedef struct { typedef struct {
@ -324,30 +318,29 @@ struct Skin {
int skeleton; // The index of the node used as a skeleton root int skeleton; // The index of the node used as a skeleton root
std::vector<int> joints; // Indices of skeleton nodes std::vector<int> joints; // Indices of skeleton nodes
Skin() Skin() { inverseBindMatrices = -1; }
{
inverseBindMatrices = -1;
}
}; };
struct Sampler { struct Sampler {
std::string name; std::string name;
int minFilter; // ["NEAREST", "LINEAR", "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST", "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_LINEAR"] int minFilter; // ["NEAREST", "LINEAR", "NEAREST_MIPMAP_LINEAR",
// "LINEAR_MIPMAP_NEAREST", "NEAREST_MIPMAP_LINEAR",
// "LINEAR_MIPMAP_LINEAR"]
int magFilter; // ["NEAREST", "LINEAR"] int magFilter; // ["NEAREST", "LINEAR"]
int wrapS; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default "REPEAT" int wrapS; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default
int wrapT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default "REPEAT" // "REPEAT"
int wrapT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default
// "REPEAT"
int wrapR; // TinyGLTF extension int wrapR; // TinyGLTF extension
int pad0; int pad0;
Value extras; Value extras;
Sampler() Sampler()
: wrapS(TINYGLTF_TEXTURE_WRAP_RPEAT) : wrapS(TINYGLTF_TEXTURE_WRAP_RPEAT),
, wrapT(TINYGLTF_TEXTURE_WRAP_RPEAT) wrapT(TINYGLTF_TEXTURE_WRAP_RPEAT) {}
{
}
}; };
struct Image{ struct Image {
std::string name; std::string name;
int width; int width;
int height; int height;
@ -359,10 +352,7 @@ struct Image{
std::string uri; // (reqiored if no mimeType) std::string uri; // (reqiored if no mimeType)
Value extras; Value extras;
Image() Image() { bufferView = -1; }
{
bufferView = -1;
}
}; };
struct Texture { struct Texture {
@ -370,11 +360,7 @@ struct Texture {
int source; // Required (not specified in the spec ?) int source; // Required (not specified in the spec ?)
Value extras; Value extras;
Texture() Texture() : sampler(-1), source(-1) {}
: sampler(-1)
, source(-1)
{
}
}; };
// Each extension should be stored in a ParameterMap. // Each extension should be stored in a ParameterMap.
@ -390,7 +376,7 @@ struct Material {
Value extras; Value extras;
}; };
struct BufferView{ struct BufferView {
std::string name; std::string name;
int buffer; // Required int buffer; // Required
size_t byteOffset; // minimum 0, default 0 size_t byteOffset; // minimum 0, default 0
@ -400,15 +386,12 @@ struct BufferView{
int pad0; int pad0;
Value extras; Value extras;
BufferView() BufferView() : byteOffset(0), byteStride(4) {}
: byteOffset(0)
, byteStride(4)
{}
}; };
struct Accessor { struct Accessor {
int bufferView; // optional in spec but required here since sparse accessor are not supported int bufferView; // optional in spec but required here since sparse accessor
// are not supported
std::string name; std::string name;
size_t byteOffset; size_t byteOffset;
size_t byteStride; size_t byteStride;
@ -420,10 +403,7 @@ struct Accessor {
std::vector<double> minValues; // required std::vector<double> minValues; // required
std::vector<double> maxValues; // required std::vector<double> maxValues; // required
Accessor() Accessor() { bufferView = -1; }
{
bufferView = -1;
}
}; };
class Camera { class Camera {
@ -438,7 +418,7 @@ class Camera {
float xMag; // required float xMag; // required
float yMag; // required float yMag; // required
float zFar; // required float zFar; // required
float zNear; //required float zNear; // required
// Perspective properties // Perspective properties
float aspectRatio; float aspectRatio;
@ -459,13 +439,14 @@ struct Primitive {
// when rendering. // when rendering.
int indices; // The index of the accessor that contains the indices. int indices; // The index of the accessor that contains the indices.
int mode; // one of TINYGLTF_MODE_*** int mode; // one of TINYGLTF_MODE_***
std::vector<std::map<std::string, int> > targets; // array of morph targets, std::vector<std::map<std::string, int> >
//where each target is a dict with attribues in ["POSITION, "NORMAL", "TANGENT"] pointing targets; // array of morph targets,
// where each target is a dict with attribues in ["POSITION,
// "NORMAL", "TANGENT"] pointing
// to their corresponding accessors // to their corresponding accessors
Value extras; Value extras;
Primitive() Primitive() {
{
material = -1; material = -1;
indices = -1; indices = -1;
} }
@ -475,18 +456,14 @@ typedef struct {
std::string name; std::string name;
std::vector<Primitive> primitives; std::vector<Primitive> primitives;
std::vector<double> weights; // weights to be applied to the Morph Targets std::vector<double> weights; // weights to be applied to the Morph Targets
std::vector<std::map<std::string, int> >targets; std::vector<std::map<std::string, int> > targets;
ParameterMap extensions; ParameterMap extensions;
Value extras; Value extras;
} Mesh; } Mesh;
class Node { class Node {
public: public:
Node() Node() : skin(-1), mesh(-1) {}
: skin(-1)
, mesh(-1)
{
}
~Node() {} ~Node() {}
@ -508,7 +485,8 @@ class Node {
typedef struct { typedef struct {
std::string name; std::string name;
std::vector<unsigned char> data; std::vector<unsigned char> data;
std::string uri; // considered as required here but not in the spec (need to clarify) std::string
uri; // considered as required here but not in the spec (need to clarify)
Value extras; Value extras;
} Buffer; } Buffer;
@ -733,7 +711,8 @@ static std::string ExpandFilePath(const std::string &filepath) {
} }
// char** w; // char** w;
// wrap filepath by quotes to avoid splitting file path when the path contains spaces(more precisely, $IFS environment variables). // wrap filepath by quotes to avoid splitting file path when the path contains
// spaces(more precisely, $IFS environment variables).
std::string quoted_filepath = "\"" + filepath + "\""; std::string quoted_filepath = "\"" + filepath + "\"";
int ret = wordexp(quoted_filepath.c_str(), &p, 0); int ret = wordexp(quoted_filepath.c_str(), &p, 0);
if (ret) { if (ret) {
@ -921,6 +900,9 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
size_t sz = static_cast<size_t>(f.tellg()); size_t sz = static_cast<size_t>(f.tellg());
if (int(sz) < 0) { if (int(sz) < 0) {
// Looks reading directory, not a file. // Looks reading directory, not a file.
if (err) {
(*err) += "Looks like filepath is a directory : \"" + filepath + "\"\n";
}
return false; return false;
} }
std::vector<unsigned char> buf(sz); std::vector<unsigned char> buf(sz);
@ -955,8 +937,10 @@ static bool LoadImageData(Image *image, std::string *err, int req_width,
int w, h, comp; int w, h, comp;
// if image cannot be decoded, ignore parsing and keep it by its path // if image cannot be decoded, ignore parsing and keep it by its path
// don't break in this case // don't break in this case
//FIXME we should only enter this function if the image is embedded. If image->uri references // FIXME we should only enter this function if the image is embedded. If
// an image file, it should be left as it is. Image loading should not be mandatory (to support other formats) // image->uri references
// an image file, it should be left as it is. Image loading should not be
// mandatory (to support other formats)
unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, 0); unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, 0);
if (!data) { if (!data) {
if (err) { if (err) {
@ -1164,7 +1148,9 @@ static bool ParseBooleanProperty(bool *ret, std::string *err,
static bool ParseNumberProperty(double *ret, std::string *err, static bool ParseNumberProperty(double *ret, std::string *err,
const picojson::object &o, const picojson::object &o,
const std::string &property, const bool required, const std::string &parent_node = "") { const std::string &property,
const bool required,
const std::string &parent_node = "") {
picojson::object::const_iterator it = o.find(property); picojson::object::const_iterator it = o.find(property);
if (it == o.end()) { if (it == o.end()) {
if (required) { if (required) {
@ -1197,8 +1183,7 @@ static bool ParseNumberProperty(double *ret, std::string *err,
static bool ParseNumberArrayProperty(std::vector<double> *ret, std::string *err, static bool ParseNumberArrayProperty(std::vector<double> *ret, std::string *err,
const picojson::object &o, const picojson::object &o,
const std::string &property, const std::string &property, bool required,
bool required,
const std::string &parent_node = "") { const std::string &parent_node = "") {
picojson::object::const_iterator it = o.find(property); picojson::object::const_iterator it = o.find(property);
if (it == o.end()) { if (it == o.end()) {
@ -1328,23 +1313,20 @@ static bool ParseStringIntProperty(std::map<std::string, int> *ret,
return true; return true;
} }
static bool ParseJSONProperty(std::map<std::string, double> *ret, std::string *err, static bool ParseJSONProperty(std::map<std::string, double> *ret,
const picojson::object &o, std::string *err, const picojson::object &o,
const std::string &property, const std::string &property, bool required) {
bool required)
{
picojson::object::const_iterator it = o.find(property); picojson::object::const_iterator it = o.find(property);
if(it == o.end()) if (it == o.end()) {
{
if (required) { if (required) {
if(err) { if (err) {
(*err) += "'" + property + "' property is missing. \n'"; (*err) += "'" + property + "' property is missing. \n'";
} }
} }
return false; return false;
} }
if(!it->second.is<picojson::object>()) { if (!it->second.is<picojson::object>()) {
if (required) { if (required) {
if (err) { if (err) {
(*err) += "'" + property + "' property is not a JSON object.\n"; (*err) += "'" + property + "' property is not a JSON object.\n";
@ -1358,8 +1340,9 @@ static bool ParseJSONProperty(std::map<std::string, double> *ret, std::string *e
picojson::object::const_iterator it2(obj.begin()); picojson::object::const_iterator it2(obj.begin());
picojson::object::const_iterator itEnd(obj.end()); picojson::object::const_iterator itEnd(obj.end());
for (; it2 != itEnd; it2++) { for (; it2 != itEnd; it2++) {
if(it2->second.is<double>()) if (it2->second.is<double>())
ret->insert(std::pair<std::string, double>(it2->first, it2->second.get<double>())); ret->insert(std::pair<std::string, double>(it2->first,
it2->second.get<double>()));
} }
return true; return true;
@ -1383,7 +1366,8 @@ static bool ParseImage(Image *image, std::string *err,
size_t bin_size) { size_t bin_size) {
// A glTF image must either reference a bufferView or an image uri // A glTF image must either reference a bufferView or an image uri
double bufferView = -1; double bufferView = -1;
bool isEmbedded = ParseNumberProperty(&bufferView, err, o, "bufferView", true); bool isEmbedded =
ParseNumberProperty(&bufferView, err, o, "bufferView", true);
isEmbedded = isEmbedded && static_cast<int>(bufferView) != -1; isEmbedded = isEmbedded && static_cast<int>(bufferView) != -1;
std::string uri; std::string uri;
@ -1508,8 +1492,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
ParseStringProperty(&uri, err, o, "uri", false, "Buffer"); ParseStringProperty(&uri, err, o, "uri", false, "Buffer");
// having an empty uri for a non embedded image should not be valid // having an empty uri for a non embedded image should not be valid
if(!is_binary && uri.empty()) if (!is_binary && uri.empty()) {
{
if (err) { if (err) {
(*err) += "'uri' is missing from non binary glTF file buffer.\n"; (*err) += "'uri' is missing from non binary glTF file buffer.\n";
} }
@ -1529,13 +1512,10 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
if (is_binary) { if (is_binary) {
// Still binary glTF accepts external dataURI. First try external resources. // Still binary glTF accepts external dataURI. First try external resources.
if(!uri.empty()) if (!uri.empty()) {
{
// External .bin file. // External .bin file.
LoadExternalFile(&buffer->data, err, uri, basedir, bytes, true); LoadExternalFile(&buffer->data, err, uri, basedir, bytes, true);
} } else {
else
{
// load data from (embedded) binary data // load data from (embedded) binary data
if ((bin_size == 0) || (bin_data == NULL)) { if ((bin_size == 0) || (bin_data == NULL)) {
@ -1558,8 +1538,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
// Read buffer data // Read buffer data
buffer->data.resize(static_cast<size_t>(byteLength)); buffer->data.resize(static_cast<size_t>(byteLength));
memcpy(&(buffer->data.at(0)), bin_data, memcpy(&(buffer->data.at(0)), bin_data, static_cast<size_t>(byteLength));
static_cast<size_t>(byteLength));
} }
} else { } else {
@ -1594,7 +1573,8 @@ static bool ParseBufferView(BufferView *bufferView, std::string *err,
ParseNumberProperty(&byteOffset, err, o, "byteOffset", false); ParseNumberProperty(&byteOffset, err, o, "byteOffset", false);
double byteLength = 1.0; double byteLength = 1.0;
if(!ParseNumberProperty(&byteLength, err, o, "byteLength", true, "BufferView")) { if (!ParseNumberProperty(&byteLength, err, o, "byteLength", true,
"BufferView")) {
return false; return false;
} }
@ -1625,7 +1605,8 @@ static bool ParseBufferView(BufferView *bufferView, std::string *err,
static bool ParseAccessor(Accessor *accessor, std::string *err, static bool ParseAccessor(Accessor *accessor, std::string *err,
const picojson::object &o) { const picojson::object &o) {
double bufferView = -1.0; double bufferView = -1.0;
if (!ParseNumberProperty(&bufferView, err, o, "bufferView", true, "Accessor")) { if (!ParseNumberProperty(&bufferView, err, o, "bufferView", true,
"Accessor")) {
return false; return false;
} }
@ -1633,7 +1614,8 @@ static bool ParseAccessor(Accessor *accessor, std::string *err,
ParseNumberProperty(&byteOffset, err, o, "byteOffset", false, "Accessor"); ParseNumberProperty(&byteOffset, err, o, "byteOffset", false, "Accessor");
double componentType = 0.0; double componentType = 0.0;
if (!ParseNumberProperty(&componentType, err, o, "componentType", true, "Accessor")) { if (!ParseNumberProperty(&componentType, err, o, "componentType", true,
"Accessor")) {
return false; return false;
} }
@ -1677,13 +1659,11 @@ static bool ParseAccessor(Accessor *accessor, std::string *err,
accessor->minValues.clear(); accessor->minValues.clear();
accessor->maxValues.clear(); accessor->maxValues.clear();
if(!ParseNumberArrayProperty(&accessor->minValues, err, o, "min", false, "Accessor")) { ParseNumberArrayProperty(&accessor->minValues, err, o, "min", false,
return false; "Accessor");
}
if(!ParseNumberArrayProperty(&accessor->maxValues, err, o, "max", false, "Accessor")) { ParseNumberArrayProperty(&accessor->maxValues, err, o, "max", false,
return false; "Accessor");
}
accessor->count = static_cast<size_t>(count); accessor->count = static_cast<size_t>(count);
accessor->bufferView = static_cast<int>(bufferView); accessor->bufferView = static_cast<int>(bufferView);
@ -1756,7 +1736,8 @@ static bool ParseMesh(Mesh *mesh, std::string *err, const picojson::object &o) {
// Look for morph targets // Look for morph targets
picojson::object::const_iterator targetsObject = o.find("targets"); picojson::object::const_iterator targetsObject = o.find("targets");
if ((targetsObject != o.end()) && (targetsObject->second).is<picojson::array>()) { if ((targetsObject != o.end()) &&
(targetsObject->second).is<picojson::array>()) {
const picojson::array &targetArray = const picojson::array &targetArray =
(targetsObject->second).get<picojson::array>(); (targetsObject->second).get<picojson::array>();
for (size_t i = 0; i < targetArray.size(); i++) { for (size_t i = 0; i < targetArray.size(); i++) {
@ -1767,7 +1748,8 @@ static bool ParseMesh(Mesh *mesh, std::string *err, const picojson::object &o) {
picojson::object::const_iterator dictItEnd(dict.end()); picojson::object::const_iterator dictItEnd(dict.end());
for (; dictIt != dictItEnd; ++dictIt) { for (; dictIt != dictItEnd; ++dictIt) {
targetAttribues[dictIt->first] = static_cast<int>(dictIt->second.get<double>()); targetAttribues[dictIt->first] =
static_cast<int>(dictIt->second.get<double>());
} }
mesh->targets.push_back(targetAttribues); mesh->targets.push_back(targetAttribues);
} }
@ -1789,8 +1771,7 @@ static bool ParseNode(Node *node, std::string *err, const picojson::object &o) {
node->skin = static_cast<int>(skin); node->skin = static_cast<int>(skin);
// Matrix and T/R/S are exclusive // Matrix and T/R/S are exclusive
if(!ParseNumberArrayProperty(&node->matrix, err, o, "matrix", false)) { if (!ParseNumberArrayProperty(&node->matrix, err, o, "matrix", false)) {
ParseNumberArrayProperty(&node->rotation, err, o, "rotation", false); ParseNumberArrayProperty(&node->rotation, err, o, "rotation", false);
ParseNumberArrayProperty(&node->scale, err, o, "scale", false); ParseNumberArrayProperty(&node->scale, err, o, "scale", false);
ParseNumberArrayProperty(&node->translation, err, o, "translation", false); ParseNumberArrayProperty(&node->translation, err, o, "translation", false);
@ -1817,7 +1798,8 @@ static bool ParseNode(Node *node, std::string *err, const picojson::object &o) {
} }
return false; return false;
} }
const int &childrenNode = static_cast<int>(childrenArray[i].get<double>()); const int &childrenNode =
static_cast<int>(childrenArray[i].get<double>());
node->children.push_back(childrenNode); node->children.push_back(childrenNode);
} }
} }
@ -1847,9 +1829,10 @@ static bool ParseParameterProperty(Parameter *param, std::string *err,
} else if (ParseNumberProperty(&num_val, err, o, prop, false)) { } else if (ParseNumberProperty(&num_val, err, o, prop, false)) {
param->number_array.push_back(num_val); param->number_array.push_back(num_val);
return true; return true;
} else if(ParseJSONProperty(&param->json_double_value, err, o, prop, false)) { } else if (ParseJSONProperty(&param->json_double_value, err, o, prop,
false)) {
return true; return true;
} else if(ParseBooleanProperty(&param->bool_value, err, o, prop, false)) { } else if (ParseBooleanProperty(&param->bool_value, err, o, prop, false)) {
return true; return true;
} else { } else {
if (required) { if (required) {
@ -1863,7 +1846,6 @@ static bool ParseParameterProperty(Parameter *param, std::string *err,
static bool ParseMaterial(Material *material, std::string *err, static bool ParseMaterial(Material *material, std::string *err,
const picojson::object &o) { const picojson::object &o) {
material->values.clear(); material->values.clear();
material->extPBRValues.clear(); material->extPBRValues.clear();
material->additionalValues.clear(); material->additionalValues.clear();
@ -1872,8 +1854,7 @@ static bool ParseMaterial(Material *material, std::string *err,
picojson::object::const_iterator itEnd(o.end()); picojson::object::const_iterator itEnd(o.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
if(it->first == "pbrMetallicRoughness") if (it->first == "pbrMetallicRoughness") {
{
if ((it->second).is<picojson::object>()) { if ((it->second).is<picojson::object>()) {
const picojson::object &values_object = const picojson::object &values_object =
(it->second).get<picojson::object>(); (it->second).get<picojson::object>();
@ -1889,15 +1870,13 @@ static bool ParseMaterial(Material *material, std::string *err,
} }
} }
} }
} } else if (it->first == "extensions") {
else if(it->first == "extensions")
{
if ((it->second).is<picojson::object>()) { if ((it->second).is<picojson::object>()) {
const picojson::object &extension = (it->second).get<picojson::object>(); const picojson::object &extension =
(it->second).get<picojson::object>();
picojson::object::const_iterator extIt = extension.begin(); picojson::object::const_iterator extIt = extension.begin();
if(!extIt->second.is<picojson::object>()) if (!extIt->second.is<picojson::object>()) continue;
continue;
const picojson::object &values_object = const picojson::object &values_object =
(extIt->second).get<picojson::object>(); (extIt->second).get<picojson::object>();
@ -1913,12 +1892,9 @@ static bool ParseMaterial(Material *material, std::string *err,
} }
} }
} }
} } else {
else
{
Parameter param; Parameter param;
if (ParseParameterProperty(&param, err, o, it->first, if (ParseParameterProperty(&param, err, o, it->first, false)) {
false)) {
material->additionalValues[it->first] = param; material->additionalValues[it->first] = param;
} }
} }
@ -1945,8 +1921,7 @@ static bool ParseAnimationChannel(AnimationChannel *channel, std::string *err,
const picojson::object &target_object = const picojson::object &target_object =
(targetIt->second).get<picojson::object>(); (targetIt->second).get<picojson::object>();
if (!ParseNumberProperty(&targetIndex, err, target_object, "node", if (!ParseNumberProperty(&targetIndex, err, target_object, "node", true)) {
true)) {
if (err) { if (err) {
(*err) += "`id` field is missing in animation.channels.target\n"; (*err) += "`id` field is missing in animation.channels.target\n";
} }
@ -2060,9 +2035,7 @@ static bool ParseSampler(Sampler *sampler, std::string *err,
return true; return true;
} }
static bool ParseSkin(Skin *skin, std::string *err, static bool ParseSkin(Skin *skin, std::string *err, const picojson::object &o) {
const picojson::object &o) {
ParseStringProperty(&skin->name, err, o, "name", false, "Skin"); ParseStringProperty(&skin->name, err, o, "name", false, "Skin");
std::vector<double> joints; std::vector<double> joints;
@ -2098,9 +2071,9 @@ bool TinyGLTFLoader::LoadFromString(Model *model, std::string *err,
} }
// scene is not mandatory. // scene is not mandatory.
//FIXME Maybe a better way to handle it than removing the code // FIXME Maybe a better way to handle it than removing the code
if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) { if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
// OK // OK
} else if (check_sections & REQUIRE_SCENES) { } else if (check_sections & REQUIRE_SCENES) {
if (err) { if (err) {
@ -2136,8 +2109,7 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
return false; return false;
} }
if (v.contains("bufferViews") && if (v.contains("bufferViews") && v.get("bufferViews").is<picojson::array>()) {
v.get("bufferViews").is<picojson::array>()) {
// OK // OK
} else if (check_sections & REQUIRE_BUFFER_VIEWS) { } else if (check_sections & REQUIRE_BUFFER_VIEWS) {
if (err) { if (err) {
@ -2162,10 +2134,11 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
} }
// 0. Parse extensionUsed // 0. Parse extensionUsed
if (v.contains("extensionsUsed") && v.get("extensionsUsed").is<picojson::array>()) { if (v.contains("extensionsUsed") &&
const picojson::array &root = v.get("extensionsUsed").get<picojson::array>(); v.get("extensionsUsed").is<picojson::array>()) {
for(unsigned int i=0; i< root.size(); ++i) const picojson::array &root =
{ v.get("extensionsUsed").get<picojson::array>();
for (unsigned int i = 0; i < root.size(); ++i) {
model->extensionsUsed.push_back(root[i].get<std::string>()); model->extensionsUsed.push_back(root[i].get<std::string>());
} }
} }
@ -2178,8 +2151,8 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
Buffer buffer; Buffer buffer;
if (!ParseBuffer(&buffer, err, it->get<picojson::object>(), if (!ParseBuffer(&buffer, err, it->get<picojson::object>(), base_dir,
base_dir, is_binary_, bin_data_, bin_size_)) { is_binary_, bin_data_, bin_size_)) {
return false; return false;
} }
@ -2187,17 +2160,16 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
} }
} }
// 2. Parse BufferView // 2. Parse BufferView
if (v.contains("bufferViews") && if (v.contains("bufferViews") && v.get("bufferViews").is<picojson::array>()) {
v.get("bufferViews").is<picojson::array>()) {
const picojson::array &root = v.get("bufferViews").get<picojson::array>(); const picojson::array &root = v.get("bufferViews").get<picojson::array>();
picojson::array::const_iterator it(root.begin()); picojson::array::const_iterator it(root.begin());
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
BufferView bufferView; BufferView bufferView;
if (!ParseBufferView(&bufferView, err, if (!ParseBufferView(&bufferView, err, it->get<picojson::object>())) {
it->get<picojson::object>())) {
return false; return false;
} }
@ -2213,8 +2185,7 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
Accessor accessor; Accessor accessor;
if (!ParseAccessor(&accessor, err, if (!ParseAccessor(&accessor, err, it->get<picojson::object>())) {
it->get<picojson::object>())) {
return false; return false;
} }
@ -2316,8 +2287,8 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
Image image; Image image;
if (!ParseImage(&image, err, it->get<picojson::object>(), if (!ParseImage(&image, err, it->get<picojson::object>(), base_dir,
base_dir, is_binary_, bin_data_, bin_size_)) { is_binary_, bin_data_, bin_size_)) {
return false; return false;
} }
@ -2333,7 +2304,8 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
return false; return false;
} }
const BufferView &bufferView = model->bufferViews[size_t(image.bufferView)]; const BufferView &bufferView =
model->bufferViews[size_t(image.bufferView)];
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)]; const Buffer &buffer = model->buffers[size_t(bufferView.buffer)];
bool ret = LoadImageData(&image, err, image.width, image.height, bool ret = LoadImageData(&image, err, image.width, image.height,
@ -2356,8 +2328,7 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; it++) { for (; it != itEnd; it++) {
Texture texture; Texture texture;
if (!ParseTexture(&texture, err, it->get<picojson::object>(), if (!ParseTexture(&texture, err, it->get<picojson::object>(), base_dir)) {
base_dir)) {
return false; return false;
} }
@ -2373,8 +2344,7 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; ++it) { for (; it != itEnd; ++it) {
Animation animation; Animation animation;
if (!ParseAnimation(&animation, err, if (!ParseAnimation(&animation, err, it->get<picojson::object>())) {
it->get<picojson::object>())) {
return false; return false;
} }
@ -2390,8 +2360,7 @@ if (v.contains("scenes") && v.get("scenes").is<picojson::array>()) {
picojson::array::const_iterator itEnd(root.end()); picojson::array::const_iterator itEnd(root.end());
for (; it != itEnd; ++it) { for (; it != itEnd; ++it) {
Skin skin; Skin skin;
if (!ParseSkin(&skin, err, if (!ParseSkin(&skin, err, it->get<picojson::object>())) {
it->get<picojson::object>())) {
return false; return false;
} }
@ -2516,7 +2485,8 @@ bool TinyGLTFLoader::LoadBinaryFromMemory(Model *model, std::string *err,
model_length); model_length);
is_binary_ = true; is_binary_ = true;
bin_data_ = bytes + 20 + model_length + 8; // 4 bytes (buffer_length) + 4 bytes(buffer_format) bin_data_ = bytes + 20 + model_length +
8; // 4 bytes (buffer_length) + 4 bytes(buffer_format)
bin_size_ = bin_size_ =
length - (20 + model_length); // extract header + JSON scene data. length - (20 + model_length); // extract header + JSON scene data.