Merge pull request #1 from syoyo/master

update fork
This commit is contained in:
Benjamin Schmithüsen 2019-07-08 17:40:20 +02:00 committed by GitHub
commit 0ffedcbe79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 35 deletions

View File

@ -66,6 +66,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
* Physical based rendering with Vulkan using glTF 2.0 models https://github.com/SaschaWillems/Vulkan-glTF-PBR * Physical based rendering with Vulkan using glTF 2.0 models https://github.com/SaschaWillems/Vulkan-glTF-PBR
* GLTF loader plugin for OGRE 2.1. Support for PBR materials via HLMS/PBS https://github.com/Ybalrid/Ogre_glTF * GLTF loader plugin for OGRE 2.1. Support for PBR materials via HLMS/PBS https://github.com/Ybalrid/Ogre_glTF
* [TinyGltfImporter](http://doc.magnum.graphics/magnum/classMagnum_1_1Trade_1_1TinyGltfImporter.html) plugin for [Magnum](https://github.com/mosra/magnum), a lightweight and modular C++11/C++14 graphics middleware for games and data visualization. * [TinyGltfImporter](http://doc.magnum.graphics/magnum/classMagnum_1_1Trade_1_1TinyGltfImporter.html) plugin for [Magnum](https://github.com/mosra/magnum), a lightweight and modular C++11/C++14 graphics middleware for games and data visualization.
* [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine) - A modern cross-platform low-level graphics library and rendering framework
* Your projects here! (Please send PR) * Your projects here! (Please send PR)
## TODOs ## TODOs

View File

@ -46,5 +46,8 @@
"max": [2], "max": [2],
"min": [0] "min": [0]
} }
] ],
"asset": {
"version": "2.0"
}
} }

View File

@ -29,5 +29,8 @@
"max": [2], "max": [2],
"min": [0] "min": [0]
} }
] ],
"asset": {
"version": "2.0"
}
} }

View File

@ -29,5 +29,8 @@
"max": [2], "max": [2],
"min": [0] "min": [0]
} }
] ],
"asset": {
"version": "2.0"
}
} }

View File

