gpt4 book ai didi

ios - 在 Scenekit 中创建自定义几何体

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:29:55 25 4
gpt4 key购买 nike

我无法显示我的自定义几何图形。当我调试它时,所有变量似乎都保存着正确的数据,但没有任何渲染。我刚刚将其设置为尝试渲染由两个三角形组成的单个正方形以进行非常简单的测试,但仍然没有成功。我觉得我构建的 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 对象时,我一定是做错了什么。

最佳答案

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

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

关于ios - 在 Scenekit 中创建自定义几何体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49584351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com