SceneKit CALayer 反锐化绘图

SceneKit CALayer unsharp drawing

我正在尝试绘制 UIBezierPaths 并将它们显示在 SCNPlane 上,但我得到的结果非常不清晰(See in the image)我怎样才能让它更清晰?

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)

我试图增加 displayLayer.frame 的大小,但它只会让东西变小。

感谢您的回答! 安德拉斯

尝试更改 UIBezierPath "flatness" 属性(0.1、0.01、0.001 等)。

这让我发疯了,所以希望这个答案能帮助其他偶然发现这个问题的人。我正在将 CALayer 映射到 SCNMaterial 纹理以用于 ARKit 场景,并且一切都是 blurry/pixelated。将 CALayercontentsScale 属性 设置为 UIScreen.main.scale 没有做任何事情,也没有玩 shouldRasterizerasterizationScale.

解决方案是将图层的框架设置为所需的框架,乘以屏幕的比例,否则 material 是缩放变换图层以适应纹理。换句话说,层的大小需要是其所需大小的 3 倍。

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