swift - 绘制没有对角线的 SCNBox 边缘?

标签 swift scenekit arkit scnnode

我正在使用 Apple 的 ARKit 制作 AR 应用程序,我想制作盒子的线框轮廓。代码中描述并显示在图片中的那个在盒子的每个面上绘制斜边。它还隐藏了盒子另一侧的角。 Scene Kit 中有没有办法让我摆脱对角线并使盒子透明,显示所有边和顶点?

let box:SCNNode = SCNNode(geometry: SCNBox(width: CGFloat(0.1), height: CGFloat(0.1), length: CGFloat(0.1), chamferRadius: CGFloat(0)))
box.geometry?.firstMaterial?.fillMode = .lines
box.geometry?.firstMaterial?.diffuse.contents = UIColor.green

Current SCNBox

最佳答案

我不确定如何去掉对角线。

但是将 Material 设置为双面会在框的另一侧绘制线条。

 box.geometry?.firstMaterial?.isDoubleSided = true

编辑:

这是实现您想要的效果的另一种方法(摆脱那些对角线!)

enter image description here

let sm = "float u = _surface.diffuseTexcoord.x; \n" +
    "float v = _surface.diffuseTexcoord.y; \n" +
    "int u100 = int(u * 100); \n" +
    "int v100 = int(v * 100); \n" +
    "if (u100 % 99 == 0 || v100 % 99 == 0) { \n" +
    "  // do nothing \n" +
    "} else { \n" +
    "    discard_fragment(); \n" +
    "} \n"

let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)

box.firstMaterial?.emission.contents = UIColor.green

box.firstMaterial?.shaderModifiers = [SCNShaderModifierEntryPoint.surface: sm] 

box.firstMaterial?.isDoubleSided = true

关于swift - 绘制没有对角线的 SCNBox 边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47999659/

相关文章:

swift - UIView 动画表现怪异

ios - 当状态更改时,如何防止 SceneKit 场景重新渲染不佳?

objective-c - 在相机不是场景中心的 3D 空间中对 2D 平面进行广告牌

ios - 如何从 'SKScene' 调用我的 'ViewController' 中的方法

arrays - Swift 巨大的数组字典,非常慢

ios - WatchKit - 如何使用 RowControllerAtIndex 以编程方式更改 UITableViewCell 的背景图像

ios - 更快的 UIImage - Base64 转换

scenekit - 调试物理 View ?

ios11 - 如何使用AR创建可在iOS 11中用作虚拟对象的.scn文件?

ios - 为什么在 ARKit 中将节点添加到检测到的平面下方