I had same problem. As some other one already said, a projection matrix in camera was wrong.
It was generated by using projectionMatrix(for:viewportSize:zNear:zFar:) - https://developer.apple.com/documentation/arkit/arcamera/2923539-projectionmatrix but I set that zFar was too short.
After I set zNearz and zFar value properly (e.g. 10.0 meter), I can get some results of hitTest.
Post
Replies
Boosts
Views
Activity
Here is expected results.
It would not be correct in detail, because these are just written down by hand.
Of course, it depends on implementation, but these would be almost right, I think. (Maybe...)
=== registering ===
at: SIMD3<Float>(1.0, 1.0, 2.0) box: GKBox(boxMin: SIMD3<Float>(0.0, 0.0, 1.5), boxMax: SIMD3<Float>(1.5, 1.5, 3.0))
at: SIMD3<Float>(2.0, 2.0, 1.0) box: GKBox(boxMin: SIMD3<Float>(1.5, 1.5, 0.0), boxMax: SIMD3<Float>(3.0, 3.0, 1.5))
at: SIMD3<Float>(2.0, 1.0, 1.0) box: GKBox(boxMin: SIMD3<Float>(1.5, 0.0, 0.0), boxMax: SIMD3<Float>(3.0, 1.5, 1.5))
=== list in elements(at:) ===
SIMD3<Float>(1.0, 1.0, 2.0)
=== elements(in:) ===
SIMD3<Float>(1.0, 1.0, 2.0)
SIMD3<Float>(2.0, 2.0, 1.0)
SIMD3<Float>(2.0, 1.0, 1.0)
I have same issue which looks like bugs of GKOctree
It may be related to this topic.
Here is reproduction code.
import GameplayKit
class point: NSObject {
var vec: simd_float3
init(x: Float, y: Float, z: Float) {
self.vec = simd_float3(x,y,z)
}
}
func test () {
let points = [
point(x: 1, y: 1, z: 2),
point(x: 2, y: 2, z: 1),
point(x: 2, y: 1, z: 1)
]
let min = point(x:0, y: 0, z: 0)
let max = point(x:3, y: 3, z: 3)
let box = GKBox(boxMin: min.vec, boxMax: max.vec)
let tree = GKOctree<point>(boundingBox: box, minimumCellSize: 0.01)
print("=== registering ===")
for p in points {
let node = tree.add(p, at: p.vec)
print("at:", p.vec, "box:", node.box)
}
print("=== list in elements(at:) ===")
for p in tree.elements(at: points[0].vec) {
print(p.vec)
}
print("=== elements(in:) ===")
for p in tree.elements(in: box) {
print(p.vec)
}
}
test()
It generates these results in the following.
=== registering ===
at: SIMD3<Float>(1.0, 1.0, 2.0) box: GKBox(boxMin: SIMD3<Float>(0.4921875, 0.99609375, 1.9921875), boxMax: SIMD3<Float>(0.50390625, 1.0078125, 2.0039062))
at: SIMD3<Float>(2.0, 2.0, 1.0) box: GKBox(boxMin: SIMD3<Float>(0.99609375, 1.9921875, 0.99609375), boxMax: SIMD3<Float>(1.0078125, 2.0039062, 1.0078125))
at: SIMD3<Float>(2.0, 1.0, 1.0) box: GKBox(boxMin: SIMD3<Float>(2.4960938, 0.99609375, 0.4921875), boxMax: SIMD3<Float>(2.5078125, 1.0078125, 0.50390625))
=== list in elements(at:) ===
SIMD3<Float>(1.0, 1.0, 2.0)
=== elements(in:) ===
Results report that each point which added to GKOctree are not in each GTKOctreeNode.box.
And when code specifies box to get elements, it doesn't return any elements at all.
It seems bugs.
Platform: iOS 14.2