Skip to content

fix: gltfio createInstance() overwrites shared morph target upload state#9915

Open
mp0rta wants to merge 2 commits intogoogle:mainfrom
mp0rta:fix/createinstance-morph-overwrite-v2
Open

fix: gltfio createInstance() overwrites shared morph target upload state#9915
mp0rta wants to merge 2 commits intogoogle:mainfrom
mp0rta:fix/createinstance-morph-overwrite-v2

Conversation

@mp0rta
Copy link
Copy Markdown

@mp0rta mp0rta commented Apr 18, 2026

fix #9914

Summary

Calling createInstance() on an asset with morph targets can overwrite morph-target upload state that is shared through MeshCache, causing ResourceLoader to upload morph position data to the wrong MorphTargetBuffer.
After a second instance is created, the primary instance can stop receiving the correct morph updates.

Fix

Detect whether morph setup has already been performed for the shared Primitive.

  • For the first instance, keep the existing behavior and populate the preallocated morph BufferSlots.
  • For additional instances, preserve the existing shared state and append new morph BufferSlots that point to the new instance's MorphTargetBuffer.

This fixes morph position uploads for the non-extended (ResourceInfo) path and prevents later createInstance() calls from breaking the primary instance.

Known Limitations

  • Morph tangents: computeTangents() still reads MorphTargetBuffer from the shared Primitive, so additional instances with lit morph targets may still get incorrect tangent frames. This patch only fixes morph position uploads.
  • ResourceInfoExtended: The extended loader path is not addressed by this patch. Supporting multi-instance morph targets there would require carrying per-instance CPU-side morph data (targetData.positions, targetData.tbn) into the upload stage.

Tests

  • VRM avatar with facial blend shapes + outline instance on Pixel 6a (Android 16, OpenGL ES)
  • createInstance() no longer breaks morph targets on the primary instance
  • Morph position data is uploaded to each instance's MorphTargetBuffer independently

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pixelflinger pixelflinger added the internal Issue/PR does not affect clients label Apr 20, 2026
@poweifeng poweifeng enabled auto-merge (squash) April 29, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createInstance() overwrites morph target buffers of the primary instance

3 participants