This was a fun piece of functionality and super easy to add. I’d seen a few HoloLens demos where you can scale the model up and down using “bigger” and “smaller” voice commands. There’s even some code in the HoloLens Toolkit that does it. But until I’d actually added it to our robot application, I hadn’t really understood how interesting it was.
You can scale a model down and have it sit on your desktop…
…or you can scale it up to 10x its realworld size and inspect it in unbelievable close-up mode. From the inside! (Although in fairness the model was never intended to be viewed like this, so some of the parts don’t appear properly. Something to think about when modeling for extreme scaling. :-)
The code to add this is trivial. You need to have a few lines in your SpeechManager.cs to capture and marshal the commands themselves, and otherwise you’ll need a simple Scale.cs such as the one below attached to your robot’s root.
using UnityEngine;
public class Scale : MonoBehaviour
{
private const float DefaultSizeFactor = 2.0f;
[Tooltip("Size multiplier to use when scaling the object up and down.")]
public float SizeFactor = DefaultSizeFactor;
private void Start()
{
if (SizeFactor <= 0.0f)
{
SizeFactor = DefaultSizeFactor;
}
}
public void OnBigger()
{
Vector3 scale = transform.localScale;
scale *= SizeFactor;
transform.localScale = scale;
}
public void OnSmaller()
{
Vector3 scale = transform.localScale;
scale /= SizeFactor;
transform.localScale = scale;
}
}
For the full fun, take a look at this video:
Next time we’re going to look at another fun piece of the puzzle: having our robot respond to music.