与 ARKit 中演示的一些测量应用程序类似,我有一个平面,上面有 2 个标记节点,并在 2 个标记节点之间绘制一条线。不过,我需要的是 2 个标记节点之间的 SCNPlane。所以,如果您的原始节点是在地板上,在墙的两侧放置一个标记,您可以在 AR 世界中用 SCNPlane 代表物理墙。
目前我正在使用以下代码放置该行:
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)
线路来自:
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,我几乎可以使用飞机,但我忍不住想,因为飞机是一个更简单的对象,必须有一个简单的解决方案。
我所需要的只是平面的宽度为两点之间的距离,我已经知道这一点。而且身高并不重要。
距离计算:
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)
Thanks