Hi, I am initializing a SCNNode from a OBJ file. Let's suppose the object is a sphere, and its pivot after loading it from the OBJ file is the bottom of the sphere (where it would rest on the floor). Its default position is the zero vector.
However, I must change the pivot to the center of the sphere. After doing so (based on its bbox), since the position is still the zero vector, does that mean that the object was translated so that the new pivot lies at (0,0,0)? Or should set its position to (0,0,0), which will now be based on the new pivot?
To test whether this is needed, I am using a separate button to change the node's position to (0,0,0) after changing its pivot, but I do not see any change visually, which leads me to believe that after changing the pivot, the object is automatically moved to (0,0,0) based on its new pivot. This is probably done faster than the scene renders which is why I do not notice any difference between the two methods.
I cannot tell which of the two is correct, meaning that I do no know whether I should set the position again to (0,0,0) after changing the pivot or not. Right now it seems like it makes no difference. Any thoughts?
You should set the position as well. So you have your bounding box:
var min = SCNVector3Zero
var max = SCNVector3Zero
node.__getBoundingBoxMin(&min, max: &max)
The pivot at center:
let pivot = SCNMatrix4MakeTranslation(
min.x + (max.x - min.x)/2,
min.y + (max.y - min.y)/2,
min.z + (max.z - min.z)/2
)
This pivot is at x: m41, y: m42, z: m43
let posShift = SCNVector3(
pivot.m41,
pivot.m42,
pivot.m43
)
so
node.pivot = pivot
node.position = posShift