feat: add VRM export to avatar preview#179
Closed
decentraland-bot wants to merge 10 commits into
Closed
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When wearables cover body parts, the base meshes are hidden via setEnabled(false). The Babylon GLTF exporter does not skip disabled meshes by default, so hidden body parts were being exported alongside wearable meshes causing visual artifacts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous isEnabled() check was too aggressive — it filtered out TransformNodes (skeleton bones) in addition to meshes, and checked the full ancestor chain. Now uses instanceof AbstractMesh to only filter actual mesh geometry, and isEnabled(false) to check only the node's own state without traversing ancestors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ones Each wearable container loads its own skeleton hierarchy. When exported to GLTF, wearable meshes reference their own duplicate bone nodes instead of the primary skeleton that the VRM humanoid mapping points to. This causes wearable meshes to appear at wrong positions or be invisible in VRM viewers. Remap all GLTF skin joints to reference the first occurrence of each bone name, unifying all meshes under a single skeleton. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Babylon GLTF exporter strips __root__ coordinate-conversion nodes and disables right-handed conversion for their descendants (bones). But center() reparents meshes under a different parent, so meshes still get coordinate-converted while bones don't. This puts them in different coordinate spaces, producing a 180-degree Y rotation on mesh geometry. Apply a compensating 180-degree Y rotation to the parent node in the GLTF JSON to re-align meshes with the bone coordinate space. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rdinate space The GLTF exporter strips __root__ nodes and disables coordinate conversion for their descendants. Since center() moves meshes out from under __root__ to a separate parent node, meshes got coordinate-converted but bones did not — causing the upside-down orientation. Reparenting parent under __root__ before export ensures uniform treatment of all nodes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tively The setParent(__root__) approach caused double Z-inversion: __root__ has scale (1,1,-1) for GLTF→Babylon conversion, and reparenting parent under it gave parent a compensating (1,1,-1) local scale. Combined with the serializer's own Z inversion, wearable meshes ended up in the wrong coordinate space. Fix: don't touch the hierarchy at all — just reset parent's full transform (including rotation) to identity and let the serializer handle handedness conversion on its own. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The GLTF exporter strips __root__ nodes (which have the loader's coordinate conversion scale) but computes IBMs against Babylon world transforms that include __root__'s Scale(-1,1,1). The exported GLTF joint transforms don't include this scale (since __root__ is stripped), so at bind pose skinMatrix = Scale(-1,1,1) instead of identity — causing inverted/deformed joints. Fix: after mergeSkeletons remaps joint indices, recompute IBMs as inverse(worldTransform(joint)) using the GLTF node hierarchy directly. This ensures skinMatrix = identity at bind pose, matching what unity-renderer's MeshFreezer.NormalizeSkinnedMesh does. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Babylon GLTF exporter applies right-handed coordinate conversion (Z-negation) to vertex data for meshes under 'parent' (not under __root__), but the vertex data was already in right-handed GLTF space. This caused the model to appear upside-down and deform during animation due to vertex/bone coordinate space mismatch. - undoVertexConversion: negates Z back in POSITION, NORMAL, TANGENT accessor data for skinned meshes - resetSkinnedMeshTransforms: removes compensating Scale(-1,1,1) from skinned mesh nodes (ignored per GLTF spec but safest as identity) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/babylon/export.ts: exports the composited Babylon.js scene as a VRM 0.x file by using@babylonjs/serializersGLTF2Export, then post-processing the GLB binary to inject theVRMextension with the humanoid bone mapping (DCLAvatar_*→ VRM humanoid spec)render()return value with anexportcontroller exposingexportVRM(), accessible both in-page and via the existing postMessage controller API@babylonjs/serializers ^4.2.2dependency (matches existing Babylon version)How it works
GLTF2Export.GLBAsync(scene)exports the composited scene (skipping social-emote duplicates and the centering helper mesh)humanoid.humanBonesentries built by matching GLTF node names against the canonical DCL→VRM bone mapping (sourced fromunity-renderer'sVRMBonesMapping.asset)Test plan
avatar.vrmdownloadsexport.exportVRM()via controller API returns an object URLRequested by Ignacio Mazzara via Slack
🤖 Generated with Claude Code