jessey-git / fx-gltf Goto Github PK
View Code? Open in Web Editor NEWA C++14/C++17 header-only library for simple, efficient, and robust serialization/deserialization of glTF 2.0
License: MIT License
A C++14/C++17 header-only library for simple, efficient, and robust serialization/deserialization of glTF 2.0
License: MIT License
Would be really nice if this was integreated. Tinygltf supports it too. But I'am with this library, so either have to replace for Tiny or await draco support in this one ^^.
The 'DefaultMaxMemoryAllocation' in gltf.h is set too small for a number of larger glTF models.
Ideally this should increase dynamically.
Line 1912 of LoadFromBinary reads like this:
nlohmann::json::parse(&json[0], &json[header.jsonHeader.chunkLength]),
But json is a vector of exactly size header.jsonHeader.chunkLength, which makes the second access an out of bounds access. This is intended behavior because the code is trying to get a pointer just after the end of the vector, but it is technically illegal (and undefined behavior!), and visual studio throws an exception in when compiling in debug.
The fix is really simple though, we can just change that line to be:
nlohmann::json::parse(json.begin(), json.end()),
Hi,
I'm attempting to implement your excellent gltf.h header into my code and found that
Int = 5124
... is missing in the ComponentType enum class.
Is that correct?
Thanks
The specifications says that the transform can be given as a columun-major matrix array or with separate TRS properties but its seems the current API does not tell us which form is available. What do you think about using std::optional for optional fields?
In the last version the library has been modified to make use of the api. It no longer builds for 'most' game consoles. Would it be possible to opt out?
Thank you a fantastic library that I use daily!
I've tried to update to latest today. Does not build with the nlohmann/json versions 3.8 and newer due to static basic_json parse(detail::span_input_adapter&& i, const parser_callback_t cb = nullptr, const bool allow_exceptions = true)
being deprecated. It's used in line 1862.
I would like a function that verifies that all naively using the document (only checking indices against -1) will not cause a buffer overrun; i tried writing this but i just started learning the gltf format this week and got confused.
I'm also pretty sure that Animation::Channel::Target::Path has only 4 valid values in the spec, and should be an enum, not a string, but maybe you know something i don't!
I've tried to do it but I got stucked on creating the new buffer, my naive implementation looks like:
`fx::gltf::Document originalDocument;
originalDocument.asset.copyright = "nocopyright";
originalDocument.asset.generator = "fx-gltf";
originalDocument.asset.version = "2.0";
fx::gltf::Scene scene;
fx::gltf::Node node;
fx::gltf::Mesh mesh;
fx::gltf::Primitive primitive;
fx::gltf::Attributes attribute;
scene.name = "myScene";
node.name = "myNode";
mesh.name = "myMesh";
std::vector<uint8_t> newBytes = { 0, 1, 2 };
fx::gltf::Buffer bufferindices;
bufferindices.uri = "indicesBuffer";
bufferindices.byteLength = static_cast<uint32_t>(sizeof(uint8_t)*newBytes.size());
bufferindices.data = newBytes;
bufferindices.SetEmbeddedResource();
originalDocument.buffers.push_back(bufferindices);
fx::gltf::BufferView bufferviewIndices;
bufferviewIndices.buffer = 0;
primitive.indices = 0;
fx::gltf::Accessor acc;
acc.name = "geometryPositions";
acc.type = fx::gltf::Accessor::Type::Vec3;
acc.componentType = fx::gltf::Accessor::ComponentType::Float;
std::vector<float> newPositions = { 0.0f,0.0f,0.0f, 0.0f,0.0f,1.0f, 1.0f,0.0f,0.0f };
fx::gltf::Buffer bufferpositions;
bufferpositions.uri = "positionsBuffer";
bufferpositions.data = newPositions; << fails!!!!!!!!!!
bufferpositions.byteLength = bufferpositions.data.size();
bufferpositions.SetEmbeddedResource();
originalDocument.buffers.push_back(bufferpositions);
fx::gltf::BufferView bufferviewPositions;
bufferviewPositions.buffer = 1;
acc.bufferView = 1;
originalDocument.accessors.push_back(acc);
mesh.primitives.push_back(primitive);
node.mesh = 0;
originalDocument.nodes.push_back(node);
scene.nodes.push_back(0);
originalDocument.scenes.push_back(scene);
originalDocument.scene = 0;
fx::gltf::Save(originalDocument, out, false);`
It doesn't compile since bufferpositions.data = newPositions; triggers an error but also I should connect my Accessor to the mesh itself.
Anyone could give me a tip? Thank you in advance.
This issue came up while trying a few sample models from the gltf sample repository, for example here:
https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/SimpleSparseAccessor/glTF-Embedded/SimpleSparseAccessor.gltf
Trying to load that model fails with Invalid buffer.uri value
.
There's an issue about this in the glTF-Sample-Models repo, but they say the models are fine and the specification need a PR: KhronosGroup/glTF-Sample-Models#244
That PR hasn't received any significant update since Dec 2017, so I'm not sure what would be the best thing to do, but fx-gltf should at least accept the application/gltf-buffer
mimetype along with application/octet-stream
, since there are models out there using that.
Version: fx-gltf 1.1.0
In glTF specification, the all texCoord default values are 0, such as Material.NormalTextureInfo.
Thank you for this wonderful gltf parsing library.
I was trying to build up a gltf file from triangle mesh structure and it turned out really well. But when I was compiling the file, it would pop up this error.
Although it will still complete the compile and the generated gltf seems to be okay, I'm still wondering is there anything I could do to avoid this error? Thanks a lot.
Merge multiple documents into one document. Is this method available?
Hello, I'm looking to replace tinygltf with something more flexible. Both tinygltf and fx-gltf don't have support for reading from std::istream
and writing to std::ostream
which is essential for my application, and I think it's better abstraction and more flexible than filenames, and assuming the client wants to use filesystem to store possibly intermediate data.
Another problem with both libraries is lack of support for custom chunks in the binary input/output. My application works with single .glb file containing all the vertex and image data, and also utilizes JSON extra
and custom binary chunk for storing app specific data.
I would like to contribute to this library and I'm wondering if there's a will in the upstream to merge these improvements. Thank you
Hi,
If the accessor's component type not float the gltf validation shows a lot of INTEGER_WRITTEN_AS_FLOAT message. The min/max vector element type always float.
Zolee
Goal:
Main Requirements:
Other Requirements:
Usage/display of Animation/Skinning data need not be handled as those may be very difficult to work with.
Currently there's no tests for negative conditions:
Don't focus on invalid json itself. nlohmann::json's parser is already well tested.
I honestly can't remember how to suggest adding it with git's interface.
This file defines data structures so that accessors can be interacted with as STL containers
E.g:
` std::vectorglm::vec3 position;
for (auto const & attrib : primitive.attributes)
{
if(attrib.first == "POSITION")
{
stdAccessorVec3 position_array(document, attrib.second);
position = std::vector<glm::vec3>(position_array.begin(), position_array.end());
}
}`
std::array<float, 3> should work just as well as glm::vec3
When given a fx::gltf::Document &, int accessor pair it will throw an error if there is any risk of a buffer overrun when the iterator class is used in a standard way.
could stand to undergo more testing (especially with sparse structures), but works for my purposes.
EDIT: i realized i messed up the ampersands on the interator preinc/postinc, GCC didn't complain because the STL algorithms i was feeding it to wasn't using the one with a bad reference.
Would be great to see how a simple gltf read using fx-gltf can be rendered in opengl.
This is probably a very dumb question, but I wanted to ask regardless. How can I create a GLTF document from scratch? I tried to look through the examples and couldn't find one that would explain it to me. Can you please create an example that creates a GLTF document from scratch and then load it back (as a test)?
I think it would be great if this library had a working/official package for the Conan package manager. This would make installing the library very convenient for those of us that use Conan.
There is actually another repo for a Conan package for this library at https://github.com/birsoyo/conan-fx-gltf but unofficial, uses an unofficial package for nlohmann_json as dependency which can cause problems for those that use that library as well and it does not support the standard CMake workflow (yet at least). Moreover, it's not available on the conan-center Bintray repository.
I would be willing to submit a PR for a Conan recipe if you would be willing to maintain it (update version numbers and such) and upload the package to Bintray. Otherwise, I guess I could make a PR to the other repo instead, make my own repo for it or try to get the Bincrafters community to do it.
What would you prefer? I think that maintaining the package together with the actual library would be preferable, if it would be possible.
nlohmann::json
requires strings in json object has UTF-8 encoding, or it will throw a nlohmann::json::type_error
exception.
So I encode the buffer uri as UTF-8.
The problem comes out when I call fx::gltf::Document::Save()
to save the glTf document in non-binary format. in Save()
, the buffer uri properties are read to form the buffer's output path. It's UTF-8 encoded thereof.
In Windows(for me it's Windows 10 x86-64, Simplified Chinese Language), path passed to std::ofstream::open
or std::ofstream::ofstream
is presumed in native-encoding. Therefor the
bin created is wrong.
For example, the buffer uri is u8"./中文.BIN"
,after create, the file's name became to 涓枃璺緞.BIN
。
A simply workaround is to use c++ 17 filesystem API to do the conversion:
// It does the conversion needed.
std::ofstream ofs(std::filesystem::u8path(u8"./中文.BIN").string());
How to convert GLB to GLTF or Vice Versa
When compiling with clang I am getting the following warnings:
-Wc++11-narrowing
-Wtautological-constant-out-of-range-compare
Namely it doesn't like the DecodeMap array of chars to be initialized with int literals. At current I am suppressing the warning and I am not sure if casting all the numbers to chars will make the code would be an "improvement".
Error message:
../fx-gltf/include/fx/gltf.h: In function ‘void fx::gltf::detail::Save(const fx::gltf::Document&, std::__cxx11::string, bool)’:
../fx-gltf/include/fx/gltf.h:956:35: error: conversion from ‘const fx::gltf::Document’ to non-scalar type ‘nlohmann::json {aka nlohmann::basic_json<>}’ requested
nlohmann::json json = document;
In G++ on ubuntu 17.2, happens with -std=c++14 as well as -std=c++17
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.