3

I'm trying to draw UIBezierPaths and display them on a SCNPlane, though I'm getting a very unsharp result (See in the image) How could I make it sharper?

let displayLayer = CAShapeLayer()
  displayLayer.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
  displayLayer.path = path.cgPath
  displayLayer.fillColor = UIColor.clear.cgColor
  displayLayer.strokeColor = stroke.cgColor
  displayLayer.lineWidth = lineWidth
  let plane = SCNPlane(width:size.width, height: size.height)
  let material = SCNMaterial()
  material.diffuse.contents = displayLayer
  plane.materials = [material]
  let node = SCNNode(geometry: plane)

I've tried to increase the displayLayer.frame's size but it only made things smaller.

Thanks for your answer! Andras

Samu Andras
  • 171
  • 1
  • 6
  • changing the layer's frame is a good idea because it will lead to a larger texture to map the object. You'll need to scale the Bézier path by the same amount for it to appear of the same size. – mnuages Dec 29 '17 at 15:21

2 Answers2

1

This has been driving me crazy, so hopefully this answer helps someone else who stumbles across this. I'm mapping a CALayer to a SCNMaterial texture for use in an ARKit scene, and everything was blurry/pixelated. Setting the contentsScale property of the CALayer to UIScreen.main.scale didn't do anything, nor playing with shouldRasterize and rasterizationScale.

The solution is to set the layer's frame to the desired frame, multiplied by the screen's scale, otherwise the material is scale transforming the layer to fit the texture. In other words, the layer's size needs to be 3x its desired size.

let layer = CALayer() layer.frame = CGRect(x: 0, y: 0, width: 500 * UIScreen.main.scale, height: 750 * UIScreen.main.scale)

Sean Thielen
  • 1,396
  • 1
  • 11
  • 15
0

Try to change UIBezierPath "flatness" property (0.1, 0.01, 0.001 etc).

Yao Huela
  • 86
  • 2