[Closed] Pivot to normal
Hi all …
i detach a face from an object as an object, is there is any way in MXS to align the new object pivot to the face normal of the new object created from.
hope it’s clear.
thanks in advance
thanks for the tip denis …
you are keep hunting me for that …
cheers
Somebody on this forum pasted this function (sorry can’t credit them) which does just that.
fn AlignPivotTo Obj Trgt =
(
-- Get matrix from object
if classOf Trgt != matrix3 then Trgt = Trgt.transform
-- Store child transforms
-- local ChldTms = in coordSys Trgt ( for Chld in Obj.children collect Chld.transform )
-- Current offset transform matrix
local TmScale = scaleMatrix Obj.objectOffsetScale
local TmRot = Obj.objectOffsetRot as matrix3
local TmPos = transMatrix Obj.objectOffsetPos
local TmOffset = TmScale * TmRot * TmPos
-- New offset transform matrix
TmOffset *= obj.transform * inverse Trgt
-- Apply matrix
Obj.transform = Trgt
-- Restore offsets
Obj.objectOffsetPos = TmOffset.translation
Obj.objectOffsetRot = TmOffset.rotation
Obj.objectOffsetScale = TmOffset.scale
-- Restore child transforms
-- for i = 1 to Obj.children.count do Obj.children[i].transform = ChldTms[i] * inverse Trgt * Obj.transform
)
Here’s the thread containing the above snippet:
http://forums.cgsociety.org/showthread.php?p=5192944
Thanks for the link, I used this function and it does indeed align the pivot’s z axis to the normal. (right object in the picture) Sorry if this is a stupid question, but is there a way to modify the script so it aligns the pivot’s y axis to the face normal (like the left object in the picture)?
here is my version of simple alignment:
fn alignPivotToFace node face:1 type:#z_up = if iskindof node Editable_Poly do
(
c = polyop.getfacecenter node face
n = polyop.getfacenormal node face
ftm = translate (matrixfromnormal n) c
case type of
(
#x_up: prerotateY ftm -90
#y_up: prerotateX ftm 90
)
itm = ftm*(inverse node.transform)
node.transform = ftm
node.objectOffsetPos *= inverse itm
node.objectOffsetRot *= inverse itm.rotation
node.transform
)
/ Sample /
(
delete objects
p = teapot segments:3
converttopoly p
while p.numfaces > 0 do
(
polyop.detachfaces p 1 asNode:on
alignPivotToFace objects[objects.count] type:#y_up
)
delete p
gc light:on
)