Using categoryBitMask in hitTest

When i am doing a hitTest, i want a object to be ignored in the hitTest, so that the hitTest ray goes through it. I think that this is possible with a categoryBitMask.

I have a different categoryBitMask for the object that i don't want to be in the hitTest, and different for the ones i do.


This is how i think it should work, but i just need to find the correct way to do this:


var hitResults = scnView.hitTest(location, options: [SCNHitTestOption.categoryBitMask != 10])


With this i get the error that SCNHitTestOption can not be Bool or something like that.

So i want to know what is the correct way to use this option, to ignore objects whose categoryBitMask is 10.

Hi,


You have to specify it as a bitmask. So you would have something like...


enum HitTestType: Int {
    case object1 = 0b0001
    case object2 = 0b0010
}

let bitMask = HitTestType.object1.rawValue | HitTestType.object2.rawValue

let result = scnView.hitTest(point, options: [SCNHitTestOption.categoryBitMask : bitMask])


Haven't tested if the code above really works, but should be enough for you to get the idea.


Oh, you also need to remember to specify the category bitmask for the nodes you want to hit. For example...


let object1Node = SCNNode()
object1Node.categoryBitMask = HitTestType.object1.rawValue


Br,


Teemu

As a tip for specifying the bitmasks you might want to check https://developer.apple.com/documentation/swift/optionset.

Using categoryBitMask in hitTest
 
 
Q