TwoHandManipulatable – part 2 of moving, scaling, rotating objects

Continuing with the example of moving, resizing and rotating objects with the BoundingBox, this article is a sequel to achieving the same objective – but in another easier way.

As I go deeper into exploring the MR Toolkit-Unity, I see that lot of things are made much more easier and intuitive for the user. For instance- if I were to move an object in the real world, I would use two hands.

The TwoHandManipulatable script in the MR Toolkit-Unity is precisely aiming to do this. Furthermore, you can achieve object rotation and scaling (resizing) with this script attached to your object.

I also list a tradeoff of my experiences using the three different options to move the objects. i.e AppBar and BoundingBox, HandDraggable.cs and TwoHandManipulatable.cs

App Bar+ Bounding Box

HandDraggable

TwoHandManipulatable

Move – not applicable

Scale – separate variable specified for scale. Click and hold on handles can be a little annoying

Rotate – click and hold on handles can be a little annoying to rotate

Pros: clearly specified boundary. And useful if you want specific movements

only Move possible – scale rate is separate. However not free flowing

Only one hand movement possible

 

Pros: easy to use, simply attach to the object with a mesh collider

 

Move, scale and rotate all three are possible

Pros: free flowing, intuitive and two hand movements, simply attach the script and use it

To get started, do the following:

1. Create a new project in Unity

It’s better if you get Unity 2018 version as you’d need to make it compatible with the next must have – Mixed Reality Toolkit- Unity

I’ve also done this with the latest OS Windows 10 Redstone 4 (which is so cool, more updates in the following article)

2. Import the Mixed Reality Toolkit-Unity from https://github.com/Microsoft/MixedRealityToolkit-Unity/releases/tag/2017.4.0.0 

3. Do the usual tweaks:

a. Delete the main Camera.  Add the MixedRealityCameraParent.prefab in the Hierarchy. This will serve as the Main Camera

b. Change the Camera Settings to Hololens preferred:

Skybox to Solid Color

Background to 0,0,0,0

c. Go to Edit ->Project Settings -> Player -> Other Settings -> and change the Scripting Runtime version to Experimental 

d. Save the scene

Now let’s get some objects within the scene which we can manipulate:

Let’s reuse the Furniture Pack 3D Asset pack from the Asset Store for free from the last project itself https://assetstore.unity.com/packages/3d/props/furniture/pack-gesta-furniture-1-28237

I’m going to add the objects: tv1, glass_table and bed2. You can add any objects that you like or add your own

Just so that it is organized, I will create an empty GameObject and move my objects into the scene. I called this object MovableGameObjects

Also ensure that the scale of the objects are smaller, since otherwise they are going to look huge!

I changed the scale of all three objects to: 0.5, 0.5, 0.5

Also make sure you adjust the camera position to an optimal view of the objects

If all is done correctly so far, then you will see the three objects grouped under MovableGameObjects 

Now for the part where we can interact with the movable objects using the TwoHandManipulatable.cs script

1. First add the Default Cursor.prefab from the HoloToolkit. Search for it in the Assets and drag and drop it into the Hierarchy

2. Search for the InputManager.prefab in the Assets and drag and drop it into the Hierachy as well

3. On the Inspector settings of the InputManager, under SimpleSingerPointerSelector component, drag and drop the Default Cursor into the Cursor field (if you haven’t seen the article Gaze and Tap on objects, then this is a good time to refer to it)

4. For every object that you want to interact with, you need to ensure that there is a corresponding MeshCollider. I added Mesh Colliders to the individual objects which are movable. In my experience, the MeshColliders work best for this kind of gesture input

So click on every movable object and in the Inspector’s Add Component, add a Mesh Collider

(Note that the asset may already come with it’s own Mesh Collider, so you don’t need to add an extra one in this case)

Coming to the twohandmanipulation part:

In the Assets, search for the TwoHandManipulatable.cs script and add it to any object.

Let’s add it to the MovableObjects

Make sure you change the manipulation mode to Move, Scale and Rotate if you want all three interactions

If you want to attach a bounding box to the objects so that you know when it’s in the manipulation mode, then simply drag and drop the BoundingBoxBasic.prefab into the Bounding Box Prefab Inspector variable of the TwoHandManipulatable script.

Build and deploy onto the HoloLens and let’s see if the interactions work.

I’ve attached a video of how the interactions should look like

Let’s look at the Inspector variables of the TwoHandManipulatable.cs script.

So what is important for us is 4 different variables:

Bounding Box Prefab is the blue box around the object as you saw in the video. It’s optional, so you can simply leave this field empty if you don’t want it. I use it mainly for visual feedback

Manipulation Mode can be different values. If you want all three Move, Rotate and Scale then choose that

Rotation Constraint can be limited to any Axis

Enable One Hand Movement is checked when you want to move objects with just one pinch and drag

Errors and solutions:

Error 1: Using the MR Toolkit-Unity may cause some errors. So if you see the errors shown below, then you need to change only one thing

Any of your scripts may show this error

Solution: First check if you have imported the HoloToolkit properly, else, see if the Console is showing this error

For this, go to Edit ->Project Settings -> Player -> Other Settings -> and change the Scripting Runtime version to Experimental 

Hope this article has helped you seamlessly move, scale and rotate objects. Let me know in your comments !

9 response to "TwoHandManipulatable – part 2 of moving, scaling, rotating objects"

  1. By: Ariel Feldman Posted: July 10, 2018

    Rock On!,
    Great blog, please do more :):)
    Also, regarding the mesh collider- from what I’ve learned the collider figure can have an impact on performance, especially when deploying on Hololens ( I think it because C/GPU calc on collider figure is not easy:).

    • By: Nischita Posted: July 11, 2018

      Hey Ariel! Thanks :)) Yes, will write more.
      Yes, you are right. The mesh calculations are dependent on the polygons/meshes in the object, and consequently the colliders. I have tried with complex models with lot of vertices and polygons, but I usually end up reducing the object more and more to attain higher performance.

  2. By: Ariel Feldman Posted: July 11, 2018

    :)…
    any chance to write a cool tutorial about complex model mesh reducing for Hololens (….& colliders handling ) – I find the area so much confusing and right now you are my favorite Hololens Unity tutor!!! 🙂
    #Go Nischita

  3. By: Nischita Posted: July 12, 2018

    Hah. That is unfortunately not my forte. But if I do get any info around it, I will make sure I post it.
    Also, with the new release of the HoloLens, awaited early next year- let’s hope they allow more options for model rendering.
    And thanks for the awesome feedback!! 🙂

  4. By: linoy sarfaty Posted: August 21, 2018

    I use Unity5.6.2 and do not have the option to change the Scripting Runtime version to Experimental

    • By: Nischita Posted: August 23, 2018

      Hi Linoy, It’s best you upgrade your Unity to the latest version since lot of things would be outdated with the previous versions.

  5. By: JOYS Posted: November 7, 2018

    Useful post.. and I have question. I want pinched a model like part 1,. How can I do for it?

  6. By: Nischita Posted: November 7, 2018

    Hi Joys, I didn’t get your question. Ideally you are also pinching the models even in this method. Did you mean the BoundingBox option?

  7. By: JOYS Posted: November 12, 2018

    my question means, “TowHandManipulatable” can’t operating with WorldAnchor(like “TapToPlace” of MRTK example)?

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: