mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-04 18:01:16 +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) {
|
||||
std::cout << Indent(indent) << "material : " << primitive.material
|
||||
<< std::endl;
|
||||
@ -333,19 +342,23 @@ static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
|
||||
<< std::endl;
|
||||
DumpStringIntMap(primitive.attributes, indent + 1);
|
||||
|
||||
DumpExtensions(primitive.extensions, indent);
|
||||
std::cout << Indent(indent) << "extras :" << std::endl
|
||||
<< PrintValue("extras", primitive.extras, indent + 1) << std::endl;
|
||||
}
|
||||
|
||||
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;
|
||||
if (!primitive.extensions_json_string.empty()) {
|
||||
std::cout << Indent(indent + 1) << "extensions(JSON string) = "
|
||||
<< primitive.extensions_json_string << "\n";
|
||||
}
|
||||
|
||||
if (!primitive.extras_json_string.empty()) {
|
||||
std::cout << Indent(indent + 1)
|
||||
<< "extras(JSON string) = " << primitive.extras_json_string
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
||||
const int indent) {
|
||||
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
||||
@ -353,6 +366,17 @@ static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
||||
<< "\n";
|
||||
DumpExtensions(texinfo.extensions, indent + 1);
|
||||
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,
|
||||
@ -546,6 +570,21 @@ static void Dump(const tinygltf::Model &model) {
|
||||
std::cout << Indent(2)
|
||||
<< "target : " << PrintTarget(bufferView.target)
|
||||
<< 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(2) << "byteLength : " << buffer.data.size()
|
||||
<< 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);
|
||||
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) << "component : " << image.component << std::endl;
|
||||
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::endl;
|
||||
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)
|
||||
<< "wrapT : " << PrintWrapMode(sampler.wrapT)
|
||||
<< 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
|
||||
<< 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);
|
||||
}
|
||||
|
||||
// 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::TinyGLTF gltf_ctx;
|
||||
std::string err;
|
||||
@ -714,6 +871,9 @@ int main(int argc, char **argv) {
|
||||
std::string input_filename(argv[1]);
|
||||
std::string ext = GetFilePathExtension(input_filename);
|
||||
|
||||
gltf_ctx.SetStoreOriginalJSONForExtrasAndExtensions(
|
||||
store_original_json_for_extras_and_extensions);
|
||||
|
||||
bool ret = false;
|
||||
if (ext.compare("glb") == 0) {
|
||||
std::cout << "Reading binary glTF" << std::endl;
|
||||
|
783
tiny_gltf.h
783
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user