This example scene demonstrates how to make objects manipulatable using BoundingBoxRig script. The bounding box is a standard interface for manipulating object in Windows Mixed Reality. Using gizmo on the corners and edges, you can scale or rotate the object. App Bar provides the button for entering/exiting 'Adjust' mode to enable/disable Bounding Box. For more information please see 'App Bar and Bounding Box' on Windows Dev Center.
There are two modes in the Bounding Box: Normal mode and Adjust mode.
- Bounding Box is not visible.
- App Bar shows 'Adjust' button
- Bounding Box and gizmo is visible
- App Bar shows 'Done' button
https://gfycat.com/TameQuaintGnu
When you select one of the gizmo, it is highlighted and other gizmos becomes invisible. This visual feedback helps the user to understand which handle is beining interacted with.
This script gets added as a Component to a GameObject. An object with this script as a Component will appear with an AppBar floating in front of it. The BoundingBoxRig script creates a rig of corner and mid-edge handles for scaling and rotating an object. The Adjust button in the AppBar turns on and off the rig. This script cooperates with the TwoHandedManipulation script.
This script is not used directly. It is already included in the BoundingBoxRig script. It takes care of creating the rotation and scale handles that are used to adjust the Target object.
AppBar and AppBarButton script
AppBar uses HolographicButton as a template to build a button collection. In default, it includes Show, Hide, Adjust, Done and Remove buttons. Depending on the current mode - Default, Hidden and Manipulation - it controls the visiblity of each button. Based on the number of the buttons, it adjusts the width of the BackgroundBar component. AppBar script has the logic for following user's position in FollowBoundingBox() function.
You can enable Bounding Box and App Bar by simply assigning BoundingBoxRig script to any GameObject. BoundingBoxRig script contains these items.
- BoundingBoxBasic prefab - Visualizes boundary wireframe
- AppBar prefab - Constructs App Bar
- BoundingBoxHandle material - Default Material for the gizmo
- BoundingBoxGrabbed material - Material for the gizmo when it is being interacted
The BoundingBoxRig exposes several properties in the Inspector. 'Flattening' lets you create a BoundingBoxRig that treats the object as if it were flat in one of its dimensions.
Customization Settings- let you specify custom materials for the Scale cubes and the Rotate spheres. Additionally, you can specify a Material that is used for any selected handle.
Behavior- These settings effect how the BoundingBoxRig Scales and Rotates the Target object. Rotation Type allows the object to be rotated in either World Coordinates, or Model Coordinates. You can also specify whether rotation occurs by moving the hand or controller, or by rotating a controller.
Bounding Box with gizmo provides the interface for scaling and rotating object. To make the object movable, you can assign HandDraggable script to the object. With HandDraggable script, you can grab the body of the object and move. You can move object in both normal mode and adjust mode since it does not require the gizmo interface.
TwoHandManipulatable script allows for an object to be movable, scalable, and rotatable with one or two hands. This script can be combined with BoudningBoxRig script, providing both options for manipulating objects. You can find this interaction behavior in the cliff house. Using two motion controllers and select buttons, you can move/rotate/scale any objects without entering adjust mode. Still you can enter adjust mode by pressing the button on the AppBar and use gizmo to scale/rotate the object. For more detailed information about TwoHandManipulatable script, please refer to the README file.
You can add additional buttons to the App Bar for other actions. AppBar prefab provides convenient options in the Inspector panel. Find the AppBar prefab in the Project panel and select it. In the Inspector panel, expand Buttons section. By modifying the number of Size field, you will be able to see the Element populated in the Buttons section. You can specify details such as postion, name and icon texture name. These buttons are using HolographicButton prefab as a template. HolographicButton is based on CompoundButton script series. For more details about CompoundButton, please refer to the README file of the InteractableObjectExample.