【问题标题】:iOS ARView.hitTest limited to a max of 100 metersiOS ARView.hitTest 限制为最大 100 米
【发布时间】:2021-07-05 18:13:24
【问题描述】:

我发现ARView.hitTest 被限制在 100 米的距离内。 距离超过 100m 的所有物体,无论大小,都无法识别。

有什么办法可以解封吗?

let hitTest = arView.hitTest(point, query: .any, mask: .all)

【问题讨论】:

    标签: ios swift augmented-reality hittest realitykit


    【解决方案1】:

    没错,hitTest(_:query:mask:) 实例方法的距离限制目前是 100 米。但是你可以实现raycast(from:to:)方法,让你从任何场景点向任何方向射出一条射线,即使距离是1000米。

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    
        let cameraPosition = arView.cameraTransform.translation
        
        let castHits = arView.scene.raycast(from: cameraPosition, to: [0, 0,-1000])
        
        guard let hitTest: CollisionCastHit = castHits.first else { return }
        
        print(hitTest.distance)
    }
    


    更新:

    另外,正如@Sacha 建议的那样,我们可以使用实例方法ray(through:) 来确定通过视图2D 空间中给定点的射线的位置和方向。它返回可选的元组(origin: SIMD3&lt;Float&gt;, direction: SIMD3&lt;Float&gt;)?,适合raycast(from:to:)方法的参数。

    【讨论】:

    • 感谢@Andy,在这种情况下,向量 [0, 0,-10000] 会与屏幕正交吗?其实我想做的是实现不受距离限制地触摸物体的能力
    • 找到了使用方法:let ray = arView.ray(through: tapPoint), let results = arView.scene.raycast(origin: ray.origin, direction: ray.direction, length : 1000, 查询: .nearest)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    相关资源
    最近更新 更多