我正在尝试生成一个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
答案 0 :(得分:1)
配置相机的zFar
属性,以避免在相机较远时进行剪裁。 (默认值为100)
例如:
cameraNode.camera?.zFar = 500
您可以使用此属性来确保在保持良好性能的同时显示所有内容。