将SCNGeometry渲染为线框 [英] Render an SCNGeometry as a wireframe
问题描述
我在iOS上使用SceneKit,并且有一个要渲染为线框的几何.所以基本上我只想绘制线条,所以不画纹理.
I'm using SceneKit on iOS and I have a geometry I want to render as a wireframe. So basically I want to draw only the lines, so no textures.
我发现我可以使用所用SCNMaterial
的shaderModifiers
属性来完成此任务.着色器修改器的示例:
I figured out that I could use the shaderModifiers
property of the used SCNMaterial
to accomplish this. Example of a shader modifier:
material.shaderModifiers = [
SCNShaderModifierEntryPointFragment: "_output.color.rgb = vec3(1.0) - _output.color.rgb;"
]
此示例显然简单地反转了输出颜色.对于着色器片段必须使用的"GLSL"语言,我一无所知.
This example apparently simply inverts the output colors. I know nothing about this 'GLSL' language I have to use for the shader fragment.
有人能告诉我应该使用什么代码作为着色器片段,以便仅在边缘附近绘制,以使几何图形看起来像线框吗?
Can anybody tell me what code I should use as the shader fragment to only draw near the edges, to make the geometry look like a wireframe?
或者也许还有其他方法可以将几何图形渲染为线框.我很想听听.
Or maybe there is a whole other approach to render a geometry as a wireframe. I would love to hear it.
推荐答案
Try setting the material fillMode to .lines (iOS 11+, and macOS 10.13+):
sphereNode.geometry?.firstMaterial?.fillMode = .lines
这篇关于将SCNGeometry渲染为线框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!