I have a 3D Globe and each of the countries are seperate meshes. I am in the process of writing a script in 3D Max that automates centring the pivots.
for all in selection do(all.pivot = all.center)
This part is fine. However I am bringing this into Unity and want to position a gameobject to each of these pivots. To have this looking aesthetically pleasing the pivots of each mesh should be perpendicular.
Now I have been looking online for direction of solutions and I've been struggling - perhaps down to misunderstanding.
I thought getting numFaces and dividing it by 2 would give an appropriate position and rotation alignment but unfortunately the halfway polygon is not close enough to the mesh centre.
I was wondering is there a way to do this by selecting the closest polygon in the mesh to the overall pivot or maybe by selecting the centre polygon through an intersection with a newly created mesh.
Perhaps I am complicating this.
Would anyone have any input that could set me in the right direction?
Thank you.
Ok I figured it out after some headbutting. The solution 'for me' was provided by the pivot point of the spherical globe's ocean. By finding a question provided by Joker Martini to design a lookAt for each pivot of every mesh to look at a target (the pivot of the spherical world water that is centered) and then flipping through rotation the pivot by learning about objectoffsetrot.
Here it is as it may be useful for someone.
for all in selection do(
one = all
target = $'Globe Sea'
pivotLookAt one two
RotatePivotOnly one ((eulerangles 0 180 0) as quat)
)
fn pivotLookAt obj target =
(
ResetXForm obj
old_tm = obj.transform
obj.dir = normalize (target.pos - obj.pos)
obj.objectOffsetRot = old_tm * (inverse obj.transform)
)
fn RotatePivotOnly obj rotation =
(
local rotValInv = inverse (rotation as quat)
animate off in coordsys local obj.rotation *= RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)
Happy to hear of any opinions out there on this for optimising or constructive improving.
Thank you.