9

When I run this SceneKit code:

let txt = SCNText(string: "Hello", extrusionDepth: 0.2)
let textNode = SCNNode(geometry: txt)
scene.rootNode.addChildNode(textNode)

I get very angular text:

Poorly rendered text

It seems to do this regardless of font and it behaves the same way on a device as in the simulator.

Here's the code in context:

    // create a new scene
    let scene = SCNScene()

    // create and add a camera to the scene
    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    scene.rootNode.addChildNode(cameraNode)

    // place the camera
    cameraNode.position = SCNVector3(x: 10, y: 0, z: 75)

    // create and add a light to the scene
    let lightNode = SCNNode()
    lightNode.light = SCNLight()
    lightNode.light!.type = SCNLightTypeOmni
    lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
    scene.rootNode.addChildNode(lightNode)

    // create and add an ambient light to the scene
    let ambientLightNode = SCNNode()
    ambientLightNode.light = SCNLight()
    ambientLightNode.light!.type = SCNLightTypeAmbient
    ambientLightNode.light!.color = UIColor.darkGrayColor()
    scene.rootNode.addChildNode(ambientLightNode)

    let txt = SCNText(string: "Hello", extrusionDepth: 0.2)

    let textNode = SCNNode(geometry: txt)
    scene.rootNode.addChildNode(textNode)



    // retrieve the SCNView
    let scnView = self.view as! SCNView

    // set the scene to the view
    scnView.scene = scene
Larry OBrien
  • 8,484
  • 1
  • 41
  • 75

2 Answers2

9

SCNText subdivides the 2D Bézier path for your text just like Core Graphics would do if you were drawing it. You can always use the flatness property to make it smoother, but you won't get "sub-pixel smoothness".

To solve this issue you can use a bigger font size, so that the underlying Bézier path is bigger and more vertices are generated when discretization occurs.

mnuages
  • 13,049
  • 2
  • 23
  • 40
0

My solution was using big font as @mnuages was suggested then using scale on the text node with

     animatedTextNode.scale = SCNVector3(0.1, 0.1, 0.1)

to get what size I wanted.

In that case when you animate text and when it comes closer to the camera it looks smooth.

Hope
  • 2,096
  • 3
  • 23
  • 40