【发布时间】: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)])
它有效。
【问题讨论】:
-
要了解命中测试和光线投射的工作原理,请查看这篇文章 - stackoverflow.com/questions/56466773/…、这篇文章 - stackoverflow.com/questions/56736645/… 和这篇文章 - stackoverflow.com/questions/60294367/…
-
Tnx,@AndyFedoroff。我会尝试 raycasting 和 writeback。
标签: swift augmented-reality hittest realitykit usdz