<分区>
类似于您可以在 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)
谢谢