donmccurdy / glTF-Transform

glTF 2.0 SDK for JavaScript and TypeScript, on Web and Node.js.
https://gltf-transform.dev
MIT License
1.43k stars 150 forks source link

Feature Request: Splitting a GLB File into Multiple Smaller GLB Files #1474

Closed CHENJIAMIAN closed 2 months ago

CHENJIAMIAN commented 4 months ago

Is your feature request related to a problem? Please describe. Currently, there is no straightforward way to split a large GLB file into multiple smaller GLB files. This can be problematic when dealing with large models that exceed the size limitations of certain platforms or when you need to manage complex scenes more efficiently.

Describe the solution you'd like I would like to see a feature implemented in the glTF-Transform tool that allows users to split a single GLB file into multiple smaller GLB files. This feature should:

  1. Automatically detect and separate meshes, textures, and other assets based on a specified size limit or user-defined criteria.
  2. Generate new GLB files for each separated component, ensuring that each file is a valid and standalone glTF model.
  3. Maintain the integrity and compatibility of the original model, ensuring that textures, materials, and animations are correctly mapped to their respective new GLB files.
  4. Provide options for users to specify the output directory and naming conventions for the generated GLB files.

Describe alternatives you've considered I have considered manually breaking down the model using 3D modeling software, but this is time-consuming and prone to errors. Additionally, I've looked into other glTF processing tools, but none seem to offer this specific functionality.

Additional context This feature would be particularly useful for developers working with large-scale virtual environments or game developers who need to optimize asset loading times. By splitting a large GLB file into smaller, more manageable pieces, developers can improve performance and reduce the load on client devices.

Moreover, this feature could potentially be integrated with existing optimization tools within the glTF-Transform suite, providing a comprehensive solution for managing and optimizing glTF assets.

I believe that this feature would greatly enhance the usability and flexibility of the glTF-Transform tool, making it an even more valuable resource for the glTF community.

CHENJIAMIAN commented 4 months ago

I saw the Divide glTF Document, but I want it wrapped into a command line.

donmccurdy commented 3 months ago

Hi @CHENJIAMIAN!

Splitting a GLB into multiple GLBs is certainly something that I'd like for users to be able to achieve with glTF Transform. The “specified size limit or user-defined criteria” is (I think) the difficulty here: there are many different ways to subdivide a scene, none obviously better than the rest.

The library does include functions intended to help — see copyToDocument and moveToDocument. Given a list of nodes, for example, these can transfer all dependencies of those nodes to a new glTF document, making it easier to create a valid output. But I haven't provided a complete function specifically for splitting a GLB; I think more specific requirements would be necessary to make that useful, and to avoid its becoming very complex.

If someone would like to propose a particular method (for example, divide 1 GLB into W x H x D GLBs according to a spatial grid) with a clear use case, I would be happy to review a PR or to advise on the implementation. In the meantime it is "self service", and would need to be implemented with the scripting API.

madjin commented 2 months ago

Currently, there is no straightforward way to split a large GLB file into multiple smaller GLB files.

But there is, it even uses gltf-transform under the hood: https://github.com/playkostudios/model-splitter