【问题标题】:Creating custom geometry in Scenekit在 Scenekit 中创建自定义几何体
【发布时间】:2018-09-10 01:56:38
【问题描述】:

我无法显示我的自定义几何图形。当我调试它时,所有变量似乎都保存了正确的数据,但没有渲染。我刚刚将它设置为尝试渲染由两个三角形组成的单个正方形,以进行非常简单的测试,但仍然没有运气。我觉得我构建 SCNGeometry 是错误的。完成所有逻辑/循环/魔术后,我有以下内容:

var verts = SCNGeometrySource(vertices: meshVertices)
var norms = SCNGeometrySource(normals: normals)
var element = SCNGeometryElement(indices: triangleIndices, primitiveType: .triangles)

我已经尝试了以下两种方法来创建 SCNGeometry。两者都不渲染,尽管 showStatistics 确实表明有两个三角形。奇怪的是,当我触摸屏幕尝试移动相机时,三角形总数跳到了 2.74K...

let newGeo = SCNGeometry(sources: [verts, norms], elements: [element])

-

var sources = [SCNGeometrySource]()
sources.append(verts)
sources.append(norms)
let newGeo = SCNGeometrySource(sources: sources, elements: [element])

除非我完全误解了某些东西,否则我真的不确定下一步该尝试什么。

确认一下,这是我变量中的数据:

meshVertices = ([SCNVector3])
    [0]: x = (Float) 0, y = (Float) 0, z = (Float) 0
    [1]: x = (Float) 1, y = (Float) 0, z = (Float) 0
    [2]: x = (Float) 0, y = (Float) 1, z = (Float) 0
    [3]: x = (Float) 1, y = (Float) 1, z = (Float) 0

normals = ([SCNVector3])
    [0]: x = (Float) 0, y = (Float) 0, z = (Float) 1
    [1]: x = (Float) 0, y = (Float) 0, z = (Float) 1
    [2]: x = (Float) 0, y = (Float) 0, z = (Float) 1
    [3]: x = (Float) 0, y = (Float) 0, z = (Float) 1

triangleIndices = ([Int])
    [0]: 3
    [1]: 2
    [2]: 0
    [3]: 3
    [4]: 0
    [5]: 1

让 SCNPlane、SCNBox 或其他要渲染的东西没有问题,所以我认为问题不存在。问题似乎在于我如何创建几何。我很确定我的顶点、法线和索引是正确的,所以在尝试创建由 SCNGeometrySource 和 SCNGeometryElement 组成的最终 SCNGeometry 对象时,我一定做错了。

【问题讨论】:

    标签: ios scenekit


    【解决方案1】:

    虽然可能有点晚了。希望这个答案也可以帮助其他人。

    指定索引时,请不要使用Int 类型。似乎在使用 SceneKit 时(或者它可能是更深层次的东西,比如 Metal/OpenGL?我不确定),Int 类型不考虑在内。请在此处使用UInt32UInt8 作为索引。

    【讨论】:

    • 谢谢,帮我省了些麻烦。
    猜你喜欢
    • 2016-11-25
    • 2023-04-10
    • 2016-03-12
    • 2017-11-12
    • 2018-01-20
    • 2016-04-01
    • 2018-08-06
    • 2018-03-05
    • 2019-09-24
    相关资源
    最近更新 更多