以下代碼在SCNView
中生成一個紅框。但是,邊緣沿着朝向您的側面/元件的頂部和底部呈鋸齒狀(如附件所示)。我們的目標是渲染與Minecraft盒子類似的更平滑的邊緣。改變攝像頭的位置會減少某些邊緣的像素化,所以這是一個攝像頭角度問題?如果是的話,無論攝像機角度是否可以渲染邊緣平滑的盒子?創建更平滑的邊緣或以其他方式修復SCNView中的盒子上的鋸齒邊緣?
例如,將攝像頭位置設置爲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)
你試過'antialiasingMode'嗎? – jtbandes
@jtbandes謝謝,使用'.Multisampling4X'對邊緣進行了一些平滑處理,但它們仍然明顯模糊不平。其他建議? – Crashalot
看起來是特定於iOS的。我在iOS和OS X操場上運行了這段代碼。 OS X版本沒有鋸齒,即使沒有啓用多重採樣。它在真正的iOS硬件上看起來如何? –