swift - Getting an SCNNode's bounding volume with rotation -
i have simple scene set using xcode level editor.
as can see, 1 of 1x5 rectangular cuboids has been rotated 90º. achieved setting y attribute of euler angles property 90 in node inspector.
but notice bounding box doesn't account cuboids rotation. case when iterate through scnnodes in scene. both cuboids have 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 seems bounding volume calculated using child node's own coordinate system, not node parent's (or scene's) coordinate system. leaves me wondering; how calculate scnnodes bounding volume in scene?
looking through documentation scnnode, seems information there. can read eulerangles
gives me correct rotation around y axis. can read transform
property.
i thought might able multiply vectors nodes transform matrix, transform matrix (4x4) , bounding box vectors (1x3) don't appear compatible. nor scenekit appear provide methods applying transformation matrix vector. however, i'm not great geometry missing obvious.
a few ideas:
in interface builder, shown on screenshot, there's editing space property can set world (instead of local)
in code, can use temporary node compute bounding box. make sure has 1 child node (the node bounding box want compute), apply transform on child node, , ask parent node bounding box. documentation:
the bounding volume of node containing child nodes minimal volume encloses bounding volumes of node’s children.
- get node's bounding box , use utils such
-convertposition:tonode:
compute bounding box in another's coordinate system
Comments
Post a Comment