本文介绍了无法使用 UIBezierPath 和 SCNShape 创建圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人熟悉使用弯曲的 UIBezierPaths 在 ARKit 中创建 SCNShape 吗?我正在创建一个封闭的圆形路径,但在我的 ARKit 场景中我得到了一个菱形.

Anyone familiar with using curved UIBezierPaths to create a SCNShape in ARKit? I'm creating a closed circle path, but I get a diamond shape in my ARKit scene.

这是我用来创建贝塞尔曲线和 SCNShape 的代码:

Here is the code I use to create the bezier path and SCNShape:

let radius : CGFloat = 1.0
let outerPath = UIBezierPath(ovalIn: CGRect(x: -radius, y: -radius, width: 2* radius, height: 2* radius))

let material = SCNMaterial()
material.diffuse.contents = UIColor.blue
material.isDoubleSided = true
material.ambient.contents = UIColor.black
material.lightingModel = .constant
material.emission.contents = UIColor.blue

let shape = SCNShape(path: outerPath, extrusionDepth: 0.01)
shape.materials = [material]

let shapeNode = SCNNode(geometry: shape)
positioningNode.addChildNode(shapeNode)

我已经成功测试了矩形贝塞尔曲线路径,但即使是圆角矩形贝塞尔曲线路径也有问题(使用 UIBezierPath(roundedRect:)).对于圆角矩形贝塞尔曲线路径,ARKit 显示了弯曲的角带有 45 度线.

I've successfully tested a rectangular bezier path, but even had issues with a rounded rect bezier path (using UIBezierPath(roundedRect:). For the rounded rect bezier path, ARKit shows the curved corners with 45 degree lines.

提前致谢!

更新:

左侧是 UIBezierPath 平坦度设置为 0.6 的初始 SCNShape.右侧是平坦度设置为 0.001 的相同 SCNShape.

On the left is the initial SCNShape with UIBezierPath flatness set to 0.6. On the right is the same SCNShape with flatness set to 0.001.

推荐答案

我找到了解决方案.基本上 UIBezierPath 的平坦度变量用于控制曲率.就我而言,默认值 0.6 太大了.我最终使用了 0.001 的平坦度

I was able to find a solution. Basically the UIBezierPath's flatness variable is used to control curvature. The default value of 0.6 was too large in my case. I ended up using a flatness of 0.001

https://developer.apple.com/documentation/scenekit/scnshape/1523432-init

这篇关于无法使用 UIBezierPath 和 SCNShape 创建圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:27