Comments (9)
My understanding is that right now this function should be on the order of 20 lines of code if we don't need to handle sparse data?
Re: "range of indices", I really do believe we should keep this API as simple as possible, hence my later suggestion about one-at-a-time. Function call overhead wouldn't matter in a typical single-file-use scenario where cgltf.h implementation is included into a single source file using it, and I'm not sure how substantial the reduction is if you just consider reading in short bursts (it's typical to read 2 floats per texcoord for example).
I'd suggest limiting the implementation to a single returned value in the interest of interface simplicity and checking the overhead with inlining disabled.
from cgltf.
I coded this up, I can make a PR after I add tests and support for sparse accessors.
from cgltf.
The idea is interesting. I'm wondering if it's better to do something like
void cgltf_accessor_read(const cgltf_accessor* accessor, size_t index, cgltf_float* out, size_t out_size);
so that the caller doesn't need to allocate a large buffer? Or maybe something like
cgltf_float cgltf_accessor_read_float(const cgltf_accessor* accessor, size_t index, size_t component);
cgltf_int cgltf_accessor_read_int(const cgltf_accessor* accessor, size_t index, size_t component);
This can then be used to parse index buffers, vertex buffers, bone indices etc. - it can return 0 on errors (all validation could happen in cgltf_validate
). I definitely end up writing something along these lines whenever I need to parse GLTF files.
from cgltf.
@prideout Something like this would be very welcome.
@zeux's first suggestion (void cgltf_accessor_read(const cgltf_accessor*, size_t, cgltf_float*, size_t)
) looks the most practical to me. It probably wouldn't be such a big difference from your implementation, @prideout?
The functions for reading one value at a time would presumably have quite a big function call overhead if you're handling lots of data.
from cgltf.
These are good ideas! Taking it a bit further, the API should perhaps take a range of indices, so that clients can either use them either way: one-at-a-time or a batch.
I also like the idea of providing a to-integer variant, which I had to write internally anyway in order to support sparse accessors.
from cgltf.
In my case the engine is already handling all of this, would it be possible to have this in a separate header, since it's not an essential functionality and thus would be a dead weight to some users?
It's not a problem with the existing cgltf_node_transform_world()
etc. APIs, but here I can imagine it could grow pretty large. Especially considering future glTF versions are expected to have more complex data packing options, use of half-floats etc.
from cgltf.
Agreed with @zeux, this isn't much code and it gets optimized out if you don't use it. In fact supporting sparse accessors isn't a big deal. I'm not quite ready to make a PR because I haven't tested it well yet, but feel free to take a sneak peak at 61b4060.
from cgltf.
@zeux, I've come around to your point of view regarding index vs range. Simplicity rules! The only thing I'm unsure about is whether to return individual components (as I've done in my initial implementation) or to return the entire element (e.g. all 9 floats of a mat3) into an output pointer.
I'm leaning towards an output pointer; this is especially useful for the three padded matrix types and it would still be a very simple API (same number of args as before).
from cgltf.
I agree that it would be more convenient to output a complete element. Otherwise it would get kind of weird how you’d have to skip indices to skip the padding.
from cgltf.
Related Issues (20)
- Validation errors are very generic HOT 1
- how do i access animations
- BigEndian support HOT 4
- Errors opening files > 2GB in size HOT 5
- Material AlphaCutoff triggers validator warnings HOT 1
- Typo in writer HOT 1
- Wide string support HOT 3
- cgltf_free uses file release callback for base64 buffers HOT 2
- cgltf_parse_file can crash with custom file_open, should not call memory_free HOT 6
- KHR_texture_transform: how to check existence of texCoord? HOT 3
- _ftelli64 does not compile on Windows when using zig cc (clang, mingw64) HOT 3
- Handling escaped json strings HOT 2
- Improved error output HOT 9
- cgltf_load_buffer_base64 returns cgltf_result_io_error for what seems to valid base64 HOT 1
- [Feature] add new KHR_mesh_quantization extension HOT 5
- cgltf_image::buffer_view::data is null HOT 2
- glb binary texture data HOT 4
- cgltf_write accessor is missing stride property HOT 1
- cgltf_write to buffer ignores options -> can't create an in-memory GLB
- write buffer_view should write TARGET
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cgltf.