Closed syoyo closed 5 years ago
I was looking into this. It seems it's the recomended way of expressing morp animation targets within glTF. I'd like to load these from tiny_gltf.
Initial support would simply require to actually expose the "sparse" metadata there:
As I understand from khronos' spec:
I'm interested into adding this to the accessor class in tinygltf :
struct {
int count;
struct {
bool isSparse;
int byteOffset;
int bufferView;
int component_type; // a TINYGLTF_COMPONENT_TYPE_ value
} indices;
struct {
int bufferView;
int byteOffset;
} values;
} sparse;
And to add the code that fills these new data structure in the code that read the JSON, in case the "sparse" object is defined.
Using theses named anonymous structure, users will be able to get everything they need to read the updated array:
const auto& the_accessor = model.accessors[some_index];
if(the_accessor.sparse.isSparse)
{
//can access these members:
the_accessor.sparse.count; //how many I need
the_accessor.sparse.indices.bufferView; //where I find the indices
the_accessor.sparce.indices.componentVype; //type of the indices
the_accessor.sparce.indices.byteOffset; //where to start looking for indices
the_accessor.sparce.values.bufferView; //where to find the new values to patch-in
the_accessor.sparce.values.byteOffset; //where to start reading the new values
}
If I'm not mistaken, that's everything we need to do to make it possible to load a sparse accessor's data.
Good!
We need glTF files with sparse accessors for testing.
It looks there is only single glTF sample model in official glTF samples repo : https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/SimpleSparseAccessor
Yes, this file looks nice because it makes it obvious if it is working or not.
Will look at getting this in a bit later, tonight or tomorrow. It should be pretty easy to make. Will post here the obligatory screenshot of that sample file being loaded inside an updated version of the glview example 😉
I want to use tinygltf as a VRM avatar loader for some VR application I am interested in making. Humanoid avatars have facial animations, and they are done by deforming meshes with morph targets. (https://dwango.github.io/en/vrm/vrm_spec/#morph-target-information) And since morph targets are likely to be defined by sparse accessors (if they were not it would be a huge waste of disk space and bandwidth...) So for me, the sooner this is in tinygltf, the better... 😅
Debugging animations/skin/morph is hard. It would first better to find a tool like RenderDoc for inspecting glTF data.
Personally, I have started small&minimal glTF animation data inspect tool using tinygltf
https://github.com/syoyo/gltf-insight/tree/devel
its very early stage and has mostly nothing yet, but I'm planning to add feature for debugging/inspect animation data to it.
I'm going to take a look at your insight tool, that's a neat idea to have something to "dissect" the content of gltf files
Please review PR #150
It implements the changes described here, and update loader_example.cc and glview.cc so that they show the data changed by the sparse
element of accessors
I think you can close this issue now that #150 has been merged.
I think you can close this issue now that #150 has been merged.
Yes.
https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#sparse-accessors