Display SCNGeometry as a wireframe

I am using SceneKit for iOS, and I have the geometry that I want to display as a wireframe. So basically I want to draw only lines, so there are no textures.

I realized that for this you can use the property shaderModifiersused SCNMaterial. Shader modifier example:

material.shaderModifiers = [
    SCNShaderModifierEntryPointFragment: "_output.color.rgb = vec3(1.0) - _output.color.rgb;"
]

This example seems to just invert the output colors. I don't know anything about this GLSL language, which I should use for a shader fragment.

Can someone tell me which code should I use as a shader fragment to draw only around the edges so that the geometry looks like a wireframe?

Or maybe there is a whole different approach to rendering geometry in the form of a wireframe. I would love to hear that.

+4
source share
3 answers

Try setting fillMode stuff to .lines (iOS 11+ and macOS 10.13 +):

sphereNode.geometry?.firstMaterial?.fillMode = .lines

+7
source

Now it is possible (at least in Cocoa):

gameView.debugOptions.insert(SCNDebugOptions.ShowWireframe)

or you can do it interactively if you enable statistics with:

gameView.showsStatistics = true

(gameView is an instance SCNView)

+3
source

() , .

, , , . , ( ) , .

GLSL, .

, GLSL (OpenGL Shading Language). .

, GLSL , (, ) , . ( , , , OpenGL ES , WebGL .)

SceneKit , , , (aka SCNGeometrySource) , , , , . OS X SCNProgram geometryShader /, (.. SceneKit, ). iOS - . , , .


It may be easier to simply draw an object using strings - try creating a new one SCNGeometryfrom the sources and elements of the original (solid) geometry, but SCNGeometryElementuse it when you recreate it SCNPrimitiveTypeLine.

+1
source

All Articles