Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SpaceNavigator driver [OpenSource]

Discussion in 'Assets and Asset Store' started by PatHightree, May 15, 2013.

  1. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Ah, I see what you mean now.
    Can you try if this version does what you're after ?
    Just replace Assets\SpaceNavigator\Editor\SpaceNavigatorWindow.cs with this one: SpaceNavigatorWindow.cs

    Regarding the other point, would it work if I kept focusing on the position where the last selected object was?
     
  2. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hi Pat, I imported your new file and had Unity recompile the code but I don't see any difference in the behavior.

    And yes I think keeping the last rotation position would be a good way to handle deselecting all objects =)

    Edit:

    Actually it looks like I can no longer translate left-right and up-down...doing so results in rotating instead of translating.

    Edit 2:

    Looks like it also automatically frames whatever object was selected whenever any SpaceNavigator movement is initiated, which wouldn't be desired because it's jarring and one may not always want the object in the exact center of the screen.
     
    Last edited: Feb 14, 2014
  3. Angry-Gobbler

    Angry-Gobbler

    Joined:
    Dec 8, 2013
    Posts:
    4
    Hi Pat,

    Just tried out your driver and am really pleased with it, thanks a lot for a great job!

    Keep on the good work. :)

    Regards,
    John D Willimann
     
  4. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Wow, this is really exciting. I was looking for info on getting a 3Dconnexion mouse to work with Unity a few months ago but didn't find this thread.

    Now that I know we have a driver I'm going to pick up a SpaceNavigator in the next week!
     
  5. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Glad to hear that :)
    There's a small update coming up that adds 3 sensitivity presets for working in large environments.
    Its under review right now and should pop up on the asset store somewhere this week.
     
  6. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Just ordered it from Amazon. It should arrive next Friday.
     
  7. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Hi,
    I really like this asset! The only think that I would wish is a speed property in the flyaround.cs script (for translation and rotation). Right now I'm hacking it into every project over and over again. The settings for Sensitivity only work in the editor but they doesn't seem to change something in play mode. Or do I missing something?
     
  8. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Wanted to mention it´s working with the wireless navigator, too.
     
  9. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @sloopidoopi I decoupled editor and player sensitivity because you might want higher speeds when editing a large area, while the player would navigate at a more leisurely pace. Because I have no way of knowing what sensitivity(s) you would like to use in your actual game. So at the moment you are left the raw input values and you have to do the sensitivity scaling yourself.
    Please tell me if you have concrete ideas how to improve on this.

    @Cascho01 yep, it actually supports the whole range of 3dconnexion input devices. I just started developing it on a SpaceNav and didn't think too much about it. I like the fact that the name of the driver is the entry level device, it potentially lowers the threshold for new users.
     
  10. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Wonderful, also wanted to mention that your drivers work absolutely relyable.

    (There´s just a little problem, that may come from my scripts:
    Sometimes, when I leave the Unityprogramm and switch to another windows app (check mails) and return to Unity and start playmode my camera gets wrong input and performs a nice planecrash.
    After stopping and restarting playmode everything works fine again.
    Maybe you have an idea where this comes from? )
     
  11. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    I just hack a speed property into the script and multiply the current values:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class FlyAround : MonoBehaviour {
    4.     public bool HorizonLock = true;
    5.     public float speed;
    6.     public float rotSpeed;
    7.  
    8.     public void Update () {
    9.         transform.Translate(SpaceNavigator.Translation*speed, Space.Self);
    10.  
    11.         if (HorizonLock) {
    12.             // This method keeps the horizon horizontal at all times.
    13.             // Perform azimuth in world coordinates.
    14.             transform.Rotate(Vector3.up, SpaceNavigator.Rotation.Yaw() * Mathf.Rad2Deg * rotSpeed, Space.World);
    15.             // Perform pitch in local coordinates.
    16.             transform.Rotate(Vector3.right, SpaceNavigator.Rotation.Pitch() * Mathf.Rad2Deg * rotSpeed, Space.Self);
    17.         }
    18.         else {
    19.             transform.Rotate(SpaceNavigator.Rotation.eulerAngles * rotSpeed, Space.Self);
    20.         }
    21.     }
    22. }
    23.  
    (Perhaps speed is not the best name for the translation factor)
     
  12. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @sloopidoopi
    Yeah, that's what I mean.

    @Cascho01
    Sounds like values are being cached somewhere.
    To honest, I wrote the driver primarily for editor use, runtime support was kinda tagged on.
    So it hasn't had a lot of testing time.
    If you have a scene/recipe to reproduce every time, please let me know and I'll try to figure it out.
     
  13. panFX

    panFX

    Joined:
    Aug 18, 2014
    Posts:
    15
    Definitely a must-have! Works well with SpacePilot PRO.
    I tweaked the SpaceNavigatorWindow.cs to get the Orbit mode working with translation like my settings in 3DS MAX etc.

    Just changed:
    _camera.Translate(new Vector3(0, 0, translation.z), Space.Self);
    to
    _camera.Translate(translation, Space.Self);
    in private void Orbit (very easy, just copy from private void Fly above).
     
  14. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    My tracking info says it should arrive on Thursday. I'm excited to start working with it.
     
  15. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Well I got it today. And it's awesome! Thank you very much for putting this together.

    It's so nice that I'm thinking about getting a SpacePilot or SpaceMouse for my other dev machine.

    Have you made any progress with using the buttons to switch modes or assign commands?
     
  16. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    No sorry, no progress on the buttons.
    Don't know how to get them working, I need 3dconnexion to release some proper bindings.

    Happy flying :)
     
  17. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Thanks for the update.

    My fingers are crossed that Unity will give us native support in the 5.x release cycle.
     
  18. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    This is such a great tool. I've already ordered a second SpaceNavigator for my other dev machine.

    I'm working on a small code change to implement clamping (i.e., min/max values) for axes translation/rotation.

    If I can get it working, would you like me to send the code to you to incorporate into your driver?
     
  19. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Here's a screenshot of my updated Editor GUI including clamping for translation and rotation.

    Your code is well structured and easy to follow. It was not hard to see where to plug in the tweaks that I wanted.

    I still have some polish and testing to do but I should be done in a day or two. Let me know if you want me to post the updated scripts.
     

    Attached Files:

  20. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Glad to hear you're having a good time :)

    Please tell me, what does the clamping of the values add ?
    As far as I can tell, the sensitivity settings allow you to do pretty much the same thing.

    If you're familiar with github you can send me a pull request.
    Otherwise, just send it to p [dot] hogenboom [at] mcw [dot] nl.
    (I can't make any promises when I'll be able to look into it though)
     
  21. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    I agree that the sensitivity settings are a different way of dealing with the same issue.

    I'm still getting used to the 3D mouse and clamping has helped me by not letting me get too high or too low in a scene or rotate too far away from the area I'm trying to focus on.

    Maybe clamping won't be a benefit once I master the 3D mouse. I'm getting better with it pretty fast,.

    When I first tried the puzzle demo that comes with the Windows driver, I couldn't reliably move the pieces into the box.

    Now my problem is figuring out how to make them fit together.
     
  22. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hehehe, I think that puzzle is meant for experienced users.
    Its not the thing you want to start your training with...

    Experiment with sensitivity settings.
    I think once you've got them set up to your liking, you'll have a much easier time.
     
  23. Parallaxe

    Parallaxe

    Joined:
    Apr 9, 2013
    Posts:
    118
    Is Father Christmas already accepting wishes for Christmas? If yes, mine would be the Mac support of this indispensable little gem. Any time I have to switch to a Mac I dearly miss this gem (-;
     
  24. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Unfortunately my name is not Father Christmas...
    There's a bit of good news though, I will be getting myself a mac sometime soon(ish)
    That's a fairly important first step towards a mac version, don't you think?
     
  25. Parallaxe

    Parallaxe

    Joined:
    Apr 9, 2013
    Posts:
    118
    That news is so exciting that I have just tried to buy you a beer. But your barkeeper came up with some sort of error in Dutch around "opnieuw" and "verwerkt". Since I don't understand Dutch I'm not sure whether I did something wrong or if your barkeeper just wanted to sell me a vacuum cleaner (-;
     
    Last edited: Sep 19, 2014
  26. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Pat! You're here. I thought the project was abandoned! Were you able to address the concerns in my last post?

    Ideally I would like this driver to work like the way it does in Autodesk Maya. Have you used the spacenavigator in Maya? Works like a dream...

    Reminder of my last post:

     
  27. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    No not abandoned, it simply isn't the only hobby project I have ;)
    The Oculus Rift bumped it out of first place.
    Also, I am not an orbit user myself, and the feature was added at a later stage.
    So I'm not surprised that it has its niggles.
    I based the feature on another user's input and it sounds like you and him think differently about how it should work.
    When I get back to working on the project I'll check if Orbit is doing anything I didn't intend.
    But making it work differently is very low on my priority list.
     
  28. lightshape

    lightshape

    Joined:
    Oct 25, 2013
    Posts:
    3
    Hi Pat, very useful plugin, thanks!

    I guess reading the buttons is not supported now? If not, do you have an idea, how to get the button states anyhow into Unity?
    Perhaps by mapping the Spacenavigator buttons to the mouse and then query the mouse button states? Unfortunately the 3Dconnexion Driver seems to not support that.

    A while ago I used a VRPN-wrapper, but now I would like to have a simple direct solution, just for the Spacenavigator.

    Thanks
    klap
     
  29. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Sorry, if I knew how to get the button values into unity, I'd use them in the driver ;)
    I heard some time ago that the 3dconnexion developers were thinking about a new api, but haven't heard from them since.
     
  30. panFX

    panFX

    Joined:
    Aug 18, 2014
    Posts:
    15
    hi,

    since unity 4.5 the driver produces an error. every time you open a script in monodevelop, this message pops up (screenshot attached). if spacenavigator is completely removed from the project, the problem is gone...
     

    Attached Files:

  31. Astiolo

    Astiolo

    Joined:
    Dec 18, 2014
    Posts:
    27
    I am impressed with this driver, really should be something the Unity devs do themselves but it's great that someone else has put the effort in and isn't charging for it.

    However I am having a problem where I can't seem to get any rotation in the fly mode, while it seems to work fine in all other modes. There is also a less important issue with the zooming which I think is due to the fact that it is zooming the camera instead of moving it. I have always had issues with unity hiding objects close to the camera when I zoom in and so I have to move the camera back then zoom in again but now I also have the problem where if I zoom in too far the view turns around and starts zooming out (still moving the camera in the same direction). The zooming issue also makes the orbit mode quite annoying for me.
     
  32. Leirlux

    Leirlux

    Joined:
    Nov 4, 2014
    Posts:
    6
    Hi there team, you've done an awesome job by implementing this driver to Unity, but I have one question: are you able to make movements to a player that has FIRST PERSON MOVEMENT? Imagine as if it was going forward, backwards and to both sides (left & right). How can I do that? Thank's before-hand guys. Awesome job, better experience.
     
  33. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Sorry all for the long delay before replying, this project has been low on my prio-list...

    @panFX
    Sorry, but I can't reproduce the bug, when I import the package into a fresh project and open with monodevelop, I encounter no error message. You're not trying to open it on a mac, are you? Because mac is not supported.

    @Astiolo
    Thanks for the kind words :)
    It sounds like you ran into some sort of edge case, maybe it is something that happens after some of using the driver.
    If you still encounter it, could you try and find a way to reliably reproduce it?
    When I can reproduce a problem, I can try to find its cause and fix it.
    As a last thought, you didn't tick the lock-rotation checkbox by accident, did you ;) It is a setting that is only applied in fly mode.

    @Leirlux
    Thanks for the compliment, but there's only me (that's why there's not very frequent replies in this thread :p)
    Anyways, you can take a look at the FlyAround sample in the runtime samples folder, it allows a runtime camera to be moved with the driver. A very rough implementation would look something like this:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Bla : MonoBehaviour {
    4.     public void Update () {
    5.         transform.Translate(new Vector3(SpaceNavigator.Translation.x, 0, SpaceNavigator.Translation.z) , Space.Self);
    6.     }
    7. }
    For something more elegant, use this as input with the standard character controller.
     
  34. Leirlux

    Leirlux

    Joined:
    Nov 4, 2014
    Posts:
    6
    Thank you so much for the reply Pat, it works 100% on the "First Person controller" prefab. One last question and I stop disturbing you; you might be busy and I'm annoying, I know. :D

    I've been trying to implement that code on the OVR scripts and it doesn't work. What I've done is copy & paste that piece of code into the OVR Player Controller script (OVRGamepadController.cs & OVRPlayerController.cs) and it doesn't work.

    It would be amazing if you help with this last thing. Sorry again for the inconvenience, hope is everything ok around there ;)

    Best regards from Spain!!!
     
  35. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Add this to the bottom of the UpdateMovement() function in OVRPlayerController.cs

    Code (CSharp):
    1.         Vector3 rot = SpaceNavigator.Instance.GetRotation().eulerAngles;
    2.         rot.x = 0;
    3.         rot.z = 0;
    4.         transform.Rotate(rot, Space.Self);
    5.         Vector3 trans = SpaceNavigator.Instance.GetTranslation();
    6.         trans.y = 0;
    7.         transform.Translate(trans, Space.Self);
    I tested this by navigating over a flat surface, no idea what happens when you use this with obstacles.

    Ciao, Patrick
     

    Attached Files:

  36. SantiagoG

    SantiagoG

    Joined:
    Feb 17, 2014
    Posts:
    3
    Hi Patrick, I recently bought a 3d mouse and saw your plugin! First let me tell you that its awesome, it works well both on win and mac and as the rest of the group I too would like unity to make a native solution for using this mouse!

    I've been having some trouble with the response of the mouse. basically it keeps rotating or translating well after I release the mouse, even after I stop runtime. Do you have any pointers on this? Also, have you been able to compile a project and use the Space navigator outside Unity?

    Do you have any posts on the use of the Oculus rift!

    Thanks for your solutions! its a great start!!!!
     
  37. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Thanks for your enthusiasm :)
    I have seen this bug before, but I do not have a way to reproduce it.
    Does the problem always occur? Or only sometimes?
    Can you reproduce it on another computer?
    Does it happen in other software?
    Any information on how and when the problem occurs can help with finding its cause.
    I am currently rewriting the way the driver is integrated with Unity and this might have a positive effect on this bug.

    I post on the oculus dev forum under the same name.
    If you have any specific questions, feel free to PM me.
     
  38. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Good news, everyone!
    There's a new version of the SpaceNavigator driver available on the Asset Store and it has Mac support !

    Mac support took a very long time, let me explain what happened.
    I'm a PC coder by trade, but a couple of weeks ago I received a mail from somebody in Google's Project Tango team.
    Project Tango is creating on mobile devices with depth camera's, specially designed to do Augmented Reality.
    He told me that they are using the SpaceNavigator driver to emulate the motion of the Tango tablet when they work inside Unity :D
    And he asked me if I would be willing to do a Mac port of the driver, and were willing to compensate me for it.
    Well, the nerd in me couldn't resist asking for a Tango tablet, and they agreed :)
    A friend of mine (Dave Buchhoffer) had already made an attempt and shared his research with me.
    Another friend loaned me a Hackingtosh and off I went.

    [edit]
    Here's the little beauty
     
    Last edited: Apr 19, 2015
    sloopidoopi, schmosef and VIC20 like this.
  39. SantiagoG

    SantiagoG

    Joined:
    Feb 17, 2014
    Posts:
    3
    That is great news!! I upgraded the driver. I did a couple of test regarding the issue I told you and can now say that it happens every single time. It looks like its only on mac.

    So I did the test on a macbook air (2011) i5 and on a Asus Rog Republic of Gamer (2014). The issue occurs using the oculus rift and the space navigator. It only happens in the mac. Maybe its because of the computer specs? Don't know, but it does not happen on the windows. It looks like its only on the unity protect. I tried to reproduce the bug in other software and came out empty.

    I'll try to look further to find out more about this.
     
  40. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    One more quesiton: does the bug occur while editing or at runtime ?
     
  41. SantiagoG

    SantiagoG

    Joined:
    Feb 17, 2014
    Posts:
    3
    It only occurs at runtime, and at first I thought it might be related to low fps,but according to the stats I'm running over 15 fps. I also change the quality settings and tried at fastest as well as good!

    Maybe it has something to do with the fact that it only uses one axis at a time, the one with the most force applied to? In windswept actually uses all axis at the same time.

    In the editor everything runs smooth!!! :)
     
    Last edited: Apr 14, 2015
  42. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Ah, that's good to hear!
    The runtime part of the driver is definitely not as battle-tested as the editor part.
    If you're familiar with github, you can check out the project's develop branch.
    That contains the latest modifications in which the editorwindow is no longer responsible for the update loop.
    Please check it out, it might fix your bug.
     
  43. evolvingtech

    evolvingtech

    Joined:
    May 27, 2012
    Posts:
    14
    Excellent that you're coding this for the Mac and made it available. Any chance you may updated for Unity 5? I'm on ver. 5 of Unity for OS X. When I import the package, I get an alert that it's for 4.X, and converts it for 5.0. When I try the runtime samples, it spins wildly out of control. It reports: Non-convex MeshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0.

    (hopefully, its just a few tweaks at the coding level and it will be a wonderful experience).
     
    Last edited: Apr 18, 2015
  44. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Thanks for pointing that out !

    First of all, I want to make clear that the package is compatible with Unity 5.
    I'm just a tad lazy in that I don't want to maintain 2 separate packages on the asset store. I submit the package from Unity 4, so 4 is listed as the minimum compatible version.

    I reproduced the error in the Follow Curve demo scene.
    The error you are seeing is an asset problem in the demo itself, not a problem with the driver.
    The torus is non-convex and apparently that kind of collider isn't supported anymore.
    Runtime use of the driver works fine as far as I can tell, please see for yourself and test the Fly Around demo scene.
     
  45. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    Just want to say a huge thanks for adding Mac support!
     
  46. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @radimoto Thanks for the thanks :)

    @evolvingtech Fixed the demo, the fix will be in 1.4 which should come soon(tm)
     
  47. evolvingtech

    evolvingtech

    Joined:
    May 27, 2012
    Posts:
    14
    The demo works a lot better now. Thanks!

    Very much appreciated.
     
  48. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    I've run into an issue when building my project to IOS on 5.0.1p1. With SpaceNavigator installed I get the following error that prevents building the player:

    Cross compilation job TDx.TDxInput.dll failed.

    If I then restrict the dll TDx.TDxInput to the Editor only, it then fails to build with:

    Assets/SpaceNavigator/Plugins/SpaceNavigatorWindows.cs(3,7): error CS0246: The type or namespace name `TDx' could not be found. Are you missing a using directive or an assembly reference?
    Assets/SpaceNavigator/Plugins/SpaceNavigatorWindows.cs(34,26): error CS0246: The type or namespace name `Device' could not be found. Are you missing a using directive or an assembly reference?
    Assets/SpaceNavigator/Plugins/SpaceNavigatorWindows.cs(3,7): error CS0246: The type or namespace name `TDx' could not be found. Are you missing a using directive or an assembly reference?
     
  49. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Thanks for the bug report!
    Please report those errors people, since adding mac support and the release of Unity 5, I now have 4 different platforms that need testing. Its quite possible that there's more of these platform issues lurking around somewhere.

    Unfortunately, I have not been able to reproduce the bug with 5.0.1f1, targeting iOS.
    That dll is only used for under windows so (assuming you do your work on OSX only) you can delete SpaceNavigatorWindows.cs and comment out the error that will occur after that in SpaceNavigator.cs.
    I am changing the implementation to platform-conditional compilation, which will hide platform-specific code from platforms that it is not intended for.
     
  50. TomNCatz

    TomNCatz

    Joined:
    Jan 6, 2015
    Posts:
    24
    I have a new bug I don't see listed here.

    Unity 5.0.1f1 Personal
    Windows 8.1
    64 bit
    SpaceMouse Pro Wireless

    The bug is two fold. In editor I do not get support for tilting or turning left and right at all and tilting forwards and backwards has been replaced with a scrollwheel like zoom(unlike the slide fore and aft that you have integrated).

    When I hit run I get left and and right tilting back as well as turning, but foreword and back are still not there.

    It should be noted that with all of this when I do a build out it works fine.

    P.S. Your plugin rocks. I've used the SpaceMouse on a Mac and a windows machine in about 6 applications now and your integration is by far the most fluid and intuitive I have worked with so far.