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
|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 !
11 thoughts on “TwoHandManipulatable – part 2 of moving, scaling, rotating objects”
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:).
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.
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!!! 🙂
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!! 🙂
I use Unity5.6.2 and do not have the option to change the Scripting Runtime version to Experimental
Hi Linoy, It’s best you upgrade your Unity to the latest version since lot of things would be outdated with the previous versions.
Useful post.. and I have question. I want pinched a model like part 1,. How can I do for it?
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?
my question means, “TowHandManipulatable” can’t operating with WorldAnchor(like “TapToPlace” of MRTK example)?
I’m having an issue with getting this tutorial to work on certain meshes that I’ve imported. On some meshes, when I select the object it moves very far away and the manipulation doesn’t work as expected. Same with the Bounding Box Rig from part 1, if I click the spherical handles to rotate an object it just moves the object, doesn’t rotate it. Although the bounding box is accurately shown around the mesh, the mesh acts as if it’s actually somewhere else when I try to manipulate it.
I was wondering if you ever dealt with this kind of issue before or would know how to resolve it.
Hi Michael, check how the colliders are on the object. It should be closely attached to the object i.e surrounding it closely. The Bounding box rig from part 1 issue: you need to pinch and move the spherical handles to rotate an object. It is somehow annoying because it isn’t smooth. I prefer the two hand manipulation without the bounding box any day for smoother movements and manipulations