在 Scene Kit 中缩小后 SCNNodes 消失了吗?

SCNNodes disappear after zooming out in Scene Kit?

我正在尝试生成一个 3d 体素风格的岛,并且正在生成砖块并将它们放置在场景中。但是,当我将相机节点上的 z 轴设置为超过 150 时,对象会消失在白色背景后面。

import Cocoa
import SceneKit
import PlaygroundSupport

let view = SCNView()
let scene = SCNScene()
view.scene = scene
view.frame = CGRect(x: 0, y: 0, width: 650, height: 650)

public func buildIsland(size: Int, image: NSImage, scene: SCNScene){

//Start building the island
var blocks = 0
for x in 0...size {
    for y in 0...size {

        //Create Block
        var block = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 0)
        var color = SCNMaterial()
        color.diffuse.contents = CGColor.init(red: 0, green: 1, blue: 0, alpha: 1)
        block.materials[0] = color
        var node = SCNNode(geometry: block)
        node.position = SCNVector3(x/2, y/2, 0)
        scene.rootNode.addChildNode(node)
        blocks = blocks + 1

    }
}

}




view.autoenablesDefaultLighting = true
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 200)
scene.rootNode.addChildNode(cameraNode)

buildIsland(size: 4, image: NSImage(), scene: scene)

view.allowsCameraControl = true

PlaygroundPage.current.liveView = view

配置相机的zFar 属性以避免相机距离较远时发生裁剪。 (默认值为 100)

例如: cameraNode.camera?.zFar = 500

您可以使用这个 属性 来让所有内容可见,同时保持良好的性能。