SceneKit-无法使用位掩码进行查询
SceneKit- Cannot query using bitmask
我们能够使用位掩码进行自定义光线投射:
let hitTest = sceneView.hitTest(location, options: [categoryBitMask: bitmask])
但 hitTest 现在已被弃用,我不知道如何为光线投射查询设置位掩码:
let query = sceneView.raycastQuery(from: location, allowing: .estimatedPlane, alignment: .horizontal)
SceneKit
在 SceneKit 中,您可以在 [SCNHitTestResult] 的上下文中使用位掩码。 hitTest(_:options:)
实例方法尚未弃用,它在 iOS 15.4.
中有效
let sceneView = ARSCNView(frame: .zero)
enum HitTestType: Int {
case object_A = 0b00000001
case object_B = 0b00000010
}
let point: CGPoint = gesture.location(in: self.sceneView)
let bitMask = HitTestType.object_A.rawValue | HitTestType.object_B.rawValue
let results = sceneView.hitTest(point, options: [.categoryBitMask: bitMask])
P.S.
目前只有 hitTest(_:types:) 被弃用。
RealityKit
在 RealityKit 中,您可以在 CollisionCastHit 的上下文中使用位掩码:
let arView = ARView(frame: .zero)
let point: CGPoint = gesture.location(in: self.arView)
let (origin, direction) = arView.ray(through: point)!
let raycasts: [CollisionCastHit] = arView.scene.raycast(origin: origin,
direction: direction,
length: 50,
query: .any,
mask: .default,
relativeTo: nil)
...或者这样:
let raycasts: [CollisionCastHit] = arView.hitTest(point,
query: .any,
mask: .default)
我们能够使用位掩码进行自定义光线投射:
let hitTest = sceneView.hitTest(location, options: [categoryBitMask: bitmask])
但 hitTest 现在已被弃用,我不知道如何为光线投射查询设置位掩码:
let query = sceneView.raycastQuery(from: location, allowing: .estimatedPlane, alignment: .horizontal)
SceneKit
在 SceneKit 中,您可以在 [SCNHitTestResult] 的上下文中使用位掩码。 hitTest(_:options:)
实例方法尚未弃用,它在 iOS 15.4.
let sceneView = ARSCNView(frame: .zero)
enum HitTestType: Int {
case object_A = 0b00000001
case object_B = 0b00000010
}
let point: CGPoint = gesture.location(in: self.sceneView)
let bitMask = HitTestType.object_A.rawValue | HitTestType.object_B.rawValue
let results = sceneView.hitTest(point, options: [.categoryBitMask: bitMask])
P.S.
目前只有 hitTest(_:types:) 被弃用。
RealityKit
在 RealityKit 中,您可以在 CollisionCastHit 的上下文中使用位掩码:
let arView = ARView(frame: .zero)
let point: CGPoint = gesture.location(in: self.arView)
let (origin, direction) = arView.ray(through: point)!
let raycasts: [CollisionCastHit] = arView.scene.raycast(origin: origin,
direction: direction,
length: 50,
query: .any,
mask: .default,
relativeTo: nil)
...或者这样:
let raycasts: [CollisionCastHit] = arView.hitTest(point,
query: .any,
mask: .default)