Open mwestphal opened 1 year 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
option
is any of the libf3d optionvalue
is convertable-from-string value that will be converted to the correct type and passed to the optionSet the value of option
to value
. No effect if value
is incompatible with option
.
inc/dec
Usage: inc option
option
is a libf3d option that supports inc/dec
Increase/Decrease the value of option
. The actual change depends of the option, which will be documented by option. May have no effect on certains options.
Note: CycleScalars and such will be handled here.
toggle
Usage: toggle option
option
is a libf3d option that supports toggle (boolean)
Toggle the the value of a boolean option.
Note: toggle animation will be handled here and added as an option instead/in supplement of being a dedicated C++ call.
Usage: print [option]
option
is any of the libf3d optionPrint the value of an option, without option, print info about the scene (current ?
binding)
alias
Usage: alias option value
option
is any of the libf3d optionvalue
is a string alias to be used for the optionAdd 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)
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).
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.
Let user use small command to control F3D, based on the libf3d::options with a unified api, eg:
:render.effect.ssao toggle
:render.effect.ssao on
:render.effect.ssao off
:render.effect.ssao reset
It could also include specific action, eg:
:camera.fit
Of course, a libf3d API would need to be designed for this.
more discussions here: https://github.com/f3d-app/f3d/issues/535