轴心工具的做法。

---------*****************变换轴心点**************************************************************-----------
 try(cui.UnRegisterDialogBar transPivot)catch()-----这个是法则。
try (DestroyDialog transPivot )catch()
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 ()
  
 )
rollout transPivot "变换轴心点" width:160 height:344
(
 
 local alignToObj=0,
    usePivot
 pickbutton alObj "alignTo:(onesel/...)" pos:[4,4] width:104 height:15
 button alSel "清除" pos:[114,4] width:35 height:15
 button al5 "X_max" pos:[4,30] width:70 height:18
 button al6 "X_min" pos:[81,29] width:70 height:18
 button al1 "Y_max" pos:[4,52] width:70 height:18
 button al3 "Y_min" pos:[81,51] width:70 height:18
 button al2 "Z_max" pos:[4,74] width:70 height:18
 button al4 "Z_min" pos:[81,73] width:70 height:18
 button alc "中心" pos:[4,96] width:70 height:18
 button alR "随机" pos:[81,95] width:70 height:18
 spinner mult "倍率" pos:[10,119] width:55 height:16 range:[0,10,1]
 spinner multR "倍率随机" pos:[85,120] width:70 height:16 range:[0,10,0]
 button pick_btn1 "自动对齐" pos:[40,142] width:70 height:18 enabled:true
 
 ----------------------
 fn rotatePivotOnly obj rotation =
 (
  local rotValInv=rotation as quat
  animate off
  in coordsys local obj.rotation*=RotValInv
  obj.objectoffsetrot*=RotValInv
  obj.objectoffsetpos*=RotValInv
 )
 on alObj picked obj do (alignToObj= obj; alObj.text=("alignTo: "+obj.name); sel=getCurrentSelection(); for i=1 to sel.count do (resetPivot sel[i];  rotatePivotOnly sel[i] alignToObj.rotation;  sel[i].pivot=alignToObj.pivot) )
 on alSel pressed do (alignToObj=0; alObj.text="alignTo:(onesel/...)")
 on al1 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.y=obj.max.y+(mult.value-1+random 0.0 multR.value)*(obj.max.y-obj.min.y) ) )
 on al2 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.z=obj.max.z+(mult.value-1+random 0.0 multR.value)*(obj.max.z-obj.min.z) ) )
 on al3 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.y=obj.min.y-(mult.value-1+random 0.0 multR.value)*(obj.max.y-obj.min.y) ) )
 on al4 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.z=obj.min.z-(mult.value-1+random 0.0 multR.value)*(obj.max.z-obj.min.z) ) )
 on al5 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.x=obj.max.x+(mult.value-1+random 0.0 multR.value)*(obj.max.x-obj.min.x) ) )
 on al6 pressed do ( sel=getCurrentSelection(); for i=1 to sel.count do (obj=if alignToObj==0 then sel[i] else alignToObj; sel[i].pivot.x=obj.min.x-(mult.value-1+random 0.0 multR.value)*(obj.max.x-obj.min.x) ) )
 on alc pressed do (
      sel=getCurrentSelection()
      for i=1 to sel.count do
      (
       obj=if alignToObj==0 then sel[i] else alignToObj
       sel[i].pivot.x=obj.min.x+0.5*(obj.max.x-obj.min.x); sel[i].pivot.y=obj.min.y+0.5*(obj.max.y-obj.min.y); sel[i].pivot.z=obj.min.z+0.5*(obj.max.z-obj.min.z) )
     )
 on alr pressed do (
      sel=getCurrentSelection()
      for i=1 to sel.count do
      (
       obj=if alignToObj==0 then sel[i] else alignToObj
       sel[i].pivot.x=random (obj.min.x-(mult.value-1+random 0.0 multR.value)*(obj.max.x-obj.min.x)) (obj.max.x+(mult.value-1+random 0.0 multR.value)*(obj.max.x-obj.min.x))
       sel[i].pivot.y=random (obj.min.y-(mult.value-1+random 0.0 multR.value)*(obj.max.y-obj.min.y)) (obj.max.y+(mult.value-1+random 0.0 multR.value)*(obj.max.y-obj.min.y))
       sel[i].pivot.z=random (obj.min.z-(mult.value-1+random 0.0 multR.value)*(obj.max.z-obj.min.z)) (obj.max.z+(mult.value-1+random 0.0 multR.value)*(obj.max.z-obj.min.z))
      )
     )
     
   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     
 on transPivot open do ( usePivot=getCoordCenter(); toolMode.pivotCenter() )
 on transPivot close do case usePivot of( #local:toolMode.pivotCenter(); #selection:toolMode.selectionCenter(); #system:toolMode.transformCenter() )
)--end rollout
createdialog transPivot  pos:(mouse.screenPos-[10,180])

cui.RegisterDialogBar transPivot style:#(#cui_dock_left,#cui_dock_right, #cui_floatable)
cui.DockDialogBar transPivot #cui_dock_right

posted on 2011-04-23 15:11  盖天00  阅读(359)  评论(0编辑  收藏  举报

导航