SCNGeometry / SCNCylinder render only edges / borders (keep color, clear contents)

I am trying to figure out how to have SCNScylinder on sceen with only border / stroke / edge visible. Everything in my scene works great, and I was thinking about just applying a clear color to specular.contents

uses delegate use SCNNode / Metal code (I do not use opengl on my stage)

Any pointers? help is appreciated

+4
source share
3 answers

WWDC 2014 , . , . AAPLSlideScenegraphSummary.m:

        // A node that will help visualize the position of the stars
        _wireframeBoxNode = [SCNNode node];
        _wireframeBoxNode.rotation = SCNVector4Make(0, 1, 0, M_PI_4);
        _wireframeBoxNode.geometry = [SCNBox boxWithWidth:1 height:1 length:1 chamferRadius:0];
        _wireframeBoxNode.geometry.firstMaterial.diffuse.contents = [NSImage imageNamed:@"box_wireframe"];
        _wireframeBoxNode.geometry.firstMaterial.lightingModelName = SCNLightingModelConstant; // no lighting
        _wireframeBoxNode.geometry.firstMaterial.doubleSided = YES; // double sided

enter image description here

SCNCylinder , , .

Edit

High Sierra/iOS 11 by @mnuages ​​- / .

+3

, geometryElements geometrySources, SCNGeometry primitiveType SCNGeometryPrimitiveTypeLine

Edit

iOS 11 SCNMaterial fillMode, .

+4

, , - ARKit.

First, I created a square image in Adobe Illustrator, which had green edges but a transparent center. This is called "outlinedFace."

Then I created SCNNode (Swift 4) as follows:

import UIKit
import ARKit

class CubeNode: SCNNode {

private var faceArray = [SCNMaterial]()
private let FACE_OUTLINE = "outlinedFace"

/// Initialization With Outline Only
///
/// - Parameters:
///   - width: Optional CGFloat (Defaults To 20cm)
///   - height: Optional CGFloat (Defaults To 20cm)
///   - length: Optional CGFloat (Defaults To 20cm)
///   - colours: [UIColor] - [Front, Right , Back , Left, Top , Bottom]
init(width: CGFloat = 0.2, height: CGFloat = 0.2, length: CGFloat = 0.2) {

    super.init()

    self.geometry = SCNBox(width: width, height: height, length: length, chamferRadius: 0)

        for _ in 0 ..< 6{
            let face = SCNMaterial()
            face.diffuse.contents = UIImage(named: FACE_OUTLINE)
            face.isDoubleSided = true
            face.lightingModel = .constant
            faceArray.append(face)
        }

    self.geometry?.materials = faceArray
    self.rotation = SCNVector4Make(0, 1, 0, .pi / 4)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

}

The key here is to make the content double-sided.

It works wonderfully for me!

0
source

All Articles