如何移动模型并同时生成其碰撞形状?

How to move a model and generate its collision shape at the same time?

我在 SwiftUI 中有 ModelEntity,它会移动。但问题是:添加generateCollisionShape方法时,它不再移动了。

我想要碰撞效果以及移动实体 我怎样才能两者兼得?

modelEntityClone.generateCollisionShapes(recursive: true)

modelEntityClone.physicsBody = PhysicsBodyComponent(massProperties: .default, 
                                                          material: .default, 
                                                              mode: .dynamic)

希望这个技巧一定能帮到您。这种物理学永远存在。 ))

struct ARViewContainer: UIViewRepresentable {
    
    let ball = ModelEntity(mesh: .generateSphere(radius: 0.5))
    let anchor = AnchorEntity()
    
    func makeUIView(context: Context) -> ARView {

        let arView = ARView(frame: .zero)

        ball.physicsBody = .init()
        ball.physicsBody?.massProperties.mass = 0

        ball.physicsMotion = .init()
        ball.physicsMotion?.linearVelocity.x = 1.0
        ball.physicsMotion?.angularVelocity.z = -.pi

        ball.position.x = -4.0
        ball.generateCollisionShapes(recursive: true)
        anchor.addChild(ball)

        anchor.position.z = -3.0
        arView.scene.addAnchor(anchor)
        return arView
    }

    func updateUIView(_ uiView: ARView, context: Context) { }
}