【发布时间】:2016-02-05 10:40:46
【问题描述】:
所以,当我运行我的程序时,每当相机查看(我认为)我尝试渲染的自定义几何体时,我都会收到一个奇怪的错误。我根据参数表面(位置和法线)的均匀采样创建了一堆三角形这是错误:
SceneKit: error, C3DRendererContextBindMeshElement unsupported byte per index (8)
它会在控制台中多次打印出来。我很难在网上找到任何真实的上下文,并且基于代码它有点神秘。代码如下:
let sampling = 5
//Returns an array of parametricVertex of 25 points (5 by 5) (grid of points on surface)
let points = object.getParametricVertexArray(sampling, vPoints: sampling)
print(points.count)
// Organize the points into triangles.
var indices = [Int]()
var stripStart = 0
for var i = 0; i < (sampling - 1); i++, stripStart += sampling {
for var j = 0; j < (sampling - 1); j++ {
let v1 = stripStart + j
let v2 = stripStart + j + 1
let v3 = stripStart + (sampling) + j
let v4 = stripStart + (sampling) + j + 1
indices.append(v4)
indices.append(v2)
indices.append(v3)
indices.append(v1)
indices.append(v3)
indices.append(v2)
}
}
let data = NSData.init(
bytes: points,
length: points.count * sizeof(parametricVertex)
)
let source = SCNGeometrySource.init(
data: data,
semantic: SCNGeometrySourceSemanticVertex,
vectorCount: points.count,
floatComponents: true,
componentsPerVector: 3,
bytesPerComponent: sizeof(Float),
dataOffset: 0,
dataStride: sizeof(parametricVertex)
)
let normalSource = SCNGeometrySource.init(
data: data,
semantic: SCNGeometrySourceSemanticNormal,
vectorCount: points.count,
floatComponents: true,
componentsPerVector: 3,
bytesPerComponent: sizeof(Float),
dataOffset: sizeof(Float) * 3,
dataStride: sizeof(parametricVertex)
)
let element = SCNGeometryElement.init(
data: NSData.init(
bytes: indices,
length: sizeof(Int) * indices.count
),
primitiveType: SCNGeometryPrimitiveType.Triangles,
primitiveCount: indices.count / 3,
bytesPerIndex: sizeof(Int)
)
let surfaceGeo = SCNGeometry.init(sources: [source, normalSource], elements: [element])
surfaceGeo.firstMaterial?.doubleSided = true
let newNode = SCNNode(geometry: surfaceGeo)
scene.rootNode.addChildNode(newNode)
参数顶点在哪里:
struct parametricVertex {
var x: Float, y: Float, z: Float //Positions
var nx: Float, ny: Float, nz: Float //Normals
}
我不知道我哪里出错了,也不知道错误试图告诉我什么。任何帮助将不胜感激。
【问题讨论】:
标签: swift macos graphics rendering scenekit