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
    Warning : runtime navigation does not work in Unity 2018 and up !

    New:
    - Navigation at runtime
    - Fixed drift on Mac

    SpaceNavigator driver for Unity3D

    This driver lets you fly around your scene in the editor and allows you to move stuff around.
    You can also use it at runtime via scripting.
    Actually, the driver should work for all 3dconnexion products, but I've only been able to test it on the SpaceNavigator.

    It has 4 modes: Fly, Orbit, Telekinesis and GrabMove
    The default mode is Fly mode and when you're flying around, this driver always keeps your horizon horizontal.
    So you don't have to worry about ending up upside down, just go where you want and get some work done.
    In Orbit mode you orbit the current selection.
    To move stuff around, you can use 2 modes: Telekinesis and GrabMove.
    In Telekinesis mode, you can move the stuff you selected with the SpaceNavigator, while your camera stays put.
    (this mode can be operated in Camera-, World-, Parent- and Local coordinates)
    In GrabMove mode the stuff will be linked to your camera so you can take it with you and position it where you want.
    Translation can be snapped to a grid.
    Rotation can be angle-snapped.

    Platform support
    As of version 1.3, this driver supports both PC and Mac.
    The driver supports both Unity Personal and Pro versions.
    Caveat: when running Unity 4 and lower on Mac you need the Pro version because Free did not allow plugins.

    The goods
    • The full package is available on the Unity asset store
    • The package also contains a couple of runtime samples:
      - Fly around.unity: Fly around with a sphere while knocking over some cubes.
      - Folow curve.unity: Make your torus follow the curve, but don't touch it!
    • The source code is available on Github
    Known bugs and limitations
    • Grab Mode only works in the camera coordinate system (sorry, I couldn't get my head around the quaternion math of manipulating in one coordinate system while constraining in another)
    Installation
    • Install 3DConnexion driver and make sure it is running
      (avoid version 10.4.4, that one's broken)
    • Import the unitypackage into your project
    • Open the SpaceNavigator window from the pull-down menu Window/SpaceNavigator (or hit Alt-S)
    • Fly away
    Upgrading
    • When installing a newer version of the plugin, please follow these steps:
    • Close the SpaceNavigator editor window.
    • Delete the SpaceNavigator folder from your project.
    • Delete Plugins\3DConnexionWrapperU4.bundle from your project.
    • Import the new package.
    • Reopen the SpaceNavigator window (Alt-S).
    If you delete the folder while the SpaceNavigator window is still open, Unity will throw some errors.
    When this happens, choose the default layout from the layout dropdown in the top right of Unity's UI and everything should return to normal.

    Pro tip
    Copy the SpaceNavigator unitypackage to Unity/Editor/Standard Packages directory.
    SpaceNavigator is added to the packages list in the project creation in wizard.
    Easy to add later by right-clicking in Project View and choosing Import Package.

    Credits
    • Enrico Tuttobene for contributing the fix for the drifting on Mac.
    • Big thanks to Chase Cobb for motivating me to implement the Mac version.
    • Thanks to Manuela Maier and Dave Buchhoffer (@vsaitoo) for testing and development feedback.
    • Thanks to Ewoud Wijma for loaning me the Hackingtosh for building the Mac port.
    • Quaternion math by Minahito http://sunday-lab.blogspot.nl/2008/04/get-pitch-yaw-roll-from-quaternion.html
    Older versions
    The Unity asset store does not provide older versions of packages, so I collected the older releases that I could find on this page: https://drive.google.com/open?id=0B7oiMnqjvbOJM0NCQ0JvellGT1E
     
    Last edited: Mar 4, 2020
  2. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Good job Patrick! Glad to see this finally up here :D

    Cheers
     
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Very nice package, thank you for providing this :) Can I put a request in to have an orbit object mode so we can rotate around the selected object, and could the right button be used to switch modes?
     
  4. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @SteveB
    Thanks man, its been a long time coming indeed.

    @SpookyCat
    Orbiting wouldn't make any sense in Telekinesis and GrabMove modes, so I added the option for orbiting only when in Fly mode.
    Unfortunately I don't know how to detect a right-mouse click, do you ?
    The modifications were made in the development branch.
    If you don't want to check out the repo, here's a unitypackage.
     
    Last edited: May 16, 2013
  5. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    That was quick :) Thanks for adding the orbit mode. Trying to download now but getting time out errors for the link, will try later.
     
  6. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    My bad, a typo in the url.
    Give it another go.
     
  7. bilke

    bilke

    Joined:
    Jul 13, 2012
    Posts:
    54
    Thanks a lot for sharing! I will try to get it working on a Mac and I will let you know how it turns out.
     
  8. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Awesome, good luck !
     
  9. Batigol

    Batigol

    Joined:
    Oct 17, 2012
    Posts:
    234
    Great works PatHightree!
    About right click, Did you try it this code?
    device.Keyboard.IsKeyDown(1)
     
  10. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Ah thanks.
    No I didn't try that one, I tried Input.GetMouseDown and Tools.viewTool.
     
  11. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    <RI.Hid> Device is not supported: ET-0405-UV1.1-1 (0013, 0x0001).

    Windows 7 unity 4.13 it works in the s3dm viewer that comes with 3d connexion, I also have a unity 'profile', don't remember it ever working in Unity.
     
  12. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    I deleted the profile, now I'm just getting zoom in and out in unity, do I need to mess with the profile?
     
  13. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    Oh, it only works in 1 scene view, in Fly mode the horizon is spinning. Are there settings for 'rotate around selected object'?
     
  14. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @SpookyCat Batigol
    I tried to get the right button of the SpaceNavigator to toggle orbit mode, but for some reason the keyboard class' IsKeyDown method will never return true.
    I added a feature branch for this.
    Bagitol, have you had SpaceNavigator buttons working in your experiments ?

    @Hike1
    Glad to hear you got it working in the end :)
    I started the project to do navigation and I've implemented that to work in camera space, so that only makes sense in one viewport.
    I've seen the horizon get crazy once, if you see it again, please try and reproduce the problem and describe it as clearly as possible. If I can reproduce it, I'll be halfway there towards fixing it (hopefully).
    Orbit mode was hacked in quickly at SpookyCat's request, no options were added in the process. What settings are you missing ?
     
    Last edited: May 29, 2013
  15. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
  16. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Have you made any progress? Been wanting to get a SpaceNavigator but the Unity support has been lacking. Would love to be able to support it at runtime, too. I've never written a device driver so I'm not sure what's involved in getting it to work on mac.
     
    Last edited: Jul 20, 2013
  17. akabane

    akabane

    Joined:
    Apr 26, 2007
    Posts:
    143
    Hi Pat!

    First of all thanks a lot for this driver - really helpful!
    A question though: I'm having a problem that after trying it at runtime. Basically I start Unity, press play, my player can move with the SpaceNav.. I press Stop. When I press play again, my spacenav doesn't work anymore. It doesn't give any error or warnings( ie device disconnected). Any clue? Maybe after instancing a spacenav once, it can't get reinitiated when the service has stopped?
    The only way for now is closing and reopening Unity...if you could help with that I'd be glad! Thanks :)

    @JTown: to get it to work at runtime, just call the SpaceNavigator class in your script to access its properties (i.e.: SpaceNavigator.Translation, SpaceNavigator.Rotation etc...)
     
  18. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hey Akabane,
    thanks for your interest in the driver and for reporting a bug!
    I should have done a better job at testing runtime support...
    I'll have a look at it asap and report back.

    At the moment I'm working on getting the driver to work without the need of having the editor window open.
    This requires some restructuring, and (re)initialization is an important part of that.
    I'll take your bug into account while developing and testing the new version.
    So if I can't do a quick fix, it will be addressed properly in the next version for sure.
     
  19. akabane

    akabane

    Joined:
    Apr 26, 2007
    Posts:
    143
    Thanks a lot!
    I noticed the problem disappears if I keep the editor window open at all times, even at runtime. Still haven't had the courage to try and do a build :p

    Can't wait for the fix/next version then! Any pointer on when you think it'll be available? :)
    Cheers

    EDIT: Additionally, even if I saw it's something you were playing around with, is there any known way to make it recognize the hardware buttons on the spacenav? I'm trying to modify the script to include sensor keyboard input, I'll update if I can get anywhere...

    EDIT2: Looks like the keyboard handling goes through an eventHandle in TDxInput.dll, so I can't directly access the button presses - I'll try to snatch up code here and there to see if I can patch something up...

     
    Last edited: Aug 16, 2013
  20. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    Good Job PatHightree!But How use Left Or Right 3d Mouse Button ,Very Thanks!
     
  21. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hi LostPanda,
    Short answer:
    Currently the device buttons aren't working, it's on my todo list though.

    Longer answer:
    The Unity driver communicates with the windows driver. but not quite in the way that it was designed to do.
    This is because the default way uses COM, which isn't supported in mono.
    Therefore I am polling the device for changes, for some reason this didn't work for the buttons last time I tried.
    I've heard that a new iteration of the windows driver is upcoming, so this might have an effect on whether the device buttons work in my driver.
     
  22. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Well this is awesome, 3DConnexion sent me a thank-you SpaceMouse Pro for writing this driver :D

    $IMG_1015.JPG
     
    TristinNewby, Climber-fx and Xmblpb like this.
  23. Batigol

    Batigol

    Joined:
    Oct 17, 2012
    Posts:
    234
    great, you are deserve to receive it :)
     
  24. Scott-Curtin

    Scott-Curtin

    Joined:
    Mar 19, 2013
    Posts:
    14
    This is a great addition- thanks so much!

    Is the version with orbit-around-object the one that's on the asset store? The asset store version is what I have, but I am not seeing the option... tried the link you mentioned above, but seems broken still.

    Orbit around object is one of the most useful features in my experience.
    ... but thanks for what is already there and for making it free!

    Cheers man.
     
  25. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    lol I like how there is an oculus in the background of that photo - this is probably the first instance of it being "just that thing in the background" rather than "ZOMG a RIFT everyone look at it!"
     
  26. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,748
    Any chance the version in the asset store could include the rotate around object mode, I tried importing the dev branch but got errors in latest Unity.
     
  27. Tony-West

    Tony-West

    Joined:
    Dec 8, 2012
    Posts:
    49
    Great tool, thank you making navigating unity much easier. The orbit object mode would be a nice addition. I would also like to request the option to be able to reverse inputs for telekinesis and grab modes. I have my fly mode setup how I like in max but when I switch to the other 2 modes the directions are the opposite of what I would expect them to be (when I push right the object goes left). Does that make sense?

    Anyway thanks again. Now I need to get it working in runtime mode as well (think I will get my brother on that).
     
  28. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Thanks for developing sharing!

    Any news on Mac compatibility?
     
  29. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    The way the space navigator typically works in most 3D programs (such as Maya, 3D-Coat, Blender, etc) is to orbit around whatever the camera is pointing at.

    Unity also exhibits the "orbiting" kind of camera behavior if you change your Unity editor view to ISO (isometric instead of perspective PERSP) and then right click and move your mouse around. It would be nice to have that kind of orbiting behavior as an option for this asset instead of only having flying-around behavior.

    That way I could use the space navigator in other 3D programs such as Maya or Blender and then seamlessly have the same behavior in Unity. I would be willing to pay for such a modification.

    I paid the 3DThrough app long ago which has my desired functionality but it's no longer working correctly and doesn't seem to be supported. Another similar app costs $70 I believe, and is not worth it for me to pay that much. Anyway, thank you
     
  30. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Ok, so it seems the orbit mode really needs some love.
    I'll give it a whirl during the holidays.
    Adding the feature isn't really a problem, but making it play nice with the other features is...
     
  31. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Cool, thanks so much. This would make Unity perfect =)
     
  32. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    This has been a productive holiday, I've just submitted version 1.1 for asset store review.
    1.1 contains the following new features :
    - Added Orbit mode.
    - Horizon locking can be toggled.
    - Axes can be inverted (for each operation mode separately).

    For those of you who don't want to wait, you can get the packages via the links on the github page.

    Unfortunately there's no news on the mac front.
    There were a couple of people who expressed interest, but I haven't heard back after that.
     
  33. GeneBox

    GeneBox

    Joined:
    Nov 15, 2012
    Posts:
    480
    Great stuff but too bad it doesn't have Mac support yet. Do you think you'll work on that at some point?
     
  34. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    +1 for Mac Support
     
  35. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Sorry, but I'm a windows developer, and while I have some experience shipping iOS unity projects, OSX plugin development is not my turf.
    My focus for this project lies with getting the current version more stable and robust.
     
  36. GeneBox

    GeneBox

    Joined:
    Nov 15, 2012
    Posts:
    480
    That is just too bad. I got that sweet piece of hardware today and while it's "usable", at the very best, in Unity it's just doesn't feel as good as, say, if I were using it in Blender.
     
  37. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hehehe, I feel your pain, that's what motivated me to write this driver in the first place ;)
     
  38. Moohasha

    Moohasha

    Joined:
    Jul 8, 2013
    Posts:
    10
    Thanks for writing this plug-in (and congrats on the free SpaceNavigator!) It works great in a 3D scene, but I'm having some problems in a 2D scene. I can only get the camera to pan, but not zoom in/out. Is this something you have looked into with the new 2D features in Unity 4.3?

    @Edit Also, the locks in Fly mode don't appear to work. I tried locking Rotation so that I could only translate, and it still rotates the camera. If the locks worked, I think I'd have a little more success in 2D.
     
    Last edited: Jan 13, 2014
  39. MrShanePaul

    MrShanePaul

    Joined:
    Nov 16, 2013
    Posts:
    1
    That is awesome. You deserve it. :)

    Thought a driver was going to cost me $70 on top of the device (which I got new at less than half price - thank you unwanted xmas presents!) which I can't really afford at the moment so you have my genuine gratitude. :p
     
  40. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    @Moohasha: I haven't looked at 2D yet, but in retrospect I'm not surprised that zooming doesn't work.
    Translation of the SpaceNavigator is applied as translation on the camera, which does exactly zero when going forward in an ortographic viewport. I'll have a look at it.

    Thanks for the spot, locking is indeed not working in Fly mode.
    Hmm, I did that by design because I thought the freedom of flying shouldn't be limited.
    Looking at it now I'm thinking that if you check the locks, you want it limited so I shouldn't interfere with that.
    Gonna remove that limitation in the next version.

    @Mr Magoo: Thanks for the kind words
     
    Last edited: Jan 15, 2014
  41. worldofvrgmbh

    worldofvrgmbh

    Joined:
    Jan 27, 2014
    Posts:
    3
    I'm trying to use your driver for interaction with a Rift ... it works already, so thank you so much for your great work! :)

    Are there any news concerning the button clicks or is there any work-around? Right now I'm pressing down the y-axis to open a menu, but the real buttons would be awesome! :)
     
  42. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hi there, fellow Rifter :)
    What are you making ???

    Great to hear you like the driver, unfortunately I haven't made any progress on the button situation and that's not likely to change soon.
    The reason for this is that the driver works by polling the 3dconnexion driver status, instead of 3dconnexion's sample code.
    I'm using to this method because the sample code uses COM which isn't supported in Mono.
    For some reason the translation and rotation data comes through fine, but the button state and device online/offline status does not.
    So until I figure out another way of communicating with the 3dconnexion driver, I'm out of options.
     
  43. akabane

    akabane

    Joined:
    Apr 26, 2007
    Posts:
    143
    Eheheh hi there! Doing exactly the same at the moment...tried to find a way but encountered the same problems Pat had :(

    Anyway great to know some Rifters are using 3d mouses for navigation...awesome tool ;)
     
  44. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    I finally got a chance to try out the new orbit mode and it rotates nice and smoothly, thank you so much for that new functionality Pat!

    However, I can't seem to figure out a way to unlock left-right translation and up-down translation while in orbit mode (forward-back translation works fine). Can you please advise? I'm running Unity 4.3.4f1

    Thanks again!!
     
  45. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Yeah, I left that out... I must admit that I never use orbit mode and thought that you people just want be looking at one special object.
    But I just checked in 3dsmax an indeeeeed, that thing still pans!
    Sorry about that, I'll enable paning in the next update.
     
  46. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    Hey eridani, thanks so much for your feedback!
    I just re-enabled panning in orbit mode and it is a huge improvement.
    And before, the whole navigation was locked down when no object is selected.
    Now when nothing is selected, I default to flying.
    This makes the whole orbit mode so much more useful, thanks!!!
    Update 1.1.2 will be in the asset store ASAP.
     
    Last edited: Feb 8, 2014
  47. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Thanks again Pat for your hard work on this driver!! The latest changes do indeed give it much more of an Autodesk feel to your product. I do have a couple of nitpicky feedback, if you can be bothered to tweak it any further:

    1. It seems right now that orbiting and translating cannot be done at the same time, and it makes it a bit less fluid when compared to Maya or Max.

    2. Instead of defaulting to flying when nothing is selected, Autodesk has it orbit around an "imaginary position" that the camera is currently pointing it. Each Autodesk product seems to handle this a bit differently, but it does default to orbiting around some default position rather than flying.

    Anyway, thanks once again for taking the time to listen to your users and develop this much-needed driver. You deserve a virtual beer. Cheers :)
     
    Last edited: Feb 10, 2014
  48. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    I guess I missed nr 1, I'll look into that.
    I had noticed nr 2 too, but is it really important ?
     
  49. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    297
    I've reproduced nr 1, it happens when you hit F (focus on object), but only the first time after loading a project.
    It affects Fly mode the same as Orbit mode.
     
  50. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Hi Pat, I think I didn't explain the first issue properly...

    1. In Maya and Max, you can simultaneously orbit and translate the camera view at all times. For example if I want to start from a far vantage point and then steadily zoom in close to an object while simultaneously orbiting around the object, all the while looking right at it, this can easily be done smoothly by simply rotating and translating the SpaceNavigator simultaneously.

    Think of a helicopter flyby camera shot, where a helicopter descends and moves close to a house, circles it, and then takes off into the sky again, all the while keeping the house in the center of the camera shot. Maya and Max can do accomplish that kind of camera work all very smoothly using the SpaceNavigator...it's extremely useful for modeling.

    Currently, your driver (at least on my machine) can only zoom in one direction a bit, and then orbit a bit, and then move down in one direction a bit, and then zoom in a bit some more, and then orbit a bit, and then move left a bit, and then orbit a bit, etc, etc...this cannot all be done smoothly and simultaneously.

    For example, I cannot simultaneously zoom closer to an object while moving it from left to right, nor can I orbit around an object while zooming closer to it at the same time. It seems initiating any translation overrides any current translation and rotation, and initiating any rotation overrides any current translation and rotation. This happens at all times whether I hit F or not.

    2. As for the other issue orbiting around a arbitrary central point when nothing is selected, I guess it's not crucial, but would be familiar for users of Maya/Max in terms of muscle memory.

    As always, thanks for your responsiveness! Your driver is certainly already useful in its current state.