gpt4 book ai didi

ios - 从 SceneKit 中的 SCNNode 中提取几何信息

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:28 24 4
gpt4 key购买 nike

我正在尝试为场景中的每个节点提取几何体。我使用 .obj 文件创建了一个场景,它呈现得非常完美。但是,我想从每个节点中提取几何图形,但我被卡住了。我的代码在下面

    let scn = SCNScene(named: "d.obj")

for i in scn!.rootNode.childNodes {
for a in i.childNodes {
for b in a.childNodes {
let element = b.geometry!.geometryElementAtIndex(0)
let source = b.geometry!.geometrySources[0]
var z: Float = 0
source.data.getBytes(&z, length: sizeof(Float))
print(z)
}
}

我想获取位置和法线,以便将它们存储在数据库中。

最佳答案

在您的代码中,您使用 let source = b.geometry!.geometrySources[0]

我建议您遍历所有源:b.geometry!.geometrySources

然后在循环中测试它是哪种来源:b.geometry!.geometrySources[i].semantic

这个 .semantic 属性可以有几个不同的值:

 NSString *const SCNGeometrySourceSemanticVertex;
NSString *const SCNGeometrySourceSemanticNormal;
NSString *const SCNGeometrySourceSemanticColor;
NSString *const SCNGeometrySourceSemanticTexcoord;
NSString *const SCNGeometrySourceSemanticVertexCrease;
NSString *const SCNGeometrySourceSemanticEdgeCrease;
NSString *const SCNGeometrySourceSemanticBoneWeights;
NSString *const SCNGeometrySourceSemanticBoneIndices;

然后,根据源的类型,做任何你想做的事情!

关于ios - 从 SceneKit 中的 SCNNode 中提取几何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38927856/

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