SceneKit – 获取节点的高度

SceneKit – Get Node's height

我有一个 SceneKit 项目,其中目前有 2 个对象,一个是简单平面的地面和一个金字塔。我想将金字塔节点的高度设置为类似以下 sudo 代码的值:

pyr.position = SCNVector3Make(0, ground.position.y+pyr.size.height, 0)

有没有办法以像素或点为单位获取节点的高度?

注意

这就是我创建 pyrground 节点的方式:

let pyr = scene.rootNode.childNodeWithName("pyramid", recursively: true)!
let ground = scene.rootNode.childNodeWithName("ground", recursively: true)!

你试过吗?

来自文档:

SCNBoundingVolume 协议 定义了一个接口,用于描述在 space 中占据体积的对象,被 SCNNode 和 SCNGeometry 类 采用。它的方法测量对象在对象局部坐标 space 中的位置和大小,表示为方框或球体。

获取对象边界框的最小和最大角点。

    func getBoundingBoxMin(_ min: UnsafeMutablePointer<SCNVector3>,
               max max: UnsafeMutablePointer<SCNVector3>) -> Bool

min
On output, the minimum coordinates of the bounding box.

max
On output, the maximum coordinates of the bounding box.

(max.y - min.y) 就是身高。