jupyter-widgets / pythreejs

A Jupyter - Three.js bridge
https://pythreejs.readthedocs.io
Other
936 stars 185 forks source link

Possibility for spacemouse support #305

Open Krande opened 4 years ago

Krande commented 4 years ago

Hi,

Something I have been looking into is how to make use of my spacemouse navigator in pythreejs to rotate and move 3d objects (like I am able to do in Abaqus, Freecad, Blender, etc..).

I found a github repo (https://github.com/archilogic-com/aframe-space-navigator-controls) that I believe is related to what I am looking for (assuming somehow the three.js implementation is transferable to pythreejs). At the same time as I attempt to make this work on my own, I thought I could check if anyone else have some experience with the this, or have some thoughts on how this might actually be implemented?

Kind Regards Kristoffer

jasongrout commented 4 years ago

It looks like that library hooks the mouse up to the browser with the gamepad api. ipywidgets has a separate gamepad api controller. I'm imagining that you could hook the mouse up to the computer, use the ipywidgets gamepad widget to read values off of the mouse and push them to python, then hook up those values in python (with the widgets link function) to whatever parameters you wanted in pythreejs. Very similar to how the flight simulator demo works: https://github.com/jovyan/jupyter-flight-simulator

CC @SylvainCorlay

Krande commented 4 years ago

Thanks for the quick reply!

I just started looking into the gamepad api and I came across this in the docs.

using

import ipywidgets

ipywidgets.Controller(
    index=0,
)

resulted in the ouput "Connect gamepad and press any button." which I tried, but nothing happened when I pushed any of the spacemouse buttons.

I also looked into some of the similar issues raised, such as #1206, and tried to use some of the proposed code examples there, but alas, the end result was the same (i.e. no observable response).

I tried using a ps4 controller and that worked perfectly fine. So could the problem be that the spacemouse is registered in Windows as something else than a regular game controller?

FYI: I am using windows 10 and Firefox browser.

Additional sidenote: I am noticing that moving the spacemouse back and forth actually moves the camera forwards and backwards as intended using pythreejs. The goal is to find a way to activate all axes!