【问题标题】:RealityKit – Proper Hit-Testing in ARViewRealityKit – ARView 中的正确命中测试
【发布时间】:2020-10-23 01:32:32
【问题描述】:

我有这样的代码:

@objc func handleTap(_ sender: UITapGestureRecognizer) {
    
    let tapLocation = sender.location(in: arView)
    
    let hitResult0 = scnView?.hitTest(tapLocation)

    if let hitResult = arView?.entity(at: tapLocation) {
         // ...
    }
}

hitResult 给出的精度很差。即使我点击了另一个较小的实体,它也会返回相同的实体 (WheelbarrowHandles)。 hitResult0 提供靠近点击位置的所有对象(太多)。

模型加载:

self.theModel = try! Entity.load(named: "wheelborrow")
self.theModel?.generateCollisionShapes(recursive: true)

是否生成了错误的碰撞形状?


更新

我试图做下一代而不是一代:

modelEntity.collision = CollisionComponent(shapes: [ShapeResource.generateConvex(from: modelEntity.model!.mesh)])

它有效。

【问题讨论】:

标签: swift augmented-reality hittest realitykit usdz


【解决方案1】:

生成的碰撞形状:

generateCollisionShapes(recursive: true)

接下来的代码:

modelEntity.collision = CollisionComponent(shapes: [ShapeResource.generateConvex(from: modelEntity.model!.mesh)])

【讨论】:

  • 这太棒了,感谢您提供此信息!。另外你是如何可视化形状/线框的? :O
  • debugOptions.insert(ARView.DebugOptions.showPhysics)
猜你喜欢
  • 2020-05-11
  • 2021-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 2020-04-28
  • 2021-09-25
  • 2021-04-29
相关资源
最近更新 更多