【发布时间】:2017-12-29 01:52:08
【问题描述】:
与您可以在 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)
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,我几乎可以用飞机工作,但我不禁认为飞机是一个更简单的物体,必须有一个简单的解决方案。
我所需要的只是让飞机的宽度等于两点之间的距离,我已经知道了。高度并不重要。
距离计算:
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)
谢谢
【问题讨论】:
-
我已经根据另一个问题回答了这个问题:stackoverflow.com/questions/45425582/…
-
我 6 个月前的评论说我发布的另一个问题已经回答了这个问题。不过,我会单击已解决的按钮。或许应该说得更清楚些。感谢您指出。
标签: swift scenekit ios11 arkit