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

GLTF Serializer rework. #15869

Merged

Conversation

SergioRZMasson
Copy link
Contributor

@SergioRZMasson SergioRZMasson commented Nov 21, 2024

This PR changes fundamentally how the Babylon serializer to GLTF works. It changes the way the serializer handles left hand to right hand conversion.

Left hand to Right hand conversion

We no longer set mesh nodes with a negative scaling to handle left vs right hand conversion. We instead change every single vertex information when needed (normal, positions, and tangents) if the mesh was created in a left handed scene. We do the same for animation data and node transforms.

This should help decrease the file size of the exported glTF by removing the need for a root node to convert handedness, essentially reverting #13909.

Cameras and Lights

We now collapse cameras and lights with their transform nodes that are added by the Babylon importer. The goal is for the scene to be able to roundtrip without infinitely expanding.

Preserve vertex data

We now avoid as much as possible changing the type of vertex data. If the Babylon scene is holding vertex data using a particular type we will avoid at all cost converting it to float or to any other type. We might apply transformations to the data (such as left to right hand system conversion) but those modifications will be done in place, avoiding as much as possible creating a new buffer.

We also allow meshes that share the same geometry to point to the same accessors in the generated GLTF, se we no longer do any buffer duplication.

This should help significantly decrease some glTF file sizes on roundtrip, as we no longer make copies of buffers nor needlessly convert smaller buffer types to float buffers.

Forum issues

This PR also fixes a couple of bugs from the forum:

Wrong flipping of animated cameras
Inconsistent transform serialization
Instances exporting as separate meshes and #14056

SergioRZMasson and others added 3 commits December 3, 2024 14:34
Co-authored-by: Popov72 <github@evpopov.com>
Co-authored-by: Popov72 <github@evpopov.com>
Co-authored-by: Popov72 <github@evpopov.com>
@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2024

@SergioRZMasson SergioRZMasson marked this pull request as ready for review December 4, 2024 11:07
@SergioRZMasson SergioRZMasson merged commit 0beb409 into BabylonJS:master Dec 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants