如果您想在扩展中使用 ARKit 的 SCNVector3,请确保您导入了 SceneKit。您可以使用以下代码:
import ARKit import SceneKit
extension SCNVector3 { func add(other: SCNVector3) -> SCNVector3 { return SCNVector3(x: self.x + other.x, y: self.y + other.y, z: self.z + other.z) } }
let position = SCNVector3(x: 0, y: 0, z: -1) let translation = SCNVector3(x: 1, y: 0, z: 0)
let newPosition = position.add(other: translation)
在这里,我们扩展了 SCNVector3 来添加一个名为'add”的函数。我们在函数中使用 ARKit 的 SCNVector3 并确保导入了 SceneKit。