本文介绍了Hololens对物体的空间理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been running SpatialUnderstandingExample scene from holo-toolkit. Couldnt figure out how to place my objects into the scene. I want to replace those small boxes that comes default with my own objects. How can I do that?Thanks

找到了绘图盒,但是如何将对象推到那里呢?

edit: found the draw box but how do i push my object there?

edit2:最终将一个对象推到该位置,但是代码仍然非常复杂,它弄乱了我的对象的大小和形状.将尝试使其干净整洁.

edit2: finally pushed an object at the position but still code is very complicated its messing up with the size and shape of my object. Will try to make it clean and neat.

推荐答案

已经有一段时间了,因为我已经看过该示例,因此希望我记得它的方法名称正确.它包含一个"DrawBox"方法,该方法将在成功调用以从空间理解中获取位置之后调用.创建框的调用看起来像这样:

It's been a while since I've looked at that example so hopefully I remember its method name's correctly. It contains a "DrawBox" method that is called after a successful call to get a location from spatial understanding. The call that creates the box looks something like this:

DrawBox(toPlace, Color.red);

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

Replace this call with the following (assuming "toPlace" contains the results from the spatial understanding call and "model" contains the model you are trying to place there):

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;
}

这篇关于Hololens对物体的空间理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:21