Skip to content
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

gltfpack: Preserve custom ID attributes #568

Merged
merged 4 commits into from Jun 17, 2023
Merged

gltfpack: Preserve custom ID attributes #568

merged 4 commits into from Jun 17, 2023

Conversation

zeux
Copy link
Owner

@zeux zeux commented Jun 17, 2023

This change keeps attributes _ID, _BATCHID and _FEATURE_ID_* in tact when processing the scene. We assume that these attributes are scalar and encode them as floating-point (to avoid possible range issues with uint16).

This change is similar to #530 (without the extraneous names) but it crucially limits the supported attributes by name otherwise we can not assume that the attribute is scalar or integer, whereas with this filtering the assumption is reasonably safe.

For increased compression efficiency, when -cc is applied we use exponential encoding unless the IDs exceed the maximum permissible range. On some test files that use feature and vertex ids, this reduces the compressed size of ID attribute streams by ~2x.

Relates to #165
Fixes #529
Closes #530

zeux added 2 commits June 16, 2023 21:11
This change keeps attributes with _ID_ or _ID in the name in tact when
processing the scene. We assume that these attributes are scalar and
encode them as floating-point (to avoid possible range issues with uint16);
the filter doesn't seem to be necessary here although we could use an
exponential filter for slightly better compression in the future.
This results in ~2x smaller attribute streams so it is very worthwhile;
as with other compression filters, we only apply this when -cc is
specified.

The encoding assumes that the values are in 0..2^23-1 range; since input
values may be encoded as floats which permits a slightly wider range
(integers up to 2^24 are encoded exactly), we guard against this to
make sure no data loss occurs.
zeux added 2 commits June 16, 2023 21:14
It should be fine to use custom_name whenever it's specified; it is only
assigned for _custom attributes right now anyhow.
The previous search would not detect _BATCHID (Cesium 3D Tiles) as
valid, and would not detect some odd strings like _IDEAL_ID.

For now let's simply recognize the attributes that are known to be used
in the ecosystem as IDs; we can expand this list or replace it with a
different identification strategy in the future.
@zeux zeux merged commit ffed110 into master Jun 17, 2023
11 checks passed
@zeux zeux deleted the gltf-id branch June 17, 2023 22:09
@zeux zeux mentioned this pull request Jul 10, 2023
@petrbroz
Copy link

Btw. we've noticed that even though _FEATURE_ID_* attributes are preserved, the extension that uses these (EXT_mesh_features) is removed from the gltfpack output. Is that intentional?

@zeux
Copy link
Owner Author

zeux commented Oct 10, 2023

Yes, gltfpack must implement extensions for them to be preserved, as is common with other glTF processing tools. In case of EXT_mesh_features specifically, this extensions doesn't really exist yet in that it has been proposed (there's an open PR on glTF repository) but has not been merged or ratified, so I haven't looked into what it would take to support it.

@petrbroz
Copy link

Got it. Thanks @zeux!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gltfpack: Preserve custom vertex attributes during optimization
2 participants