我一直在运行全息工具包中的 SpatialUnderstandingExample 场景。无法弄清楚如何将我的对象放入场景中。我想用我自己的对象替换那些默认的小盒子。我怎样才能做到这一点?谢谢
编辑:找到了画框,但我如何将我的对象推到那里?
编辑2:最终将一个对象推到该位置,但代码仍然非常复杂,它弄乱了我的对象的大小和形状。会尽量让它干净整洁。
我一直在运行全息工具包中的 SpatialUnderstandingExample 场景。无法弄清楚如何将我的对象放入场景中。我想用我自己的对象替换那些默认的小盒子。我怎样才能做到这一点?谢谢
编辑:找到了画框,但我如何将我的对象推到那里?
编辑2:最终将一个对象推到该位置,但代码仍然非常复杂,它弄乱了我的对象的大小和形状。会尽量让它干净整洁。
自从我查看该示例以来已经有一段时间了,所以希望我能正确记住它的方法名称。它包含一个“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;
}