3

I'm currently following David Roonqvist's 3D Graphics with SceneKit book.

Chapter 5 deals with hit testing, no issues implementing it, but only deals with his testing from mouse events.

Now, I know my camera's orientation will ALWAYS intersect a certain geometry.

I need to obtain the texture coordinate of the intersecting point between the camera orientation and the geometry.

Any pointers as how to go about it? I've been looking all over without much success.

Any help is appreciated.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
David Homes
  • 2,725
  • 8
  • 33
  • 53

1 Answers1

2

I haven't tried this but...

SCNHitTestResult returns, among other things, textureCoordinatesWithMappingChannel(_:). Documentation cites the example of adding scorch marks to a game character's texture after it's been hit by a laser.

It appears that SCNNode's

hitTestWithSegmentFromPoint(_ pointA: SCNVector3,
                     toPoint pointB: SCNVector3,
                     options options: [String : AnyObject]?) -> [SCNHitTestResult]

will give you the hits you need, between the camera and the geometry, regardless of the orientation of the camera. If the camera and the target are using different local node coordinate systems, you'll have to do some conversion using convertPosition(_:from:Node:) or similar functions.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • hay Hal, I ended up applying SCNSceneRenderer.hitTest(.... but thanks for also valid answer! – David Homes Nov 05 '15 at 04:27
  • Great! Please post your solution as an answer, and then accept that answer, so the question will show up as closed. Plus, I'd love to see a bit more detail on how you used SCNSceneRenderer! – Hal Mueller Nov 05 '15 at 04:34
  • sceneView.delegate = self, then implemented: func renderer(renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: NSTimeInterval) { renderer.hitTest(midpoint, options: nil) that gave the same [SCNHitTestResult] – David Homes Nov 05 '15 at 04:39