Ignoring an object in hittest
Asked Answered
H

1

5

Is it possible to ignore an object in SceneKit's hitTest so that when the hitTest ray is sent, it goes through an object? I still want to see both objects, i just want the ray to ignore another.

Here the top image shows how it works now, and the bottom is what i'd like to have.

enter image description here

I think that it would be possible by putting the sphere to another view, but i don't think that i could see the object then.

Hhour answered 7/5, 2017 at 13:41 Comment(0)
O
7

when performing the hit test you can use the SCNHitTestOptionCategoryBitMask option to restrict the set of nodes that are tested.

Nodes have a categoryBitMask property and only the ones for which the following condition is satisfied will participate in the hit test:

node.categoryBitMask & hitTestOptionCategoryBitMask != 0
Odele answered 7/5, 2017 at 14:52 Comment(4)
hitTestOptionCategoryBitMask is not a SceneKit API. This is just a placeholder for the variable/value you will use for the value associated to the SCNHitTestOptionCategoryBitMask key in the hit test options dictionary.Odele
I am not sure if you understood, i want to be able to hittest the plane, even if there is another object in between the camera and the plane. I think that when hittesting, by doing something like if node.categorybitmask == 1 {..} it just won't hittestHhour
The formula shows what SceneKit will do internally to decide whether the node should participate in the hit test. This is not something that you have have to do. The only thing you have to change is to set a bit mask to your plane, and specify a bit mask as an option when performing the hit test.Odele
var hitResults = scnView.hitTest(location, options: [SCNHitTestOption.categoryBitMask : 10]) This is what i was able to do without errors. But this doesn't do anything. In your example you somehow had the bool in there, but i couldn't get [SCNHitTestOption.categoryBitMask != 0] to work.Hhour

© 2022 - 2024 — McMap. All rights reserved.