SceneKit 节点的奇怪行为
Strange behavior with SceneKit Node
我创建了一个圆形数组对象,没问题。
当我旋转时,中心似乎有一个 sinc 或 gaussian 函数。
相机是z 60,结构半径是30。
初始视图,无伪影
向上旋转 90 度,无伪影
旋转 180 度,伪像出现在对象的中心
继续轮换,神器还在。
对象的代码在这里
class func Build(scene: SCNScene) -> SCNNode {
let radius: Double = 30.0
let numberOfStrands: Int = 24
//Create the base chromosomes.
let baseChromosome = SCNBox(width: 4.0, height: 24, length: 1.0, chamferRadius: 0.5)
let baseChromosomes = DNA.buildCircleOfObjects(baseChromosome, numberOfItems: numberOfStrands, radius: radius)
baseChromosomes.position = SCNVector3(x: 0, y: 0.5, z: 0)
return baseChromosomes
}
class func buildCircleOfObjects(_geometry: SCNGeometry, numberOfItems: Int, radius: Double) -> SCNNode {
var x: Double = 0.0
var z: Double = radius
let theta: Double = (M_PI) / Double(numberOfItems / 2)
let incrementalY: Double = (M_PI) / Double(numberOfItems) * 2
let nodeCollection = SCNNode()
nodeCollection.position = SCNVector3(x: 0, y: 0.5, z: 0)
for index in 1...numberOfItems {
x = radius * sin(Double(index) * theta)
z = radius * cos(Double(index) * theta)
let node = SCNNode(geometry: _geometry)
node.position = SCNVector3(x: Float(x), y: 0, z:Float(z))
let rotation = Float(incrementalY) * Float(index)
node.rotation = SCNVector4(x: 0, y: 1, z: 0, w: rotation)
nodeCollection.addChildNode(node)
}
return nodeCollection
}
}
使用这些设置
cameraNode.camera?.xFov = 60
cameraNode.camera?.yFov = 60
cameraNode.camera?.zFar = 1000
cameraNode.camera?.zNear = 0.01
文物消失了。我认为这是zFar的问题,它应该均匀地剪裁后表面而不是镜头像差。
掉出Viewing frustum may be the one to cause most problem. However there is another common cause by misunderstanding the behavior of SCNView's allowsCameraControl,即双指放大或缩小(更改相机的fieldOfView),但pointOfView的位置提示相同。
无论相机的 zNear 有多小,您的节点仍然位于 pointOfView 的后面。因此你看到他们被剪掉了。在这种情况下,下面的代码可能会对您有所帮助,至少可以避免这个问题。
sceneView.pointOfView!.simdPosition
= float3(0, 0, -scene.rootNode.boundingSphere.radius)