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

Expose simplifyRatio to the optimize CLI #1349

Closed jo-chemla closed 2 months ago

jo-chemla commented 2 months ago

Is your feature request related to a problem? Please describe. Using the gltf-transform optimize cli, exposing the simplifyError argument is useful to control the simplify operation amount. When using the simplify without prior weld yields to bad simplification results, where ratio is not correctly used - which is expected since the vertices are not weld'ed, which optimize chains under-the-hood.

Describe the solution you'd like It could be useful to also expose simplifyRatio as a CLI flag to the optimize command, so optimize command could be used as a single all-in-one operation to aim for a target simplification amount, constrained or not by error.

Describe alternatives you've considered A simple workaround as of today is to either run gltf-transform weld && gltf-transform simplify or gltf-transform optimize && gltf-transform simplify subsequently. Exposing the simplifyRatio to the optimize CLI would just be a nice-to-have.

Additional context Reference to the simplify doc:

ratio=0.0, error=0.0001: Aims for maximum simplification, constrained to 0.01% error.
ratio=0.5, error=0.0001: Aims for 50% simplification, constrained to 0.01% error.
ratio=0.5, error=1: Aims for 50% simplification, unconstrained by error.
donmccurdy commented 2 months ago

@jo-chemla This sounds like a good addition! Would you be up for making a PR? The bindings for the 'optimize' command are defined in packages/cli/src/cli.ts -

https://github.com/donmccurdy/glTF-Transform/blob/8a3a1302ab03c4cac5f8d156fd0c1d40db844bc6/packages/cli/src/cli.ts#L236-L245

jo-chemla commented 2 months ago

Thanks for the pointer! Just did a PR here: https://github.com/donmccurdy/glTF-Transform/pull/1354 Don't hesitate if anything is missing, I added both simplifyRatio and simplifyLockBorder arguments to the gltf-transform optimize CLI command.