本文介绍了无法使用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.

提前谢谢!

更新:

左侧是初始SCNShape,其UIBezierPath平坦度设置为0.6.右边是同一SCNShape,其平整度设置为0.001.

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创建圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:35