2 Replies
      Latest reply on Mar 9, 2020 1:28 PM by bill@otherwise.com
      jinukwon Level 1 Level 1 (0 points)

        I'm implementing an example app using ARKit + SceneKit. In order to do hittest on scenekit objects(nodes) in the scene, I used ARSCNView.hittest() and it worked well. However when I draw same scene with SCNRenderer(I'm writing also an offscreen renderer) and try to do hittest with SCNRenderer.hittest() but it doesn't return any results.

         

        I assumed the range of input points should be only inside of GPU viewport which is SCNRenderer.currentViewport. But it doesn't work

         

        Any idea how to do properly do hittest with SCNRenderer?

        Thanks in advance

        • Re: Hittest doesn't work with SCNRenderer
          gchiste Apple Staff Apple Staff (320 points)

          Hello,

           

          Are you converting your view touch/click location to the renderer's viewport coordinate space?

           

          let xScale = drawableSize.width/view.frame.width

          let yScale = drawableSize.height/view.frame.height

          let locationInViewport = CGPoint(x: locationInView.x*xScale, y: locationInView.y*yScale)

           

          renderer.hitTest(locationInViewport, options: nil)

          • Re: Hittest doesn't work with SCNRenderer
            bill@otherwise.com Level 1 Level 1 (0 points)

            I seem to vagely remember this happening to me.  I believe the renderer has to actually render the nodes for hit testing to occur.  Is it possible the rendering is not happening (you mentioned something about an offscreen renderer)?

             

            In my case I was trying to increase the size of some small nodes so they could be more easily tapped.  I think I changed their scale before the hit test and then restored it afterwards.  This didn't work because the hit test used the cached bounding box when the object was last rendered.

             

            As an aside, I did solve my problem by changing the boundingBox of the node before rendering .  This doesn't afffect the rendering but does affect the hit testing.