Hololens放置具有空间理解的对象

时间:2016-11-21 19:48:44

标签: hololens

我一直在使用holo-toolkit运行SpatialUnderstandingExample场景。无法弄清楚如何将我的对象放入场景中。我想替换那些默认使用我自己的对象的小盒子。我怎样才能做到这一点? 感谢

编辑:找到了绘图框,但我如何将对象推到那里?

edit2:最后在该位置推了一个对象但是代码非常复杂,它弄乱了我的对象的大小和形状。将尽力使它干净整洁。

1 个答案:

答案 0 :(得分:1)

我看了那个例子已经有一段时间了,所以希望我能正确地记住它的方法名称。它包含一个“DrawBox”方法,该方法在成功调用后从空间理解中获取位置。创建框的调用看起来像这样:

DrawBox(toPlace, Color.red);

用以下内容替换此调用(假设“toPlace”包含空间理解调用的结果,“model”包含您尝试放置的模型):

var rotation = Quaternion.LookRotation(toPlace.Normal, Vector3.up);

// Stay center in the square but move down to the ground
var position = toPlace.Postion - new Vector3(0, RequestedSize.y * .5f, 0);

// instantiate the hologram from a model
GameObject newObject = Instantiate(model, position, rotation) as GameObject;

if (newObject != null)
{
     // Set the parent of the new object the GameObject it was placed on
     newObject.transform.parent = gameObject.transform;
}