自动对齐核心已经完成。这个不错。
macroScript gt_duiqigognju
category:"盖天工具"
ButtonText:"对齐"
toolTip:"对齐工具"
(
global gt_yc_Ail
fn g_filter o = superclassof o == Geometryclass
fn find_intersection z_node node_to_z =
(
--try(
--同样的条件 数字及计算要比字符串快 所以能用数字 不用字符串。
---改写成自动的循环处理的, 我考虑的因为只有6 个 所有用循环擦看。
local oop
local compare_array =#()
for i in 1 to 6 do
(
oop=case of
(
(i==1): [0,0,-1]
(i ==2): [0,0,1]
(i ==3):[-1,0,0]
(i==4):[1,0,0]
(i ==5):[0,-1,0]
(i ==6):[0,1,0]
--default: reference $foo
)
-- print oop
local testRay = ray node_to_z.pos oop
local nodeMaxZ
case oop of
( ------Z 轴
([0,0,-1]) :(nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
)
([0,0,1]) :(nodeMaxZ = z_node.min.z
testRay.pos.z = nodeMaxZ - 0.0001 * abs nodeMaxZ
)
-------X轴
([-1,0,0]) : (nodeMaxZ = z_node.max.x
testRay.pos.x = nodeMaxZ + 0.0001 * abs nodeMaxZ
)
([1,0,0]) : (nodeMaxZ = z_node.min.x
testRay.pos.x = nodeMaxZ - 0.0001 * abs nodeMaxZ
)
------- Y轴
([0,-1,0]) : (nodeMaxZ = z_node.max.y
testRay.pos.y = nodeMaxZ + 0.0001 * abs nodeMaxZ
)
([0,1,0]) : (nodeMaxZ = z_node.min.y
testRay.pos.y = nodeMaxZ - 0.0001 * abs nodeMaxZ
)
)
--)
--testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
if intersectRay z_node testRay !=undefined then
(
---因为我先做了x轴的负方向 其实两个方向是同事存在了 所有 好要进行比较了
--return
append compare_array (intersectRay z_node testRay)
-- exit
)
)/*
for i in compare_array do
(
distance_d = distance $selection[1].pos i.pos
--print compare_array[1].pos
distance_c=0
if distance_d>= distance_c then
(
distance_c =distance_d
)
)*/
---其实就有两个我比较下好; 用列举法
distance_d = distance $selection[1].pos compare_array[1].pos
try ( distance_c = distance $selection[1].pos compare_array[2].pos )
catch ( distance_c =distance_d+20)
if amin distance_d distance_c == distance_d then
(
return compare_array[1]
)else
(
return compare_array[2]
)
-- ) catch ()
)
try(destroyDialog gt_yc_Ail)catch()
rollout gt_yc_Ail "yongchao-对齐" width:168 height:80
(
spinner conunt_spn1 "" pos:[152,25] width:12 height:16 range:[1,6,1] type:#integer
edittext conunt_edt1 "" pos:[3,25] width:147 height:16 text:"Z轴的负方向" enabled:false
button pick_btn1 "开始对齐" pos:[6,49] width:142 height:24
groupBox grp1 "轴向选择:" pos:[5,9] width:160 height:39
on conunt_spn1 changed arg do
(
new_obj = case arg of
(
1: conunt_edt1.text="Z轴的负方向"
2: conunt_edt1.text="Z轴的正方向"
3: conunt_edt1.text="X轴的负方向"
4: conunt_edt1.text="X轴的正方向"
5: conunt_edt1.text="Y轴的负方向"
6: conunt_edt1.text="Y轴的正方向"
--default: reference $foo
)
)
on pick_btn1 pressed do
(
---从上到下执行。先执行这里的这个。
target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter --- 这种拾取的方法更好。不用再显示;
if isValidNode target_mesh then ---这个好用, 是如果节点没有被删除。
(
undo "MoveToSurface" on
(
for i in selection do
(
int_point = find_intersection target_mesh i
-- print int_point as string
if int_point != undefined and int_point != ok then
(
i.pos = int_point.pos
-- print int_point.pos
)
)--end i loop
)--end undo
)--end if
)--end pressed
)
createdialog gt_yc_Ail style:#(#style_border,#style_titlebar,#style_resizing,#style_sysmenu)
)