• Projects
  • 3Dconnexion Space Mouse Support in Godot

That's why my input library has a rather odd collection of devices it supports, so far only things I directly own. 🙂

I do find the values are jittery when looking at them directly, but I've never noticed it when using them to control things.

A couple of other things to consider if you haven't already done so:
The range of the axes can vary, not just by model but individual device. The general range is considered to be -350 to 350, but for example my space pilot pro vertical axis has a range of around -410 (up) to 532 (down), but I have to push very hard on it to hit those extremes. The X axis is similar, left has a smaller range than right.
What I do is start with -350 to 350 as the min/max for each axis. If I get a larger value, I adjust the range to fit it. The returned values from my lib are then scaled to fit -1.0 to 1.0 to the current range.

Also making the axes nonlinear can be good. Put a power curve on it so small movements from centre have less effect. The official app only lets you change scale, mine has user specified power as well.

Here's my input test app where I reverse engineer these things. 🙂

Okay, cool. I think I see the issue. I have a command line app just printing values, and I see some odds one when barely moving the puck. Like it will be at 0 and then jump to 94 or some high number when I am only slightly touching it. So maybe my code is not correct, or there is some conversion issues. Because the numbers look fairly plausible most of the time but seem biased in one direction and then also extremely noisy at close to zero. It's getting late, though, I will investigate tomorrow. Thanks for the advice.

Pretty sure the windows driver & control software will run a calibration step on first launch, and it's not optional.

Yeah, i was considering that. I'll have to look at the code that is available and see if there is a way to calibrate if there are hardware irregularities.

Okay, I figured it out. It had nothing to do with the hardware or any of the HID code. It was just some bad matrix math in my GDScript plugin. How it ever worked in the first place is beyond me.

So I got the original Space Navigator wired to work, with the old 2 channel format. I also added an array for device/vendor IDs, right now it only has the 2 I own, but it's all dynamic so I just have to plugin the hex codes for the rest of the models and it should all work. Going to test one other thing tonight, but it's pretty much finished (at least on Linux). Tomorrow I will compile for macOS and Windows, which should just work since it's standard C code, but you know how that goes.

Got Windows compiled and it's perfect. Amazingly, I didn't have to modify the code at all. Standards for the win!

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.