【问题标题】:ARKit - place a SCNPlane between 2 vector points on a plane in Swift 3 [duplicate]ARKit - 在 Swift 3 中的平面上的 2 个矢量点之间放置一个 SCNPlane [重复]
【发布时间】: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


【解决方案1】:

您可以在 ARKit 中的 2 个向量之间创建一个节点。

在此处查看 GitHub 项目,https://github.com/max6363/ARKit-LineNode-Between-2-Points

继续摇摆......享受...... :)

【讨论】:

  • 这只是在两点之间放置一条线吗?我已经有了(见问题文本)。我所追求的有点复杂,但我还是回答了。谢谢
猜你喜欢
  • 1970-01-01
  • 2018-12-01
  • 1970-01-01
  • 2017-02-25
  • 2018-04-15
  • 2018-10-20
  • 2019-09-07
  • 1970-01-01
  • 2020-06-04
相关资源
最近更新 更多