rollout igorznag_align_to_world "Align"
(
checkbox ckb_flip "Flip" pos:[5,5]
radiobuttons rb_view labels:#("XY", "YZ", "ZX") pos:[55,5]
button btn_align "Align" pos:[60,25]
on btn_align pressed do
(
if selection.count==1 then
(
obj=selection[1]; objbo=obj.baseobject
if(classof objbo==Editable_Poly)then
(
vs_ba=polyop.getVertSelection objbo;vs_a=vs_ba as array
if vs_a.count==3 then
(
p1=polyop.getVert objbo vs_a[1] node:obj
p2=polyop.getVert objbo vs_a[2] node:obj
p3=polyop.getVert objbo vs_a[3] node:obj
v1 = normalize (p2 - p1)
v3 = normalize (cross v1 (normalize (p3 - p1)))
v2 = normalize (cross v3 v1); mo=matrix3 v1 v2 v3 p1
mt=transmatrix p1;; vt=viewport.getType()
if(vt==#view_right or vt==#view_left)then mt=matrix3 [0,-1,0] [0,0,1] [-1,0,0] p1
if(vt==#view_front or vt==#view_back )then mt=matrix3 [1,0,0] [0,0,1] [0,-1,0] p1
views_a=#(#view_top,#view_bottom,#view_right,#view_left,#view_front,#view_back)
if(finditem views_a vt==0)then
(
if(rb_view.state==2)then mt=matrix3 [0,-1,0] [0,0,1] [-1,0,0] p1
if(rb_view.state==3)then mt=matrix3 [1,0,0] [0,0,1] [0,-1,0] p1
)--if(finditem views_a vt==0)then
obj_scale=1;if(ckb_flip.checked)then obj_scale=-1
undo on (obj.transform*=(inverse mo)*scaleMatrix[1,1,obj_scale]*mt)
redrawViews()
)--if vs_a.count==3 then
)--if(classof objbo==Editable_Poly)then
)--if selection.coutn==1 then
)--on btn_align pressed do
);createDialog igorznag_align_to_world 170 50