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: Implement mesh instancing #142

Merged
merged 11 commits into from
May 13, 2020
Merged

gltfpack: Implement mesh instancing #142

merged 11 commits into from
May 13, 2020

Conversation

zeux
Copy link
Owner

@zeux zeux commented May 12, 2020

This change reworks the gltfpack mesh processing pipeline to be instancing-friendly: instead of duplicating all mesh instances during parsing, we keep the instance data if possible throughout the pipeline.

By default gltfpack no longer merges multiple instances of the same mesh together; this behavior can be changed using -mm command-line switch (which usually generates fewer draw calls for scenes with duplicate geometry, at the expense of using more memory).

This change also implements experimental support for EXT_mesh_gpu_instancing, which can be activated using -mi switch. The instance data is saved in the same format as animation keyframes, which doesn't fully match the current spec draft.

zeux added 11 commits May 11, 2020 21:18
Instead of an optional node pointer we now have an array of nodes.

When merging, the rule is that the node arrays must be pairwise
compatible with each other wrt transforms. This hopefully will maintain
mergeability for common cases without requiring splitting mesh sets.

The rest of the code is adjusted in a trivial manner; when writing node
attachments, we need to write a new quantization node for each target
node because a node can only have one parent.
mm (mesh merge) will be used to restore the behavior where many
instances of the same mesh can get merged in world space.

mi (mesh instance) will be used to implement instancing extension.
Instead of duplicating meshes during parsing, we now parse all meshes[]
elements, fill them with node references and discard empty meshes.

This allows us to implement proper instancing export and is much more
memory efficient on large inputs.
This allows us to confirm that the scene complexity doesn't change
significantly during packing.
When -mm is specified, we merge individual instances of the same mesh
together. This can only be done when no instance is attached to an
animated node.
This is a copy of mrdoob/three.js#18913, using
the inline quaternionFromBufferAttribute since it will need to be
changed to support quantized inputs.
This adds all the necessary infrastructure with statistics and data
structure changes to implement mesh instancing.
We decompose each node's transform into T/R/S and compress them
individually using the same format and settings we use for animation
data.

Note that we are explicitly disabling cross-mesh merging in presence of
instancing - in theory it's possible to use it but it doesn't seem like
it's very important to do so...
Quantization offset needs to be applied in the instance local space.
Right now this is inconsequential since we don't allow merging meshes
with instances, but this may change in the future.

Also clang-format.
Supporting normalized rotations as an input and removed clone to fix
quantized inputs.
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.

None yet

1 participant