-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support writing sparse accessors #351
Comments
Nice, this will be a neat feature, especially since the popular exporters don't support sparse encoding. We've seen several models with morphing that have lots of zeroes, they would be definitely be helped by sparse encoding. |
I'm thinking of several ways this could work — Current, before support for sparse arrays. accessor
.setType('SCALAR')
.setArray(new Float32Array([0, 0, 0, 0, 1, 0, 0])); 1. Boolean, supports only 0-filled base array. Full backward-compatibility — the array is kept unpacked in memory and can be read and modified by code normally. At export, the serializer generates sparse indices and values. accessor
.setType('SCALAR')
.setArray(new Float32Array([0, 0, 0, 0, 1, 0, 0]))
.setSparse(true); 2. Explicit indices and values, supports distinct base, indices, and values arrays. Breaking change, and adds some non-trivial complexity to all code that reads or writes accessor values. This is how glTF specification actually represents sparse data, and is how the data would be written into a serialized file at export in any case. accessor
.setType('SCALAR')
.setArray(null) // implicit 0-filled array. optional.
.setSparseIndices(new Uint32Array([4]))
.setSparseValues(new Float32Array([1])); 3. Explicit base, supports distinct base vs. final values. Breaking change, but more limited complexity for the rest of the codebase than (2). Code that reads accessor values can remain the same, but code that writes accessor values may need to update setSparseBase, e.g. to ensure the arrays remain equal in length. accessor
.setType('SCALAR')
.setArray(new Float32Array([0, 0, 0, 0, 1, 0, 0]))
.setSparse(true)
.setSparseBase(null); // implicit 0-filled array. optional. I might prefer (3), for a few reasons:
The one disadvantage I see is a higher memory footprint compared to (2). However, the common case using a zero-filled array retains the same memory footprint it has today, so no regression here. And because all engines I'm aware of will have to unpack this data before GPU upload anyway, I don't think supporting sparse data sizes that won't fit in memory is an important enough goal to complicate the 'normal' accessor API, which (2) would certainly do. |
FYI @hybridherbst, since you'd expressed an interest in #289. |
Work in progress toward (1), in: Probably won't keep going beyond (1) for now, but this could be extended to support (3) later. |
Sparse accessors are useful in certain cases, it may be helpful to have an API in
/core
for indicating which accessors should be written as sparse. Identifying candidate accessors could be left for user control or a helper in/functions
.The text was updated successfully, but these errors were encountered: