Cra*_*lot 4 3d ios glkit scenekit swift
下面的代码在SCNView. 但是,边缘沿着面向您的侧面/元件的顶部和底部呈锯齿状(如附件所示)。目标是渲染类似于 Minecraft 盒子的更平滑的边缘。更改相机位置会减少某些边缘的像素化,那么这是相机角度问题吗?如果是,是否可以渲染具有平滑边缘的盒子,无论相机角度如何?
例如,设置相机位置以SCNVector3(x: 0.0, y: 0.0, z: 10.0)有效地以 2D 形式渲染盒子并具有清晰的边缘(第二个附件)。
let sceneView = SCNView(frame: self.view.frame)
self.view.addSubview(sceneView)
let scene = SCNScene()
sceneView.scene = scene
let camera = SCNCamera()
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: -3.0, y: 0.0, z: 10.0)
let ambientLight = SCNLight()
ambientLight.type = SCNLightTypeAmbient
ambientLight.color = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0)
cameraNode.light = ambientLight
let light = SCNLight()
light.type = SCNLightTypeOmni
let lightNode = SCNNode()
lightNode.light = light
lightNode.position = SCNVector3(x: 0, y: 20, z: 10)
let cubeGeometry = SCNBox(width: 3.0, height: 3.0, length: 3.0, chamferRadius: 0.0)
let cubeNode = SCNNode(geometry: cubeGeometry)
let planeGeometry = SCNPlane(width: 100.0, height: 100.0)
let planeNode = SCNNode(geometry: planeGeometry)
planeNode.eulerAngles = SCNVector3(x: GLKMathDegreesToRadians(-90), y: 0, z: 0)
planeNode.position = SCNVector3(x: 0, y: -0.5, z: 0)
let redMaterial = SCNMaterial()
redMaterial.diffuse.contents = UIColor.redColor()
cubeGeometry.materials = [redMaterial]
let greenMaterial = SCNMaterial()
greenMaterial.diffuse.contents = UIColor.greenColor()
planeGeometry.materials = [greenMaterial]
let constraint = SCNLookAtConstraint(target: cubeNode)
constraint.gimbalLockEnabled = true
cameraNode.constraints = [constraint]
lightNode.constraints = [constraint]
scene.rootNode.addChildNode(lightNode)
scene.rootNode.addChildNode(cameraNode)
scene.rootNode.addChildNode(cubeNode)
scene.rootNode.addChildNode(planeNode)
Run Code Online (Sandbox Code Playgroud)
正如评论中提到的,如果您想对每一帧进行抗锯齿,请设置antialiasingMode. 它不像 CoreGraphics 那样出色,但它相当不错。然而,它确实增加了大量的工作负载,所以你\xe2\x80\x99会消耗电池并降低帧速率。
在 OS X 上,默认情况下每帧进行 4 倍多重采样。在 iOS 上,默认情况下不进行多重采样,因为它\xe2\x80\x99s 非常昂贵。
\n\n幸运的是,\xe2\x80\x99s 有一个我更喜欢的解决方案,那就是打开jittering. 它\xe2\x80\x99s有点像多重采样但很懒。当对象移动时,它们会正常渲染(带有锯齿),但当它们停止移动时,渲染器会在后台运行 96 帧以上,并平滑所有锯齿。
最终的外观比抗锯齿好得多(因为\xe2\x80\x99s没有\xe2\x80\x9c96x抗锯齿模式\xe2\x80\x9d)并且在快速硬件上大多数人我\xe2\x80\x99已经展示了它\xe2\x80\x99t 意识到当物体移动时质量会发生变化。
\n