与 ARKit 中展示的一些测量应用程序类似,我有一个平面,上面有两个标记节点和一个连接这两个节点的线。然而,我需要在这两个节点之间添加一个 SCNPlane 。因此,如果您的原始平面是地板,并且您在墙的两侧放置了标记,则可以在您的 AR 世界中使用 SCNPlane 表示物理墙壁。
目前我正在使用以下代码放置该线:
我知道有类似的问题:例如35002232。 但我认为我需要的更简单。 有一个用户Windchill在那里提供了一份答案,我几乎可以用来制作平面图,但是我不禁想,因为平面图是一个更简单的对象,肯定有一个简单的解决方案。
我所需要的只是让飞机的宽度等于两点之间的距离,我已经知道这个距离。 高度并不重要。
距离计算:
目前我正在使用以下代码放置该线:
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)
谢谢