Getting an SCNNode's bounding volume with rotation

I have a very simple scene set up using the XCode level editor.

As you can see, one of the 1x5 rectangular cuboids has been rotated by 90º. This was achieved by setting the y attribute of the Euler Angles property to 90 in the Node Inspector.

But notice that the Bounding Box doesn't account for the cuboids rotation. This is also the case when I iterate through the SCNNodes in the scene. Both cuboids have the same Bounding Volumne

for wall:SCNNode in walls.childNodes {
    var v1 = SCNVector3Zero
    var v2 = SCNVector3Zero
    wall.getBoundingBoxMin(&v1, max:&v2)
    print(v1, v2)

// Prints
// SCNVector3(x: -0.5, y: 0.0, z: -2.5) SCNVector3(x: 0.5, y: 0.5, z: 2.5)
// SCNVector3(x: -0.5, y: 0.0, z: -2.5) SCNVector3(x: 0.5, y: 0.5, z: 2.5)

So it seems the Bounding Volume is calculated using the child node's own coordinate system, not node parent's (or scene's) coordinate system. Which leaves me wondering; How do I calculate the SCNNodes bounding volume in the scene?

Looking through the documentation for SCNNode, it seems all the information is there. I can read the eulerAngles which gives me the correct rotation around the y axis. I can read the transform property.

I thought I might be able to multiply the vectors by the nodes transform matrix, but the transform matrix (4x4) and bounding box vectors (1x3) don't appear to be compatible. Nor does SceneKit appear to provide any methods for applying a transformation matrix to a vector. However, I'm not great with Geometry so I could be missing something obvious.


A few ideas:

  1. In Interface Builder, as shown on your screenshot, there's an Editing space property that you can set to World (instead of Local)

  2. In code, you can use a temporary node to compute the bounding box. Make sure that only has one child node (the node whose bounding box you want to compute), apply any transform on that child node, and they ask the parent node for its bounding box. From the documentation:

The bounding volume of a node containing child nodes is the minimal volume that encloses the bounding volumes of the node’s children.

  1. Get the node's bounding box and then use utils such as -convertPosition:toNode: to compute the bounding box in another's coordinate system

Need Your Help

Accessing elements of an object in a jList/listModel

java arrays swing jlist

I'm trying to populate a jList, I want it to display a name but also store an ID (which is not displayed) for each item in the list.

HTTP post request - difference between AngularJS and JQuery

javascript php jquery angularjs ionic-framework

What is the true difference between HTTP POST requests run by AngularJS and JQuery?