donmccurdy / glTF-Transform

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

Add Merge Materials #1244

Closed zhaoyuanmeng closed 5 months ago

zhaoyuanmeng commented 5 months ago

Optimize materials by finding and removing identical duplicates. If multiple materials have the same properties, only one will be kept.

zhaoyuanmeng commented 5 months ago

I have a very large bim5 data imported into glb data, because bim5 builds too many objects, causing the browser to load too slowly, want to achieve the same material batch operation to reduce draw call, thank you

donmccurdy commented 5 months ago

Hi! I think that the dedup() and join() functions will together do what you're after.

Examples:

import { dedup, flatten, join } from '@gltf-transform/functions';

await document.transform(
  dedup(),
  flatten(),
  join()
);
gltf-transform optimize input.glb output.glb --no-compress
zhaoyuanmeng commented 5 months ago

Thank you. I'll have a try!