Hololens 通过空间理解放置物体

Hololens Placing Objects With Spatial Understanding

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

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

edit2:终于在该位置推了一个对象,但代码仍然非常复杂,它弄乱了我对象的大小和形状。会尽量做到干净整洁。

我已经有一段时间没看过那个例子了,所以希望我能正确记住它的方法名称。它包含一个 "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;
}