我通过Scenekit基于真实表制作了虚拟平面(SCNPlane)。另外,我想知道虚拟平面的 4 个顶点的坐标。
你可以得到边界框的坐标,就像BlackMirrorz所说的。
let (min, max) = planeNode.boundingBox
Run Code Online (Sandbox Code Playgroud)
这将为您提供作为 SCNVector3 对象的对角(最小和最大)。这些坐标将相对于 object,未旋转、未平移和未缩放。导出 2d 平面中的另外两个角坐标。不用担心 Z 轴。SCNPlane 本质上是一个 2D 对象。
let bottomLeft = SCNVector3(min.x, min.y, 0)
let topRight = SCNVector3(max.x, max.y, 0)
let topLeft = SCNVector3(min.x, max.y, 0)
let bottomRight = SCNVector3(max.x, min.y, 0)
Run Code Online (Sandbox Code Playgroud)
然后打电话
let worldBottomLeft = planeNode.convertPosition(bottomLeft, to: rootNode)
let worldTopRight = planeNode.convertPosition(topRight, to: rootNode)
let worldTopLeft = planeNode.convertPosition(topLeft, to: rootNode)
let worldBottomRight = planeNode.convertPosition(bottomRight, to: rootNode)
Run Code Online (Sandbox Code Playgroud)
将每个坐标转换为世界空间。系统将为您进行旋转、平移和缩放。
| 归档时间: |
|
| 查看次数: |
1270 次 |
| 最近记录: |