Coder Social home page Coder Social logo

jessey-git / fx-gltf Goto Github PK

View Code? Open in Web Editor NEW
350.0 350.0 38.0 3.03 MB

A C++14/C++17 header-only library for simple, efficient, and robust serialization/deserialization of glTF 2.0

License: MIT License

C++ 95.38% CMake 4.62%
directx directx-12 directx12 fx-gltf gltf gltf-loader gltf2

fx-gltf's People

Contributors

ansoulom avatar dimitri-tdg avatar jessey-git avatar nasso avatar otri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fx-gltf's Issues

[Suggestion] Conan package

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.

Implement small DX12/Vulkan viewer using fx-gltf

Goal:

  • Real world use case (may find fx-gltf problems)
  • Create APIs to help interpret the Buffer data (practical experience will yield better APIs)

Main Requirements:

  • API abstraction layer so we can use both Vulkan and DX12
    • No immediate mode rendering
  • Simple mouse movements (Rotate, Pan, Zoom etc.)
  • A "solid" lighting view (no materials)
  • Able to load/use material data
    • Implement shaders as necessary (perhaps use HLSL exclusively and output GLSL from that...)
    • Pick a "good" image load library / limit to only .png files perhaps?

Other Requirements:

  • A PBR implementation

Usage/display of Animation/Skinning data need not be handled as those may be very difficult to work with.

buffer uri containning non-ASCII characters cause problems

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());

Custom chunks and STL iostream read/write

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

Testing: Negative/Exceptional cases are missing

Currently there's no tests for negative conditions:

  • Using incorrect gltf json (missing required elements, nonsensical data etc.)
  • Using the API to build invalid gltf models (exceptions during Save etc.)

Don't focus on invalid json itself. nlohmann::json's parser is already well tested.

Does not build with the nlohmann/json versions 3.8 and newer

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.

Out of bounds access reading GLBs

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()),

Merge document

Merge multiple documents into one document. Is this method available?

Funcition to verify document

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!

Missing ComponentType Int (5124)

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

Accessor validation message

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

How can I create a GLTF file from scratch?

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)?

Error with "fx::gltf::Accessor::Sparse"

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.
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.

Is there a basic example of how to create a simple triangle?

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.

Compile error in void fx::gltf::detail::Save

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

Warnings with clang

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".

`application/gltf-buffer` data uris not supported

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

[Suggestion] Draco support

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 ^^.

Dependency on <filesystem>

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?

thirdparty example addition

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.

stl_accessor.zip

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.