mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-04 20:00:42 +08:00
Add feature to store original JSON string for extras and extensions(for user-specific JSON parsing). # Fixes 215
Fix some glTF object(e.g. Skin) does not have extras and/or extensions property.
This commit is contained in:
parent
1100f0f1eb
commit
6e08b17ce3
@ -322,6 +322,15 @@ static void DumpStringIntMap(const std::map<std::string, int> &m, int indent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DumpExtensions(const tinygltf::ExtensionMap &extension,
|
||||||
|
const int indent) {
|
||||||
|
// TODO(syoyo): pritty print Value
|
||||||
|
for (auto &e : extension) {
|
||||||
|
std::cout << Indent(indent) << e.first << std::endl;
|
||||||
|
std::cout << PrintValue("extensions", e.second, indent + 1) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
|
static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
|
||||||
std::cout << Indent(indent) << "material : " << primitive.material
|
std::cout << Indent(indent) << "material : " << primitive.material
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -333,19 +342,23 @@ static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
DumpStringIntMap(primitive.attributes, indent + 1);
|
DumpStringIntMap(primitive.attributes, indent + 1);
|
||||||
|
|
||||||
|
DumpExtensions(primitive.extensions, indent);
|
||||||
std::cout << Indent(indent) << "extras :" << std::endl
|
std::cout << Indent(indent) << "extras :" << std::endl
|
||||||
<< PrintValue("extras", primitive.extras, indent + 1) << std::endl;
|
<< PrintValue("extras", primitive.extras, indent + 1) << std::endl;
|
||||||
|
|
||||||
|
if (!primitive.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(indent + 1) << "extensions(JSON string) = "
|
||||||
|
<< primitive.extensions_json_string << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpExtensions(const tinygltf::ExtensionMap &extension,
|
if (!primitive.extras_json_string.empty()) {
|
||||||
const int indent) {
|
std::cout << Indent(indent + 1)
|
||||||
// TODO(syoyo): pritty print Value
|
<< "extras(JSON string) = " << primitive.extras_json_string
|
||||||
for (auto &e : extension) {
|
<< "\n";
|
||||||
std::cout << Indent(indent) << e.first << std::endl;
|
|
||||||
std::cout << PrintValue("extensions", e.second, indent + 1) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
||||||
const int indent) {
|
const int indent) {
|
||||||
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
||||||
@ -353,6 +366,17 @@ static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
|||||||
<< "\n";
|
<< "\n";
|
||||||
DumpExtensions(texinfo.extensions, indent + 1);
|
DumpExtensions(texinfo.extensions, indent + 1);
|
||||||
std::cout << PrintValue("extras", texinfo.extras, indent + 1) << "\n";
|
std::cout << PrintValue("extras", texinfo.extras, indent + 1) << "\n";
|
||||||
|
|
||||||
|
if (!texinfo.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(indent)
|
||||||
|
<< "extensions(JSON string) = " << texinfo.extensions_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!texinfo.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(indent)
|
||||||
|
<< "extras(JSON string) = " << texinfo.extras_json_string << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpNormalTextureInfo(const tinygltf::NormalTextureInfo &texinfo,
|
static void DumpNormalTextureInfo(const tinygltf::NormalTextureInfo &texinfo,
|
||||||
@ -546,6 +570,21 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
std::cout << Indent(2)
|
std::cout << Indent(2)
|
||||||
<< "target : " << PrintTarget(bufferView.target)
|
<< "target : " << PrintTarget(bufferView.target)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
std::cout << Indent(1) << "-------------------------------------\n";
|
||||||
|
|
||||||
|
DumpExtensions(bufferView.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", bufferView.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!bufferView.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< bufferView.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bufferView.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << bufferView.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,6 +595,21 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
std::cout << Indent(1) << "name : " << buffer.name << std::endl;
|
std::cout << Indent(1) << "name : " << buffer.name << std::endl;
|
||||||
std::cout << Indent(2) << "byteLength : " << buffer.data.size()
|
std::cout << Indent(2) << "byteLength : " << buffer.data.size()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
std::cout << Indent(1) << "-------------------------------------\n";
|
||||||
|
|
||||||
|
DumpExtensions(buffer.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", buffer.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!buffer.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< buffer.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buffer.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << buffer.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,6 +656,17 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
|
|
||||||
DumpExtensions(material.extensions, 1);
|
DumpExtensions(material.extensions, 1);
|
||||||
std::cout << PrintValue("extras", material.extras, 2) << std::endl;
|
std::cout << PrintValue("extras", material.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!material.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< material.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!material.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << material.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,6 +690,18 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
std::cout << Indent(2) << "height : " << image.height << std::endl;
|
std::cout << Indent(2) << "height : " << image.height << std::endl;
|
||||||
std::cout << Indent(2) << "component : " << image.component << std::endl;
|
std::cout << Indent(2) << "component : " << image.component << std::endl;
|
||||||
DumpExtensions(image.extensions, 1);
|
DumpExtensions(image.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", image.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!image.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< image.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!image.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << image.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,6 +714,18 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
std::cout << Indent(1) << "source : " << texture.source
|
std::cout << Indent(1) << "source : " << texture.source
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
DumpExtensions(texture.extensions, 1);
|
DumpExtensions(texture.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", texture.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!texture.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< texture.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!texture.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << texture.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,6 +747,20 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
std::cout << Indent(2)
|
std::cout << Indent(2)
|
||||||
<< "wrapT : " << PrintWrapMode(sampler.wrapT)
|
<< "wrapT : " << PrintWrapMode(sampler.wrapT)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
DumpExtensions(sampler.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", sampler.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!sampler.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< sampler.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sampler.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << sampler.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,6 +793,54 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
<< "znear : " << camera.orthographic.znear
|
<< "znear : " << camera.orthographic.znear
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << Indent(1) << "-------------------------------------\n";
|
||||||
|
|
||||||
|
DumpExtensions(camera.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", camera.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!camera.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2) << "extensions(JSON string) = "
|
||||||
|
<< camera.extensions_json_string << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!camera.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << camera.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::cout << "skins(items=" << model.skins.size() << ")" << std::endl;
|
||||||
|
for (size_t i = 0; i < model.skins.size(); i++) {
|
||||||
|
const tinygltf::Skin &skin = model.skins[i];
|
||||||
|
std::cout << Indent(1) << "name : " << skin.name << std::endl;
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "inverseBindMatrices : " << skin.inverseBindMatrices
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << Indent(2) << "skeleton : " << skin.skeleton
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "joints : " << PrintIntArray(skin.joints)
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << Indent(1) << "-------------------------------------\n";
|
||||||
|
|
||||||
|
DumpExtensions(skin.extensions, 1);
|
||||||
|
std::cout << PrintValue("extras", skin.extras, 2) << std::endl;
|
||||||
|
|
||||||
|
if (!skin.extensions_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extensions(JSON string) = " << skin.extensions_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!skin.extras_json_string.empty()) {
|
||||||
|
std::cout << Indent(2)
|
||||||
|
<< "extras(JSON string) = " << skin.extras_json_string
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,6 +858,12 @@ int main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store original JSON string for `extras` and `extensions`
|
||||||
|
bool store_original_json_for_extras_and_extensions = false;
|
||||||
|
if (argc > 2) {
|
||||||
|
store_original_json_for_extras_and_extensions = true;
|
||||||
|
}
|
||||||
|
|
||||||
tinygltf::Model model;
|
tinygltf::Model model;
|
||||||
tinygltf::TinyGLTF gltf_ctx;
|
tinygltf::TinyGLTF gltf_ctx;
|
||||||
std::string err;
|
std::string err;
|
||||||
@ -714,6 +871,9 @@ int main(int argc, char **argv) {
|
|||||||
std::string input_filename(argv[1]);
|
std::string input_filename(argv[1]);
|
||||||
std::string ext = GetFilePathExtension(input_filename);
|
std::string ext = GetFilePathExtension(input_filename);
|
||||||
|
|
||||||
|
gltf_ctx.SetStoreOriginalJSONForExtrasAndExtensions(
|
||||||
|
store_original_json_for_extras_and_extensions);
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (ext.compare("glb") == 0) {
|
if (ext.compare("glb") == 0) {
|
||||||
std::cout << "Reading binary glTF" << std::endl;
|
std::cout << "Reading binary glTF" << std::endl;
|
||||||
|
775
tiny_gltf.h
775
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user