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

Add KHR_draco_mesh_compression support to glTF Exporter #16064

Merged

Conversation

alexchuber
Copy link
Contributor

@alexchuber alexchuber commented Jan 14, 2025

This PR adds the ability to export to glTF using Draco encoding. Some notes:

KHR_draco_mesh_compression

  • Usage:
BABYLON.GLTF2Export.GLTFAsync(scene, "fileName", {  meshCompressionMethod: "Draco" });
  • Using Draco compression will increase export time, especially if the scene to export contains many unique meshes.
  • A primitive's vertex data + indices are either fully Draco-compressed or not. As such:
    • No uncompressed "fallback" data is exported if a primitive is Draco-compressed. This can be improved in future iterations.
    • KHR_draco_mesh_compression will be a required extension if any primitive in the glTF is successfully Draco-compressed
  • The encoder options used in the glTF exporter are defined as follows:
const DefaultEncoderOptions: IDracoEncoderOptions = {
    decodeSpeed: 5,
    encodeSpeed: 5,
    method: "MESH_EDGEBREAKER_ENCODING", // Or, if primitive contains morph targets, "MESH_SEQUENTIAL_ENCODING"
    quantizationBits: {
        POSITION: 14,
        NORMAL: 10,
        COLOR: 8,
        TEX_COORD: 12,
        GENERIC: 12,
    },
};

glTF Exporter

  • Creation of bufferViews and accessors are all done in the same way, through an intermediate class to help track relationships
  • Final binary buffer is no longer built on-the-go, but instead only once requested via generateBinaryAsync
  • Fixed glTF validation errors related to byte alignment, among other small buffer-related warnings

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 14, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 14, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 15, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 15, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 15, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jan 15, 2025

@alexchuber alexchuber requested a review from bghgary January 16, 2025 14:46
@alexchuber alexchuber marked this pull request as ready for review January 16, 2025 14:47
@bjsplat
Copy link
Collaborator

bjsplat commented Jan 18, 2025

Copy link
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments. Looks good otherwise.

@alexchuber alexchuber merged commit 0a83d19 into BabylonJS:master Jan 21, 2025
14 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.

3 participants