如何在Measure应用程序中在ARKit(SceneKit)中绘制虚线?

时间:2018-12-18 08:10:56

标签: swift scenekit arkit scnnode

只是想知道是否有可能(如我所知,但是如何)像在Measure应用程序中那样在ARSCNView中绘制虚线? 也许有一种方法可以直接使用场景节点idk。

我一直在使用SCNCylinder画一条直线,IDK是否有可能重新使用它并进行调整,或者我们必须使用一种截然不同的方式制作虚线。

in 2 days

1 个答案:

答案 0 :(得分:0)

可能不是最专业的解决方案,但我从一个非常相似的方法开始。然后添加如下虚线样式。

首先,我创建了一张半白色,半透明的图像,以创建虚线样式

然后在SCNCylinder的材料中使用它:

material.diffuse.contents = UIImage(named: "line")!
material.diffuse.wrapS = .repeat
material.diffuse.wrapT = .repeat
material.isDoubleSided = true // Not sure if this is really needed here^

接下来,我根据需要对其进行缩放,以重复它(使其精细):

material.diffuse.contentsTransform = SCNMatrix4MakeScale(width * repeatCountPerMeter, height * repeatCountPerMeter, 1)

当我使用白色图像时,我可以用任何想要的颜色“着色”它:

material.multiply.contents = UIColor.green

要使其看起来更像“ 2D风格”,请忽略照明,使用:

material.lighting = .constant

另外(由于将圆柱体旋转90°),我还必须旋转材质:

let rotation = SCNMatrix4MakeRotation(.pi / 2, 0, 0, 1)
material.diffuse.contentsTransform = SCNMatrix4Mult(rotation, material.diffuse.contentsTransform)

每当调整行的大小时,都相应地更新其SCNMatrix4MakeScale(请参见width和高度above, where for height,我只是输入直径(2 * r))。

相关问题