swift - RealityKit – ARView 中的正确命中测试
问题描述
我有这样的代码:
@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)])
它有效。
解决方案
推荐阅读
- angular - PrimeNG 添加自定义标题文本
- android - Android 12 飞溅白色背景
- visual-studio-code - 无论如何在关闭内核之前将环境变量保存在vscode jupyter中?
- r - ggcorrplot,多列,按因子分组
- c# - 如何在应用程序中提供虚拟目录路径
- sql - 在运行时使用 JDBCTemplate 创建表
- javascript - 打字稿的fineOneAndUpdate错误:“文档”类型上不存在属性“findOneAndUpdate”
. 猫鼬 - django - 在没有端口号的 ubuntu 网络服务器上加载 Flask 应用程序
- flutter - 如何处理稍后初始化的不可空变量?
- sql - 如何在 Sql 中加入表?