I'm not sure of the correct terminology to describe this issue so I've posted two pictures demonstrating the problem.
When using 3D models authored in 3rd party packages like SketchUp, you might encounter grouped geometry (childnodes) that are not aligned to the parent node axis. The picture below shows a top view of a model of Da Vinci wooden Odometer with 4 wheels (2 wheels for moving the cart & another 2 wheels for measuring the distanced travelled).
3 wheels in this model are not aligned with any of the rootNodes 3-axis. So when you do a rotation like say
let rotateAction = SCNAction.rotate(by: 20, around: SCNVector3(1,0,0), duration: 10)
let rotateForever = SCNAction.repeatForever(rotateAction)
wheelNode?.runAction(rotateForever)
the wheel will not rotate on its centre (even if the wheelNodes pivot is in the centre of the wheel Geometry) because the wheels orientation is not aligned to the x-axis.
I know one way to make it work... is you can manually rotate the geometry around so all 4 wheels now are aligned with at least a primary axis.
But is there a way to do this using swift instead.
- Detect a childnodes mis-alignment to the primary axis of rotation say x-axis..... and re-align either the childnode or whole model at run-time so its align with a primary axis.
Is it possible to do this sort of thing with wheelNode.rotateBy instead?
Any help would be appreciated.