PatHightree / SpaceNavigator

SpaceNavigator driver for Unity3D
MIT License
170 stars 55 forks source link

Rotation not working for SpaceNavigator Wireless in editor and playmode #31

Open JiapengChi opened 3 years ago

JiapengChi commented 3 years ago

Describe the bug Hi, I tried the Fly Around sample scene, but I noticed that I cannot rotate the camera or the target sphere. I printed the SpaceNavigatorHID.current.Rotation.ReadValue(), which was always (0.0, 0.0, 0.0). So was in the Input Debugger.

Did I do something wrong?

Desktop:

Thank you so much.

PatHightree commented 3 years ago

Is your device a SpaceNavigator or another variant ?

JiapengChi commented 3 years ago

@PatHightree Yes, I am using the 3DConnexion SpaceNavigator.

PatHightree commented 3 years ago

Can you rotate the camera in the sceneview ?

JiapengChi commented 3 years ago

@PatHightree Sorry, cannot do it. Unity cannot get any rotation vectors from the SpaceNavigator.

PatHightree commented 3 years ago

Maybe there is a hardware variation. Can you please install the Input Device Helper from the samples in the package manager. Run it via the Window/SpaceNavigator/Save all HID descriptors to files pull-down menu. Then attach the json file for the SpaceNavigator to this issue. Thanks.

JiapengChi commented 3 years ago

@PatHightree Here it is: https://www.dropbox.com/s/us3kru5fch6q50r/SpaceMouse.json?dl=0

Thanks!

BTW: Can this driver work with Spacemouse Enterprise?

PatHightree commented 3 years ago

Strange, this json file doesn't look like mine at all, even the vendorId and productId are different. Can you check whether this is the correct file ? Mine starts with "vendorId": 1133, "productId": 50726, Yours is "vendorId": 9583, "productId": 50739,

The driver might support the Spacemouse Enterprise as is, if it uses the same data layout as the SpaceNavigator. If it doesn't, please open a new issue and attach the corresponding json file and I will try to add support for it.

JiapengChi commented 3 years ago

Hi @PatHightree,

I have tried several different data formats to fetch the rotation, only QuaternionControl can get something with positive infinity and negative infinity. I guess they may change the data format for the rotation operations of SpaceMouse wireless and SpaceMouse Enterprise.

Do I need to start a new issue for that?

PatHightree commented 2 years ago

AH, you're using a wireless SpaceNavigator, that uses a different data layout than the wired version. On the other hand, I though I had already included support for the wireless version, so maybe I messed that up. I'll rename this issue to focus it on the SpaceNavigator Wireless. Please open another issue for the SpaceMouse Enterprise and include the corresponding json file. Thank you

P.S. I updated the issue template to include the device type and connection, thanks for that as well :)

unsetlay commented 2 years ago

Hi, I am using the SpaceMouse wireless and getting the same issue, too. I can not rotate the view using spacemouse wireless, should I open a new issue or provide some info to help?

JiapengChi commented 2 years ago

Hi @PatHightree ,

Actually, I am using SpaceMouse wireless with wire, but neither of the two scripts in the project can get the rotation data.

I will start a new issue.

Thanks!

PatHightree commented 2 years ago

@unsetlay Thanks, no further actions needed right now. G ood to know we have another SN Wireless available for testing a fix.

@JiapengChi The data format is device-specific, shouldn't matter if it's actually connected wired or wireless (afaik). I want to use one issue per hardware variation, so I'll use this one for the SN Wireless and the new one for the SM Enterprise.

loopervfx commented 2 years ago

@PatHightree I am also able to repro this issue with SpaceMouse Wireless P/N: 3DX-600044 PID: A4318303087 on Windows 10. I am happy to test when a fix is in the works.

As a workaround, if someone needs a live repo (not the old unitypackage) that you can at least have Scene View functionality for SpaceMouse using the 3DConnexion Driver on Windows, I am using this fork: https://github.com/Dinomite-Studios/space-mouse-unity. You must paste https://github.com/Dinomite-Studios/space-mouse-unity.git in the + Add package from git URL.. entry field.

JiapengChi commented 2 years ago

Hi @PatHightree ,

May I ask what kind of tool you use for reverse engineering of HID device events?

Thanks.

PatHightree commented 2 years ago

Just the Unity Input Debug window, the Unity forums and Google

jondowen commented 1 year ago

In case this is useful for anyone, I managed to get rotation working with my SpaceMouse Wireless when connected via USB cable.

// Registering the layout
InputSystem.RegisterLayout<SpaceNavigatorWirelessHID>(
    matches: new InputDeviceMatcher()
        .WithInterface("HID")
        .WithManufacturer("3Dconnexion.*")
        .WithCapability("productId", 0xc62e));      // SpaceMouse Wireless (cabled)
        //.WithCapability("productId", 0xC652));    // 3DConnexion Universal Receiver

I then found that yaw and roll were swapped, so swapping the offsets for these in SpaceNavigatorWirelessHIDState.ReportFormat1 (like in SpaceNavigatorHIDState.ReportFormat2) got this working properly too:

// 1st report
[InputControl(name = "translation", format = "VC3S", layout = "Vector3", displayName = "Translation")] 
[InputControl(name = "translation/x", offset = 0, format = "SHRT", parameters = "scale=true, scaleFactor=10")] 
[InputControl(name = "translation/y", offset = 4, format = "SHRT", parameters = "scale=true, scaleFactor=-10")]
[InputControl(name = "translation/z", offset = 2, format = "SHRT", parameters = "scale=true, scaleFactor=-10")]
[InputControl(name = "rotation", format = "VC3S", layout = "Vector3", displayName = "Rotation")] 
[InputControl(name = "rotation/x", offset = 6, format = "SHRT", parameters = "scale=true, scaleFactor=-80")] 
[InputControl(name = "rotation/y", offset = 10, format = "SHRT", parameters = "scale=true, scaleFactor=80")] 
[InputControl(name = "rotation/z", offset = 8, format = "SHRT", parameters = "scale=true, scaleFactor=80")]
public ReportFormat1 report1;

Versions: Unity 2022.1.24f1 3DConnexion 10.8.11

No joy getting the Universal Receiver working, but I guess that's issue #50.

FejZa commented 1 year ago

Thanks a lot @jondowen. This works great in editor and play mode. But in a windows standalone player build rotation does not work, just translation unfortunately. Any chance you solved that as well?

sagarpatel commented 6 months ago

Thanks @jondowen , this works great on my end too. I was getting the same problem as @FejZa in a windows standalone build, thankfully this fix mentioned on this page seems to work: https://github.com/PatHightree/SpaceNavigator/issues/38

Recap: both translation and rotation working in Play mode as well as Windows Standalone build using Unity 2023.1.15f1