Roo
Roo

Reputation: 279

SCNNode getBoundingBoxMin

I have a node that I'm extracting from an SCNScene. I've got some information about it, but I'm confused about one thing - how the bounding box is calculated. The node is positioned once it is loaded at vector 0,0,0 using:

[myNode setPosition: SCNVector3Make(0, 0, 0)];

However, the bounding box still reports a min.x of -1.

How can this be if I've just positioned it at 0? Additionally, it doesn't matter what vector values I give, it always has a min.x of -1 - despite the node actually moving around screen as expected.

Upvotes: 0

Views: 742

Answers (1)

rickster
rickster

Reputation: 126137

It's hard to answer definitively without more information about what's in your scene and what you're doing with it, but it's probably one or both of these issues:

The bounding box tells you the extent of the node's content, not its position — e.g. if you have a cube 2 units wide positioned at (0, 0, 0), its bounding box min and max corners will be (-1, -1, -1) and (1, 1, 1).

Depending on what tricks you're using to move your node around, the node itself may not be changing position — SCNActions, CAAnimations, and physics all work on a separate copy of the node hierarchy. (Partly this is to support implicit animation — e.g. set the position of a node, and it'll appear to animate from the current position to the position you set, but you can still read back position and have it be the value you set it to.)

You get to this separate hierarchy with the node's presentationNode property — ask the presentation node for its bounding box and you'll see its position/extent as affected by actions/animations/physics and currently rendered.

Upvotes: 2

Related Questions