复杂“.DAE”对象的 SceneKit 自定义形状

SceneKit custom shapes for complex ".DAE" objects

问题 1:

与基本对象发生碰撞的代码 - 管无法正常工作:

    let tubeGeometry = SCNTube(innerRadius: 2, outerRadius: 2.5, height: 2)
    let tubeMaterial = SCNMaterial()
    tubeMaterial.diffuse.contents = UIColor.green
    tubeGeometry.materials = [tubeMaterial]

    let tubeNode = SCNNode(geometry: tubeGeometry)
    tubeNode.position = SCNVector3(0, 0, 0)

    let tubeShape = SCNPhysicsShape(geometry: tubeGeometry, options: nil)
    let tubeBody = SCNPhysicsBody(type: .dynamic, shape: tubeShape)

    tubeNode.physicsBody?.categoryBitMask = collisionTube
    tubeNode.physicsBody?.collisionBitMask = collsionTarget
    tubeNode.physicsBody?.mass = 1
    tubeNode.physicsBody = tubeBody

    scene.rootNode.addChildNode(tubeNode)

截图:

为什么球在物体的顶部?

问题 2:

我仔细阅读了 类 SCNPhysicsShapeSCNPhysicsBody

的使用手册

研究了对 DAE 对象施加约束的所有可能方法。 并得出结论,所有限制都必须在对象的单个物理模型中对复杂的 SCNNode 束进行编程。

找到非常有趣的答案:

我真的希望有一种方法可以制作类似 let DAEShape = SCNPhysicsShape(geometry: "*.DAE")... 的方法,否则复杂对象的设置冲突可能需要一个月或更长时间的开发。

比如复杂管"DAE"物体的碰撞如何设计,如截图所示,有什么建议吗?

问题不在于性能,而在于以最直接的方式对复杂 3D 对象实施复杂约束的能力,从而避免编程的繁琐...

如何使用 "DAE" 对象的顶点、边和面设置物理约束?

我真的希望答案是... 提前致谢!

    let url = Bundle.main.url(forResource: "art.scnassets/half", withExtension: "dae")
    let sceneSource = SCNSceneSource(url: url!, options: nil)
    let tubeGeometry = (sceneSource?.entryWithIdentifier("Cube-mesh", withClass: SCNGeometry.self ))! as SCNGeometry

    tubeNode = SCNNode(geometry: tubeGeometry)
    tubeNode.position = SCNVector3(0, 1, 0)
    tubeNode.eulerAngles = SCNVector3Make(1.5, 2, 0)
    tubeNode.physicsBody = SCNPhysicsBody(type: .static, shape: SCNPhysicsShape(geometry: tubeGeometry, options: [SCNPhysicsShape.Option.type: SCNPhysicsShape.ShapeType.concavePolyhedron]))
    scene.rootNode.addChildNode(tubeNode)