f3d icon indicating copy to clipboard operation
f3d copied to clipboard

Provide interaction for external window

Open GitCodeBoy opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. I follow the test example to build a external widget/window inherit QOpenGLWindow in Qt.Use f3d.window.render() to draw the content.However, It doesn't interact with users the way Native types do,like handling mouse or keyboard event. It may be a good idea to provide interaction for external window. Enable External Windows to have similar functionality as native Windows.

GitCodeBoy avatar Sep 09 '22 02:09 GitCodeBoy

@Meakk do you think this is even doable ? Unless I'm mistaken the interaction layer would actually depend on the chosen lib providing the OpenGL context, at least it's how it is implemented for Qt in VTK.

mwestphal avatar Jan 23 '24 07:01 mwestphal

Hmmm, we could have an external interactor too so the user can just forward the mouse/keyboard events, what do you think?
Something like interactor.triggerMouseEvent(type, posX, posY, buttonHeld).
I don't know what would be the complexity for that, but I guess having the redesign an interactor can be annoying for libf3d developers.

Meakk avatar Jan 23 '24 09:01 Meakk

That would work I suppose. I wish we had an actual usecase first and I dont think @GitCodeBoy is still using the libf3d.

mwestphal avatar Jan 23 '24 14:01 mwestphal

Here is example for tkinter in Python. Idea is for quick mesh manipulation/prototyping using F3D viewer with its builtin properties.

LanPTR3D.zip

JPLost avatar May 26 '24 08:05 JPLost

Copy from Discord discussion https://discord.com/channels/1046005690809978911/1248564285328851015


So, I've been thinking of our current interactor logic and how it's pretty much unusable when using an "external" window. When using the external context, the event loop is managed externally so you cannot really do a interactor.start() . The main issue is the user has to reimplement all the interaction logic and handle the camera manually, which is a huge pain point. We've seen Nokse. reimplementing it, and I've also reimplemented it in Java for the Android implementation (spoiler: it doesn't work well) One solution for that would be to add public forwarder API to trigger events manually from the app. It could be something like that:

while (userEventLoop)
{
  switch(eventType)
  {
    case MOUSE_MOVE:
      engine.getInteractor().triggerMouseMove(event.mouse_dx, event.mouse_dy);
    case KEY_PRESS:
      engine.getInteractor().triggerKeyPress(event.modifiers, event.key);
    case FILE_DROP:
      engine.getInteractor().triggerFileDrop(path);
    case...
   }
   engine.getWindow().render();
}

The code above is basically what VTK is doing for native interactors at low level when we call start(). By doing that, the user handles the event loop, but F3D will handle all kind of interaction so all camera manipulations, key bindings and file drop come for free for the user.

Meakk avatar Jun 07 '24 09:06 Meakk

So in short we need to provide a dedicated API for this, so not breaking.

mwestphal avatar Jul 13 '24 15:07 mwestphal