处理Swift(c3drenderContextBindMeshElement)时出现奇怪的运行时场景基特错误

处理Swift(c3drenderContextBindMeshElement)时出现奇怪的运行时场景基特错误,swift,macos,graphics,rendering,scenekit,Swift,Macos,Graphics,Rendering,Scenekit,所以,当我运行我的程序时,每当相机看到我想渲染的自定义几何体时,我总是会遇到一个奇怪的错误。我根据参数化曲面位置和法线的均匀采样创建了一组三角形,错误如下: SceneKit: error, C3DRendererContextBindMeshElement unsupported byte per index (8) 它在控制台中多次打印出来。我很难在网上找到任何真实的上下文,基于代码,它有点神秘。代码如下: let sampling = 5 //Returns an ar

所以,当我运行我的程序时,每当相机看到我想渲染的自定义几何体时,我总是会遇到一个奇怪的错误。我根据参数化曲面位置和法线的均匀采样创建了一组三角形,错误如下:

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)

我不知道我哪里出了问题,也不知道错误是什么,甚至我都不知道。非常感谢您的帮助。

您正在使用64位整数Int,8字节作为索引,这是不受支持的。您可以将索引声明为UInt16数组来解决此问题

您正在使用64位整数Int,8字节作为索引,这是不受支持的。您可以将索引声明为UInt16数组来解决此问题

天哪!真不敢相信我居然没看到!非常感谢你!哦,我的上帝!真不敢相信我居然没看到!非常感谢你!
struct parametricVertex {
    var x: Float, y: Float, z: Float      //Positions
    var nx: Float, ny: Float, nz: Float   //Normals
}