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

Draft
wants to merge 130 commits into
base: master
Choose a base branch
from

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

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 25, 2024

Visualization tests for WebGL 1 have failed. If some tests failed because the snapshots do not match, the report can be found at

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/15869/merge/testResults/webgl1/index.html

If tests were successful afterwards, this report might not be available anymore.

packages/dev/serializers/src/glTF/2.0/glTFExporter.ts Outdated Show resolved Hide resolved
packages/dev/serializers/src/glTF/2.0/glTFUtilities.ts Outdated Show resolved Hide resolved
packages/dev/core/src/Buffers/buffer.ts Outdated Show resolved Hide resolved
packages/dev/core/src/Buffers/buffer.ts Outdated Show resolved Hide resolved
packages/dev/serializers/src/glTF/2.0/glTFExporter.ts Outdated Show resolved Hide resolved
packages/dev/serializers/src/glTF/2.0/glTFExporter.ts Outdated Show resolved Hide resolved
@sebavan sebavan enabled auto-merge (squash) November 26, 2024 17:17
@SergioRZMasson SergioRZMasson marked this pull request as draft November 26, 2024 17:40
@SergioRZMasson
Copy link
Contributor Author

I'm temporarily converting this back to draft since we are waiting on @ryantrem, the plan is to merge it next week.

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.

5 participants