2

I am using the following method to determine which SCNNodes are visible by the camera.

[self.scnView nodesInsideFrustumWithPointOfView:cameraNode];

However the returned array is always empty. I set up the scene up as follows:

-(void)setupScene{
scene = [SCNScene scene];

cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
[scene.rootNode addChildNode:cameraNode];
cameraNode.position = SCNVector3Make(0, 0, 0);

[scene.rootNode addChildNode:cameraNode];

self.scnView.scene = scene;
self.scnView.showsStatistics = YES;
self.scnView.backgroundColor = [UIColor clearColor];
}

At a random time, after the scene is created, I add a SCNNode to the scene:

testnode = [Testnode createNode];
testnode.position = SCNVector3Make(0, 0, -10);
[self.scnView.scene.rootNode addChildNode:testnode];

On my device, the node "testnode" is visible on my screen yet nodesInsideFrustumWithPointOfView: returns nothing.

EDIT: I tried changing the point of view to a spot light object and test whether "testnode" is inside its frustum. Here is what I see on screen: https://i.stack.imgur.com/ZMr6b.jpg Yet the array still returns empty. The testnode is the white cube.

SMD01
  • 101
  • 1
  • 13
  • Same experience. Did you find a fix? – Crashalot Sep 18 '16 at 01:09
  • @Crashalot I did! Forgot to write it here though. Hopefully it applies to you as well. It seems both isNodeInsideFrustum and nodesInsideFrustumWithPointOfView were not detecting nodes that were children of nodes with null geometry. In my case, the node was a particle system which was the child of a node with null geometry. – SMD01 Sep 18 '16 at 02:50
  • Hmm ok, kinda makes sense if the hit testing requires geometry to work. Perhaps post this as an answer so future readers can benefit? – Crashalot Sep 18 '16 at 04:10

1 Answers1

1

Adding this for better visibility. Thank Crashalot for this.

Basically, if the SCNNode you are trying to detect using [scnView nodesInsideFrustumWithPointOfView:] and [scnView isNodeInsideFrustum: withPointOfView:] is the child of a node with empty geometry, it won't be detected.

In my case, I added a plane geometry and set the material to transparent:

SCNNode *emptynode = [SCNNode node];
node.geometry = [SCNPlane planeWithWidth:1.0f height:2.0f];
node.geometry.firstMaterial.transparency = 0.0f;
SMD01
  • 101
  • 1
  • 13