donmccurdy/glTF-Transform

Expose simplifyRatio to the optimize CLI

Closed this issue · 2 comments

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.

@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 -

// OPTIMIZE
program
.command('optimize', 'Optimize model by all available methods')
.help(
`
Optimize the model by all available methods. Combines many features of the
glTF Transform CLI into a single command for convenience and faster results.
For more control over the optimization process, consider running individual
commands or using the scripting API.
`.trim(),

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