• Projects
  • 3Dconnexion Space Mouse Support in Godot

Well, I got Mac to compile, but it's not good. My code works, but the system is doing all weird stuff. If you have the official 3Dconnexion drivers installed, then it takes over control and leaves the device open, meaning I am not able to connect to it. I'm not sure why this is, on Windows it works fine with multiple apps having access (just not at the same time). On Windows you can also disable specific apps or the whole driver itself. But on Mac there are limited options, it is very bare-bones compared to Windows, and people on the forum said the only way was to uninstall completely.

That would be fine, except without the official driver on Mac, the Space Mouse does some sort of mouse cursor emulation by default. So while I can connect to it via HID, and that works, it is also moving the mouse around, rotating the camera, zooming in, etc, wildly. And I'm not sure why that is. But even if I could disable it, most people that have devices like this are using them for 3D modeling work, so it would be too much to ask them to uninstall the driver just for a Godot plug-in.

So I don't know. I spent all day on this, but it's getting late to figure this out. At least Linux and Windows are fully working. I will have to see what I can do about Mac. I don't want to release unless it's cross-platform, especially since I know these devices are popular with designers that are likely on Mac. I saw there was some config XML file the driver uses, so I might be able to blacklist Godot. It's kind of a hack, but at least I have a lead.

Yes, well, I can't stand Apple or anything about their computers, but I'm not going to release an app unless it works on all platforms. I mean, if I really can't figure it out after a couple days we will see, but I don't like apps that are only on one OS, it seems rude to users.

@Kojack Do you have any experience with the Space Mouse on macOS? I am wondering if I am missing something or it's really this messed up. See 3 posts above. Thanks.

    cybereality
    Never even tried plugging a space mouse into a mac.

    Maybe try calling

    hid_darwin_set_open_exclusive(0);

    before opening the device. Apparently that was added to hidapi in march, after 3 years of people discussing problems with shared access to hid devices on macs.

    But that's just me with google, I avoid mac development. 🙂

    Thanks, @Kojack . That seemed promising, but was already in the code. I also tried setting it to 1, but it was the same. Will have to keep looking.

    I looked all on Github and I see what the issue is. The official driver on macOS (starting with Big Sur) opens the Space Mouse in exclusive mode, so there is nothing I can do to get access via HIDAPI after that point. This is unfortunate, but at least I know it's not a bug in my code. Maybe I will see if I can disable the mouse emulation so it will at least work if you uninstall the driver.

      cybereality
      Is there any kind of per app configuration on the mac connexion software?
      On windows, the app has that pic I posted above. The default for all non connexion aware software is the pitch axis is enabled and does mouse wheel emulation, everything else is disabled. You can turn it off manually if you get double input (HID and mousewheel).
      The app configurations are stored in xml files, so maybe you can make a godot config file that just turns everything off for godot. I have no idea where a mac would store those though (if they even exist on a mac). For windows, the files are at C:\Users\kojack\AppData\Roaming\3Dconnexion\3DxWare\Cfg\

      Edit: wait, no, you are talking about when the drivers aren't installed. Ignore all that.
      I guess macs are treating it as a generic HID device themselves and add default support.

      So, yes, I considered that. The Mac app is more limited, it's not like Windows where you can enable/disable axis and stuff. Even if you could, that doesn't help, cause the service starts at boot and attaches with exclusive access. So AFAIK there is no way to get it to work with the driver installed. I saw a few people with the same exact issue and there is no work around.

      That said, I was able to get it working without the driver. I just had to connect to it with exclusive access, and then that disables the mouse cursor emulation. I would have liked to get the driver working too, but for that I would need the official SDK and I don't feel like doing that at this point. One cause there are license concerns, and two I don't really feel like supporting their software with the way they treat non-Windows users. Also having to support two code paths in the library. Not worth my time.

      So it's all working and tested on Windows, Linux, and macOS, with both the new wireless model Space Mouse and the older Space Navigator. Those are the only formats, so, in theory, most of the other devices should work as well, but I'll have to get feedback as I don't have the hardware. I'm working on a video now, and the Github page, should be up in a few hours.

      Well, it kinda works. Most things being inverse and wayyyyy too sensitive. 😃

        Strange. I tested the old wired (same one I sent you) and the new wireless model, on Windows, Linux, and macOS. This was designed for Godot 3.4.4 but it should be compatible, I don't think the API changed. Can you list out the relevant specs of your machine (OS and version, Godot version, etc.)?

          Also, check Github again. I updated the Readme with some OS specific instructions.

          Megalomaniak Well, it kinda works. Most things being inverse and wayyyyy too sensitive.

          I also tested on 60Hz and 144Hz monitors, but since the update happens in Godot (in _process()) there may be some timing issues if you have a weird refresh rate. What kind of monitor do you have?

            @Megalomaniak If you're on Windows, you have to open the 3Dconnexion driver after you open the Godot editor. Then click the settings, it should show a popup for the godot-x86_64.exe. In there, uncheck everything, so that you don't get double control.

            cybereality Strange. I tested the old wired (same one I sent you) and the new wireless model, on Windows, Linux, and macOS. This was designed for Godot 3.4.4 but it should be compatible, I don't think the API changed. Can you list out the relevant specs of your machine (OS and version, Godot version, etc.)?

            I'm pretty sure it's just up to expectations and preferences. I tend to think in terms of moving and manipulating the camera rather than the object/world which causes everything to feel inverse to my brain. In other words: it's psychosomatic.

            edit: well, the sensitivity might be to do with my device being new and underused. Hasn't "worn in" yet perhaps so still overly sensitive.

              cybereality I also tested on 60Hz and 144Hz monitors, but since the update happens in Godot (in _process()) there may be some timing issues if you have a weird refresh rate. What kind of monitor do you have?

              75hz Freesync over HDMI and radeon chill is set to 'on', targeting 50 to 75 range in global profile. But godot reports pretty much a constant 75fps update anyways.

              Megalomaniak I'm pretty sure it's just up to expectations and preferences.

              I could see that. I've been using the Space Mouse off and on for like 15 years, so I am very comfortable with it. When I first got it it did seem very fast, but it's just sensitive. Also note that the focus/pivot is on the selected object (or the world origin, if nothing is selected). The movement will slow down as you get closer to the object.

              I tried to tweak it to get a balance where you could still control and get up close to something down to like 10cm but it would still feel okay up to like 10m. If you go too far out it will get fast, so if you have a large level you might have to click on an object closer to the camera.

              I wanted to add sliders to adjust the speed, but it doesn't look like you can export variables in editor plugins. My only option was to make a new dock, where I could attach settings. I might still want to do that, depending on the feedback I get. In the meantime, you can open the file addons/spacemouse/SpaceMouse.gd and look for these two variables.

              const translate_speed = 0.1
              const rotate_speed = 0.02

              Feel free to change them if you like (you will have to enable/disable the plugin to see the effect). Converting the code to fly the camera is probably a lot more work, but I can look into it. I might have to make that dock anyway, so if that's the case I can put in some other options.

                cybereality In the meantime, you can open the file addons/spacemouse/SpaceMouse.gd and look for these two variables.
                const translate_speed = 0.1
                const rotate_speed = 0.02
                Feel free to change them if you like (you will have to enable/disable the plugin to see the effect).

                I suspect trying to tighten those scalar values down would likely just run into floating point precision issues, but I guess I could try.

                cybereality I wanted to add sliders to adjust the speed, but it doesn't look like you can export variables in editor plugins. My only option was to make a new dock, where I could attach settings.

                I think in this case, just having a config.ini or just conf(no extension) file in a sort of plain text format would probably be fine.