gpt4 book ai didi

ios - 如何使用具有多个对象(几何体)的场景文件中的几何体?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:08:26 27 4
gpt4 key购买 nike

我有一个 blender 文件,我将其导出为 DAE/collada,然后使用 Xcode 将其转换为 Scenekit 的场景文件。我在使用场景文件中的几何体时遇到问题。

场景文件(“model.scn”)非常基础:

  • 组(无几何元素)
    • Shape1(几何元素)
    • Shape2(几何元素)
    • Shape3(几何元素)

当我尝试使用该模型时,我无法将 3 种形状的组合几何用于与 SCNPhysicsBody 一起使用的 SCNGeometry。

我试过各种方法,但都不管用:

方法一

let scene = SCNScene(named: "art.scnassets/model.scn")!
let node = scene.rootNode.childNode(withName: "Group", recursively: true)!
guard let geo = node.geometry else { return }
// node.geometry is nil so returns here

let physicsBody = SCNPhysicsBody(type: .kinematic, shape: SCNPhysicsShape(geometry: geo))
// this is what I need the custom/aggregate geometry for

方法二

let scene = SCNScene(named: "art.scnassets/model.scn")!
let geoNode = SCNNode()
let node1 = scene.rootNode.childNode(withName: "Shape1", recursively: true)!
let node2 = scene.rootNode.childNode(withName: "Shape2", recursively: true)!
let node3 = scene.rootNode.childNode(withName: "Shape3", recursively: true)!
geoNode.addChildNode(node1)
geoNode.addChildNode(node2)
geoNode.addChildNode(node3)

// expected geoNode.geometry is not nil, but it is

根据 Apple's documentation

A node can have only one geometry attached to it. To combine geometries so they can be controlled or animated together, create a node with no geometry and add other nodes to it.

但它似乎没有工作,因为父节点的可选几何图形仍然为零。

我想做的应该很简单,但我的做法是错误的。我想使用我的 dae/collada/scene 文件中的几何体。我不想使用默认值(立方体、圆柱体、棱锥体、球体、圆环体等)。

我做错了什么?谢谢!

最佳答案

SceneKit 不会自动为您合并 SCNGeometry 实例。为此,您必须在创建合并的 SCNGeometry 之前创建新的 SCNGeometrySourceSCNGeometryElement 对象。

文档可能有点误导。它想说的是,如果您想同时操作多个几何图形,那么将多个节点分组在一个共同的父节点下将使事情变得更容易,因为操作这个单个节点会影响(平移、旋转、缩放)它的所有子节点。

请注意,在您的情况下,您可以使用 init(shapes:transforms:)显式合并多个 SCNPhysicsShape 实例。首先为每个几何体创建一个形状,然后创建组合形状。 transforms 参数将由 transform 组成节点分组在它们共同的父节点下。

关于ios - 如何使用具有多个对象(几何体)的场景文件中的几何体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45778853/

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