f3d-app / f3d

Fast and minimalist 3D viewer.
https://f3d.app
BSD 3-Clause "New" or "Revised" License
2.71k stars 193 forks source link

Command line / Scripting interactions in a vim-like manner #595

Open mwestphal opened 1 year ago

mwestphal commented 1 year ago

Let user use small command to control F3D, based on the libf3d::options with a unified api, eg:

Of course, a libf3d API would need to be designed for this.

more discussions here: https://github.com/f3d-app/f3d/issues/535

mwestphal commented 9 months ago

So moving forward with this, here are my thoughts and a design proposal.

Introducing f3dCommand

f3dCommand will let user interact with f3d in a text based way and script certain f3d interactions. It is centered on a few standard commands:

set, inc, dec, toggle, print, alias

And a few specific commands:

exit, reset.

Standard commands takes a libf3d options as arguments. specific commands do not support arguments at all.

set

Usage: set option value

Set the value of option to value. No effect if value is incompatible with option.

inc/dec

Usage: inc option

print

Usage: print [option]

Print the value of an option, without option, print info about the scene (current ? binding)

alias

Usage: alias option value

Add an alias for option named value. value can then be used anywhere instead of option. All command-line long options will be provided as alias for the libf3d option counterpart by default in F3D application.

Note: We could extend the alias method and support not only option but any multi-word string but then separator and escaping characters will come into play. I'd rather avoid it unless we absolutely need it.

exit

Usage: exit

Stop the interactor and give back control to the applicative side

reset

Usage: reset

Reset the camera position to its default position (current "Enter" binding)

mwestphal commented 9 months ago

Notes from internal discussions:

@snoyer @Meakk remarked that we should plan for integration with imgui and autocompletion.

@snoyer suggested unset command, which would reset the value to default. @mwestphal suggested that reset option could be used for the same thing but in any case, it requires improvement to the options framework for implementation.

@Meakk suggested to separate between inc/dec and prev/next but it did not reach consensus and finally the idea was let down (I think?).

@snoyer suggested inverting the logic and avoiding separators (eg: fxaa_toggle) but it did not reach consensus).

mwestphal commented 9 months ago

Implementation tryouts:

A command class or namespace does not seem very usefull.

Simply adding a

interactor& interactor::command(const std::string& command) should be enough for the public API.

In terms of actual implementation, most of the logic will go in the interactor_impl class.

Regarding the imgui integration needs, (autocompletion, option listing), it will require improvements to the options class and be provided by the interaction_impl class. But it is not required in the first implementation.