tinygltf icon indicating copy to clipboard operation
tinygltf copied to clipboard

Reading GLTF data from model

Open koiava opened this issue 6 years ago • 7 comments

https://github.com/syoyo/tinygltf/blob/dac2a89b630fcb4c0e6131a048c0e3040588bd2c/examples/raytrace/gltf-loader.cc#L47

Somewhere here should be a code which translates data from model to meshes/materials/textures

right now it returns true but actually there is nothing in the output buffers. After that it crashed inside nanort when it calculates BoundingBox with 0 elements inside mesh(This looks like a separate issue).

How

Translate Model to output buffers or log message about TODO.

koiava avatar Dec 19 '17 09:12 koiava

Ah, I remembered raytrace example is still work-in-progress, so it won't work.

I have described the current status in README.

syoyo avatar Dec 19 '17 09:12 syoyo

I see. Still would be better to return appropriate message :) Shouldn't be too hard :)

koiava avatar Dec 19 '17 09:12 koiava

To implement raytracer for glTF model, we need scene graph data structure.

For the scene graph data structure, I have implemented nanosg: https://github.com/lighttransport/nanort/tree/master/examples/nanosg so you may use nanosg to convert glTF meshes into the scene hierarchy for the raytracer example.

syoyo avatar Dec 19 '17 09:12 syoyo

I see. Still would be better to return appropriate message :) Shouldn't be too hard :)

Changed to report error message :-)

syoyo avatar Dec 19 '17 09:12 syoyo

For reference, this is partially done in the PR #40 that has just been merged in. Implementation is still pretty rough at the moment. This will load all the meshes into a glTF files on the scene, but it doesn't attempt to load materials or to move theses meshes in the positions defined by the eventual "scene" inside the glTF file.

Ybalrid avatar Feb 27 '18 16:02 Ybalrid

gltfBuffer and gltfImage vector? why? I feel will Influence performance. But thanks to open source.

chenliming777 avatar Jun 08 '18 05:06 chenliming777

@chenliming777

Once memory is allocated, std::vector<T> has no performance impact over a regular array of T that was already allocated on the heap. So access to the data and traversal is as fast as it could be.

push_back(const T&) can trigger re-allocation of a larger array inside the vector. But this is only done while parsing the file and loading the data.

Once you are done with it (eg: loaded all useful data to the GPU) and you dispose of the tinygltf::Model object, all of this memory will be freed.

With this considerations in mind, I don't feel like there's a bad influence on performance from doing it this way.

Ybalrid avatar Jun 08 '18 08:06 Ybalrid