ARKit-在Swift 3的平面上的2个矢量点之间放置一个SCNPlane [英] ARKit - place a SCNPlane between 2 vector points on a plane in Swift 3
问题描述
类似于您可以在ARKit中看到的一些测量应用程序,我有一个带有2个标记节点的平面,并在2个之间绘制了一条线.尽管如此,我需要的是2个之间的SCNPlane.您的原始物是地板,并且在墙的两边都放了一个标记,您可以在AR世界中用SCNPlane代表物理墙.
Similar to some of the measuring apps you can see being demonstrated in ARKit, I have a plane with 2 marker nodes on it and a line drawn between the 2. What I need though is an SCNPlane between the 2. So, if your original was the floor and you put a marker either side of a wall, you could represent the physical wall with a SCNPlane in your AR world.
当前,我使用以下代码放置行:
Currently I'm placing the line with the following code:
let line = SCNGeometry.lineFrom(vector: firstPoint.position, toVector: secondPoint.position)
let lineNode = SCNNode(geometry: line)
lineNode.geometry?.firstMaterial?.diffuse.contents = UIColor.white
sceneView.scene.rootNode.addChildNode(lineNode)
lineFrom:
extension SCNGeometry {
class func lineFrom(vector vector1: SCNVector3, toVector vector2: SCNVector3) -> SCNGeometry {
let indices: [Int32] = [0, 1]
let source = SCNGeometrySource(vertices: [vector1, vector2])
let element = SCNGeometryElement(indices: indices, primitiveType: .line)
return SCNGeometry(sources: [source], elements: [element])
}
}
我知道那里也有类似的问题:例如35002232.但是我认为我追求的是更简单的方法.用户那里提供了一个答案:Windchill,我几乎可以使用飞机了,但是我不禁想到,因为飞机是一个更简单的对象,所以必须有一个简单的解决方案.
I know there are similar questions out there: 35002232 for example. But I think what I'm after is simpler. There is an answer there by a user: Windchill that I can almost get to work with a plane but I can't help but think as the plane is a simpler object, there must be a simple solution.
我需要做的是使平面的宽度等于两点之间的距离,我已经知道这一点.而且高度并不重要.
All I need is for the plane to have a width of the distance between the 2 points, I already know this. and the height isn't important.
距离计算:
let position = SCNVector3Make(secondPoint.position.x - firstPoint.position.x, secondPoint.position.y - firstPoint.position.y, secondPoint.position.z - firstPoint.position.z)
let result = sqrt(position.x*position.x + position.y*position.y + position.z*position.z)
谢谢
推荐答案
您可以在ARKit中的两个向量之间创建一个节点.
You can create a node between 2 vectors in ARKit.
在此处查看GitHub项目, https://github.com/max6363/ARKit-LineNode-Between-2-Points .
See GitHub project here, https://github.com/max6363/ARKit-LineNode-Between-2-Points.
继续摇摆......享受...:)
Keep rocking.... Enjoy.... :)
这篇关于ARKit-在Swift 3的平面上的2个矢量点之间放置一个SCNPlane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!