@ -390,9 +390,34 @@ struct Parameter {
if (it != std::end(json_double_value)) { if (it != std::end(json_double_value)) {
return int(it->second); return int(it->second);
} }
// As per the spec, if texCoord is ommited, this parameter is 0
return 0; return 0;
} }
/// Return the scale of a texture if this Parameter is a normal texture map.
/// Returned value is only valid if the parameter represent a normal texture
/// from a material
double TextureScale() const {
const auto it = json_double_value.find("scale");
if (it != std::end(json_double_value)) {
return it->second;
}
// As per the spec, if scale is ommited, this paramter is 1
return 1;
}
/// Return the strength of a texture if this Parameter is a an occlusion map.
/// Returned value is only valid if the parameter represent an occlusion map
/// from a material
double TextureStrength() const {
const auto it = json_double_value.find("strength");
if (it != std::end(json_double_value)) {
return it->second;
}
// As per the spec, if strenghth is ommited, this parameter is 1
return 1;
}
/// Material factor, like the roughness or metalness of a material /// Material factor, like the roughness or metalness of a material
/// Returned value is only valid if the parameter represent a texture from a /// Returned value is only valid if the parameter represent a texture from a
/// material /// material
@ -437,8 +462,8 @@ struct AnimationChannel {
struct AnimationSampler { struct AnimationSampler {
int input; // required int input; // required
int output; // required int output; // required
std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE", std::string interpolation; // "LINEAR", "STEP","CUBICSPLINE" or user defined
// "CUBICSPLINE"], default "LINEAR" // string. default "LINEAR"
Value extras; Value extras;
AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {} AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {}
@ -708,7 +733,6 @@ struct Mesh {
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;
ExtensionMap extensions; ExtensionMap extensions;
Value extras; Value extras;
@ -719,6 +743,7 @@ class Node {
public: public:
Node() : camera(-1), skin(-1), mesh(-1) {} Node() : camera(-1), skin(-1), mesh(-1) {}
// TODO(syoyo): Could use `default`
Node(const Node &rhs) { Node(const Node &rhs) {
camera = rhs.camera; camera = rhs.camera;
@ -736,6 +761,9 @@ class Node {
extras = rhs.extras; extras = rhs.extras;
} }
~Node() {} ~Node() {}
Node &operator=(const Node &rhs) = default;
bool operator==(const Node &) const; bool operator==(const Node &) const;
int camera; // the index of the camera referenced by this node int camera; // the index of the camera referenced by this node
@ -796,7 +824,12 @@ struct Light {
class Model { class Model {
public: public:
Model() {} Model() {}
Model(const Model &) = default;
Model &operator=(const Model &) = default;
~Model() {} ~Model() {}
bool operator==(const Model &) const; bool operator==(const Model &) const;
std::vector<Accessor> accessors; std::vector<Accessor> accessors;
@ -1304,8 +1337,7 @@ bool Material::operator==(const Material &other) const {
} }
bool Mesh::operator==(const Mesh &other) const { bool Mesh::operator==(const Mesh &other) const {
return this->extensions == other.extensions && this->extras == other.extras && return this->extensions == other.extensions && this->extras == other.extras &&
this->name == other.name && this->primitives == other.primitives && this->name == other.name && this->primitives == other.primitives;
this->targets == other.targets && Equals(this->weights, other.weights);
} }
bool Model::operator==(const Model &other) const { bool Model::operator==(const Model &other) const {
return this->accessors == other.accessors && return this->accessors == other.accessors &&
@ -3097,7 +3129,7 @@ static bool ParseAccessor(Accessor *accessor, std::string *err, const json &o) {
if (componentType >= TINYGLTF_COMPONENT_TYPE_BYTE && if (componentType >= TINYGLTF_COMPONENT_TYPE_BYTE &&
componentType <= TINYGLTF_COMPONENT_TYPE_DOUBLE) { componentType <= TINYGLTF_COMPONENT_TYPE_DOUBLE) {
// OK // OK
accessor->componentType = componentType; accessor->componentType = int(componentType);
} else { } else {
std::stringstream ss; std::stringstream ss;
ss << "Invalid `componentType` in accessor. Got " << componentType ss << "Invalid `componentType` in accessor. Got " << componentType
@ -3383,24 +3415,6 @@ static bool ParseMesh(Mesh *mesh, Model *model, std::string *err,
} }
} }
// Look for morph targets
json::const_iterator targetsObject = o.find("targets");
if ((targetsObject != o.end()) && targetsObject.value().is_array()) {
for (json::const_iterator i = targetsObject.value().begin();
i != targetsObject.value().end(); i++) {
std::map<std::string, int> targetAttribues;
const json &dict = i.value();
json::const_iterator dictIt(dict.begin());
json::const_iterator dictItEnd(dict.end());
for (; dictIt != dictItEnd; ++dictIt) {
targetAttribues[dictIt.key()] = static_cast<int>(dictIt.value());
}
mesh->targets.push_back(targetAttribues);
}
}
// Should probably check if has targets and if dimensions fit // Should probably check if has targets and if dimensions fit
ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false); ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false);
@ -3478,7 +3492,9 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o) {
} else { } else {
Parameter param; Parameter param;
if (ParseParameterProperty(&param, err, o, it.key(), false)) { if (ParseParameterProperty(&param, err, o, it.key(), false)) {
material->additionalValues[it.key()] = param; // names of materials have already been parsed. Putting it in this map
// doesn't correctly reflext the glTF specification
if (it.key() != "name") material->additionalValues[it.key()] = param;
} }
} }
} }
@ -4848,6 +4864,10 @@ static void SerializeGltfAsset(Asset &asset, json &o) {
SerializeStringProperty("generator", asset.generator, o); SerializeStringProperty("generator", asset.generator, o);
} }
if (!asset.copyright.empty()) {
SerializeStringProperty("copyright", asset.copyright, o);
}
if (!asset.version.empty()) { if (!asset.version.empty()) {
SerializeStringProperty("version", asset.version, o); SerializeStringProperty("version", asset.version, o);
} }
@ -4916,8 +4936,7 @@ static void SerializeGltfImage(Image &image, json &o) {
if (image.uri.empty()) { if (image.uri.empty()) {
SerializeStringProperty("mimeType", image.mimeType, o); SerializeStringProperty("mimeType", image.mimeType, o);
SerializeNumberProperty<int>("bufferView", image.bufferView, o); SerializeNumberProperty<int>("bufferView", image.bufferView, o);
} } else {
else {
SerializeStringProperty("uri", image.uri, o); SerializeStringProperty("uri", image.uri, o);
} }
@ -5146,6 +5165,9 @@ static void SerializeGltfTexture(Texture &texture, json &o) {
if (texture.source > -1) { if (texture.source > -1) {
SerializeNumberProperty("source", texture.source, o); SerializeNumberProperty("source", texture.source, o);
} }
if (texture.name.size()) {
SerializeStringProperty("name", texture.name, o);
}
if (texture.extras.Type() != NULL_TYPE) { if (texture.extras.Type() != NULL_TYPE) {
SerializeValue("extras", texture.extras, o); SerializeValue("extras", texture.extras, o);
} }