I am trying to select an object which has been placed on a detected plane in order to perform various task on it such as rotating through gestures.
In order to search for placed objects and avoid getting hitTestResults of irrelevant nature (eg. selecting the plane or the ARWorldMap itself) I am trying to use hitTest(_:options:) with SCNHitTestOption.categoryBitMask. However it seems as the hitTest returns results of all types, not just objects with the selected categoryBitMask = 5, even though from my understanding categoryBitMask is "An option to search only for objects matching a specified bitmask." How do I fix this problem, and is there a better way to select placed 3D-models in ARKit? Below is the function I have to rotate a 3d-model.
enum BodyType: Int {
case model = 5
}
@objc func panned(recognizer :UIPanGestureRecognizer) {
guard let recognizerView = recognizer.view as? ARSCNView else {return}
let touch = recognizer.location(in: recognizerView)
let translation = recognizer.translation(in: recognizerView)
let hitTestResult = self.sceneView.hitTest(touch, options: [SCNHitTestOption.categoryBitMask: BodyType.model.rawValue])
guard let modelNodeHit = hitTestResult.first?.node.parent else{return}
if recognizer.state == .changed {
self.newAngleY = Float(translation.x) * (Float) (Double.pi) / 180
self.newAngleY += self.currentAngleY
modelNodeHit.eulerAngles.y = self.newAngleY
}else if recognizer.state == .ended {
self.currentAngleY = self.newAngleY
}
}