Hololens Placing Objects With Spatial Understanding

家住魔仙堡 提交于 2019-12-12 03:43:49

问题


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: 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.


回答1:


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

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


来源:https://stackoverflow.com/questions/40728179/hololens-placing-objects-with-spatial-understanding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!