CollisionEvent 在 RealityKit 场景中没有触发的原因?



Event 订阅已添加到RealityKitARViewscene

arView.scene.subscribe(to: CollisionEvents.Began.self) { event in
print("Some collision occured")
}

Entitiesscene中发生视觉碰撞,但CollisionEvent没有被发射。以下是明显冲突的对象的 2 个示例层次结构:

▿ "篮板" : __RKPhysics, 儿童: 1...⟐ 物理运动组件
...⟐ 变换
...⟐ 碰撞组件
...⟐ 同步组件
...⟐ 物理车身组件
...▿ "simpBld_root" : 模型实体
......⟐ 变换
...⟐ 模型组件
......⟐ 同步组件

CollisionComponent

CollisionComponent(

shapes: [RealityKit.ShapeResource], mode: RealityKit.CollisionComponent.Mode.default, filter: RealityKit.CollisionFilter(group: RealityKit.CollisionGroup(rawValue: 1), mask: RealityKit.CollisionGroup(rawValue: 1)))

▿ "球":模型实体 ...⟐ 变换
...⟐ 碰撞组件
...⟐ 模型组件
...⟐ 同步组件
...⟐ 物理车身组件

CollisionComponent

CollisionComponent(

shapes: [RealityKit.ShapeResource], mode: RealityKit.CollisionComponent.Mode.default, filter: RealityKit.CollisionFilter(group: RealityKit.CollisionGroup(rawValue: 1), mask: RealityKit.CollisionGroup(rawValue: 4294967295)))

命名Entities已被添加到被视为AnchorEntity的一部分:

let anchorEntity = AnchorEntity(anchor: anchor)
anchorEntity.addChild(backboardEntity)
anchorEntity.addChild(ballEntity)
arView.scene.anchors.append(anchorEntity)

为什么没有CollisionEvents不被解雇?

这段代码是不言自明的:

import RealityKit
import Combine
class ViewController: UIViewController {

@IBOutlet var arView: ARView!
var subscriptions: [Cancellable] = []

override func viewDidLoad() {
super.viewDidLoad()            
let modelOne = ModelEntity(mesh: .generateSphere(radius: 0.04)) 
as (Entity & HasCollision & HasPhysicsBody)
let modelTwo = ModelEntity(mesh: .generateSphere(radius: 0.04)) 
as (Entity & HasCollision & HasPhysicsBody)

modelOne.position.y = 0.75
modelOne.physicsBody = .init()
modelOne.physicsBody?.mode = .dynamic
modelOne.generateCollisionShapes(recursive: false)            
modelTwo.physicsBody = .init()
modelTwo.physicsBody?.mode = .static
modelTwo.generateCollisionShapes(recursive: false)

let sub = arView.scene.subscribe(to: CollisionEvents.Began.self, 
on: modelOne) { _ in print("OCCURED!") }
subscriptions.append(sub)

let anchor = AnchorEntity()
anchor.addChild(modelOne)
anchor.addChild(modelTwo)
arView.scene.anchors.append(anchor)
}
}

相关内容

  • 没有找到相关文章

最新更新