问题描述
我绘制了一个包含 SCNGeometryElement 对象的场景.(这是一个地形.我每个网格项目有 2 个三角形)为了优化,我决定用 TriangleStrip 替换我的三角形基元.但它没有给我相同的结果
I have draw a scene which contains a SCNGeometryElement object. (it is a terrain. I have 2 triangles per grid item)In order to optimize, i decided to remplace my triangle primitive by TriangleStrip.But it does not give me the same result
我的顶点数组是连续的 4 个点:
My Vertex array is a succession of 4 points:
C D
A B
我的索引数组包含 A、C、B 和 D 的索引因此,当我使用 TriangleStrip 时,场景套件应该绘制 ACB 和 CBD 三角形.这是苹果文档中所说的.
My indices array contains index of A, C, B and DSo when i work with TriangleStrip, scene kit is supposed to draw ACB and CBD triangles. That is what is said in apple documentation.
我想知道应该在primitivecount中放什么.我尝试了几件事.它改变了渲染,但我无法用简单的三角形检索到与之前相同的结果......
I am wondering what i should put in primitivecount. I tried several things. It changes the rendering but i can not retrieve the same result i had before with simple triangles...
有什么想法吗?
谢谢
let element = SCNGeometryElement(data: buffer_indices , primitiveType: .TriangleStrip, primitiveCount: Int(points_count), bytesPerIndex: sizeof(CInt))
推荐答案
对于三角形条带,primitiveCount
应该等于 indexCount - 2
.
For a triangle strip the primitiveCount
should be equal to indexCount - 2
.
或者,您可以使用 Swift 友好的 SCNGeometryElement(indices:originalType:)
(另见这篇文章).
Alternatively you can use the Swift-friendly SCNGeometryElement(indices:primitiveType:)
(see also this post).
这篇关于SceneKit SCNGeometryElement TriangleStrip 与三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!