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

3
我正在尝试提取场景中每个节点的几何图形。我使用一个 .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)
            }
        }

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

1个回答

2

在你的代码中,你使用了 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;

然后,根据来源类型,您可以随心所欲地进行操作!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接