首页 > 解决方案 > 如何确保不相对于相机移动 SCN 节点

问题描述

我在 SCN 场景中创建了点、线、文本等视图实体。但是一旦创建,如果我移动我的相机,即使这些实体也会相对于相机移动。

我想将这些实体(例如,SCN 节点)保持在相同的位置(我在创建它们时使用的坐标)。

例如,我正在使用下面的函数来创建一个点。

// add dot node with given position
func nodeWithPosition(_ position: SCNVector3) -> SCNNode {
    // create sphere geometry with radius
    let sphere = SCNSphere(radius: 0.01)
    // set color
    sphere.firstMaterial?.diffuse.contents = UIColor(red: 255/255.0,
                                                     green: 153/255.0,
                                                     blue: 83/255.0,
                                                     alpha: 1)
    // set lighting model
    sphere.firstMaterial?.lightingModel = .constant
    sphere.firstMaterial?.isDoubleSided = true
    // create node with 'sphere' geometry
    let node = SCNNode(geometry: sphere)
    node.position = position

    return node
}

上面的函数可以这样使用:

let node = self.nodeWithPosition(position)
sceneView.scene.rootNode.addChildNode(node)

如果有人可以帮助我,我会非常高兴。

标签: iosswiftarkit

解决方案


推荐阅读