Create smoother edges or otherwise fix the jagged edges on a box in SCNView?

The code below creates a red box in SCNView. However, the edges are jagged along the upper and lower sides of the side / element facing you (as shown in the appendix). The goal is to make smoother edges look like Minecraft boxes. Changing the position of the camera reduces the pixelation of certain edges, so is this a problem with the viewing angle of the camera? If so, can boxes with smooth edges be displayed regardless of camera angle?

For example, setting the camera position to SCNVector3(x: 0.0, y: 0.0, z: 10.0)makes the field effective in 2D and with clear edges (second attachment).

enter image description here enter image description here

    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)
+4
1

, , antialiasingMode. , CoreGraphics, . , , .

OS X 4x . iOS , .

, , , jittering. , . , ( jaggies), , 96 jaggies.

, ( theres no " 96x" ) Ive , , .

+4

Source: https://habr.com/ru/post/1623174/


All Articles