系类函数介绍 之中可能没有一些预订变量 应用时要自己加上。

--选择物体的第一个材质球 是这个。

fn clmedit_add =
 (
 oop_array = selection as array 
  meditMaterials[1] =  oop_array[1].Material
 )

--如果选择的材质是多维材质那么就是 他的材质的数量 就是id 号的个数

 fn or_or num  =
 (  
    if classof $.material   == Multimaterial then
    ( 
      clmedit_add()
    
     shu =  meditMaterials[num].materialIDList. count
     return  shu  
    )else
    (
     return false 
    )
 )

--这个函数是基于上面的 是选择物体的材质是第一个 并且知道他的id 的数量 返回有贴图的 材质数组  还有就是没有材质的贴图的 数组。

 fn check_unm    =
 (
  unm = or_or 1
 if unm == undefined then
 (
  return false
 )
 
  list_mat = meditMaterials[1].materialIDList
 stand_mat=#()
  for i in 1 to unm do
  ( 

    if classof  meditMaterials[1][list_mat[i]] == Standardmaterial  then
    ( 

     append  stand_mat list_mat[i]
    
    )
    else
    (

     append  nostand_mat  list_mat[i]
    
     if  nostand_mat.count >0 then
     (
     
     if AboutRollout != undefined then destroydialog AboutRollout
    rollout AboutRollout "About"
    (
    label lbl5  "选择物体的多维材质中" pos:[10,10]
    label lbl3 "有不是标准子材质的材质"
    timer tmclose "" interval:2000 active:true
    on AboutRollout rbuttonup press do destroydialog AboutRollout ------ 右键进行消除
    on tmclose tick do destroydialog AboutRollout  --时间按点到消除  给我提供了思路。
    )createdialog AboutRollout 200 100  modal:true style:#(#style_border,#style_sysmenu,#style_sunkenedge)

     clearListener()
                 setListenerSel #(0,-1)
      for i in nostand_mat do
      (
            format "不是标准材质的有: meditMaterials[1][%]\n" i    Listener()
      )
    )
    )
  )
    
 )

--还是从 收集的材质中 过滤掉有贴图的材质。

 fn cle_mat_id_face =
 ( 

  met_obj_face =#()

  met_obj_face_id =#()
 
  check_unm()
  comparison = stand_mat
 
  for i in comparison  do
  (
   channel_num = 24

   for n in 1 to channel_num do 
   (

    the_prop = getSubTexmap MeditMaterials[1][i] n

    if the_prop != undefined then
    (
    if  findItem  map_preparation i ==0 then
    (
    
     append  map_preparation i
    )
    
    )
   )
 
  )

  for each in comparison do
  (

  if  findItem  map_preparation  each ==0  then
  (
    append  met_obj_face_id  each
  )
 
  )
 
     return met_obj_face_id
 )

--- 介上面函数没有贴图的进行选择 里面有关于选择贴图并指点 id 脚本 选择面 更新场景脚本,等。

  fn cle_mat_id_face_add =
  (

     clear_array_mat = cle_mat_id_face ()
    meditMaterials[1].materialIDList = map_preparation
      select_one = $selection [1]  
      max modify mode

    if classof select_one.baseobject== Editable_mesh then
    (
     convertTo  select_one PolyMeshObject
    )

  if classof select_one.baseobject== Editable_Poly  then
 
      ( --
 
    dat_num = #{}

    modPanel.setCurrentObject $.baseObject

     subobjectLevel = 4

    for i in clear_array_mat do
    (

     select_one.EditablePoly.selectByMaterial i
     dat_num += polyop.getfaceselection $
    )

     polyop.setfaceselection select_one  (dat_num )
     nodeInvalRect select_one
   )
  )

--继承上面全局加前缀 名字后缀

 
  fn mat_modifiers_mane  prefix name_n suffix =
  ( 

         or_or 1

    if  or_or 1 ==false then return false
  
   list_mat  = meditMaterials[1].materialIDList
  
   for i in list_mat do
   (
    if name_n=="" then
    (
     meditMaterials[1][i].name =prefix +  meditMaterials[1][i].name +suffix
    )else
    (
     meditMaterials[1][i].name =prefix +  name_n+i as string +suffix
    )
   
   )
  
  
  )

---选择局部的id 进行前缀名字的后缀

  fn multimaterial_mat  nums   prefix name_n suffix   =
  (
             or_or 1

    if  or_or 1 ==false then return false

    if classof meditMaterials[1][nums] ==Standardmaterial then
    (
 
     chenk = getnumsubtexmaps meditMaterials[1][nums]
        
      for each in 1 to  chenk do
   ( 

     the_prop = getSubTexmap MeditMaterials[1][nums] each
   
     if the_prop!= undefined then
     ( --

      if  name_n== "" then
      (--

       kl = (getSubTexmap MeditMaterials[1][nums] each )  .name

        (getSubTexmap MeditMaterials[1][nums] each ) .name = prefix+ kl+suffix
      )else
      (
      
     (getSubTexmap MeditMaterials[1][nums] each ) .name= prefix+ name_n+ nums as string +suffix 
      
      )
     )
   
   )
   
   
    )
   
   
  )---end fn

----材质的所有前缀名字的后缀 继承上方

  fn multimaterial_mat_all   prefix name_n suffix  =
  (

   check_unm ()

    mat_array = stand_mat

   if mat_array.count ==  0 then  return false
   for i in  mat_array do
   (

     if  classof meditMaterials[1][i] == Standardmaterial then
     (   --
       chenk = getnumsubtexmaps meditMaterials[1][i]
     
       for each in 1 to  chenk do
       ( 

      the_prop = getSubTexmap MeditMaterials[1][i] each
    
      if the_prop!= undefined then
      ( --

       if  name_n== "" then
       (--
        kl = (getSubTexmap MeditMaterials[1][i] each )  .name
 
      (getSubTexmap MeditMaterials[1][i] each ) .name = prefix+ kl+suffix
       )else
       (
       (getSubTexmap MeditMaterials[1][i] each ) .name= prefix+ name_n +each as string  +suffix 
       )
      )---end  if the_prop!= undefined then
    
       )---end for each
         
     )---end if
   )---end for
   
  )---end fn

-----局部材质固有色的操作

  fn Fixed_point_color   unm cloor_id   =
  (

   check_unm ()

    mat_array = stand_mat

   if mat_array.count ==  0 then  return false
  
 
   --(
     if  classof meditMaterials[1][unm] == Standardmaterial then
     (
      meditMaterials[1][unm].diffuse =cloor_id
     
     )---end if
       
  -- )---end for
    
  )---end fn

---顶点颜色的操作

  fn dingdianclor  objID  clort =
  (
  
    check_unm ()

   mat_array = stand_mat

   if  classof meditMaterials[1][objID] == Standardmaterial then  
   (

     select_one = $selection [1]
     max modify mode
   
        if classof select_one.baseobject== Editable_mesh then
   (
    -- 转多边行
    convertTo  select_one PolyMeshObject
   )

    dat_num = #()
    if classof select_one.baseobject== Editable_Poly  then
 
     (  
      modPanel.setCurrentObject select_one.baseObject
  
               subobjectLevel = 4
            select_one.EditablePoly.selectByMaterial objID
      --polyop.getfaceselection 这里用顶点选择、
      select_one.EditablePoly.ConvertSelection #Face #Vertex
      subobjectLevel = 1
             dat_num =  polyop.getVertSelection select_one

      polyop.setVertColor select_one  0  dat_num  clort
     
     )
   )----end if  
  
  )-----end fn

---继承上面还是这样的 保证才是的有贴图的收集

 fn  Map_collection  =
 (

  check_unm ()
  mat_array = stand_mat

    for i in  mat_array do
    (   --
    
      for each in 1 to  24 do  --这里其实直接就可以写成24 算法就更快了。 我把 这里的chenk 改成24 了 2011.4.7
     ( 

    the_prop = getSubTexmap MeditMaterials[1][i] each
  
    if the_prop!= undefined then
    (

     if  findItem  tietushouji_map_id  i ==0  then
     append  tietushouji_map_id  i
    
    )---end if then_prop
  
     )---end for each
    )----end for
    return  tietushouji_map_id
 
 )----end fn

---继承上面对有贴图的继承贴图名字

 fn map_map_compared =
 (
  map_array_com =  Map_collection ()
  if map_array_com.count ==0 then return false

  for i in 1 to  map_array_com.count do
  (  
    linshi_add_array =""
   try chenk = getnumsubtexmaps meditMaterials[1][(map_array_com[i])] catch()

   for each in 1 to chenk do
   (
    the_prop = getSubTexmap MeditMaterials[1][(map_array_com[i])] each
   
    if  classof  the_prop  == Bitmaptexture then
 (
  str = the_prop.fileName ---分出来要最后一个。
  
   oop = filterString   str "\\" --分组
  
   add_array = oop[(oop.count)]

    append  linshi_add_array add_array 
  
 )
   
   )

   bmp_zhuan_string[i] = linshi_add_array as string
  )--end for
 
   return  bmp_zhuan_string
 
 )----end fn

-----继承上面对有贴图的所有的 通道进行收集

 fn map_compared =
 (
  map_array_com =  Map_collection ()

  if map_array_com.count ==0 then return false

  for i in 1 to  map_array_com.count do
  (  
    linshi_add_array =""
   try chenk = getnumsubtexmaps meditMaterials[1][(map_array_com[i])] catch()

   for each in 1 to chenk do
   (
    the_prop = getSubTexmap MeditMaterials[1][(map_array_com[i])] each
   
    the_prop =the_prop as string

    append  linshi_add_array the_prop
   
   )

   zhuan_string[i] = linshi_add_array as string
   --*********************************************************************************************

   --*****************************************************************************************
  )--end for
 
   return  zhuan_string
 
 )----end fn

----查询相同了 返回字符串类表这个是想要的 如:#("1-3")

fn map_compared =
 (
  map_array_com =  Map_collection ()

  if map_array_com.count ==0 then return false

  for i in 1 to  map_array_com.count do
  (  
    linshi_add_array =""
   try chenk = getnumsubtexmaps meditMaterials[1][(map_array_com[i])] catch()

   for each in 1 to chenk do
   (
    the_prop = getSubTexmap MeditMaterials[1][(map_array_com[i])] each
   
    the_prop =the_prop as string

    append  linshi_add_array the_prop
   
   )

   zhuan_string[i] = linshi_add_array as string
   --*********************************************************************************************

   --*****************************************************************************************
  )--end for
 
   return  zhuan_string
 
 )----end fn
 --
 global add_mat_num =#()
      add_mat_dao =#()
 
 fn array_mat_compared   hanshu  =
 (   
 
  art_map_ch =  hanshu     --map_compared()

  if art_map_ch == false then return false
  if ( art_map_ch.count==0 and  art_map_ch.count==1 ) then return false
    kl=0
      oop_oo =""
   global  gt_aryu =#()
   global aty_1 =#()
     xin=#()
  for i in 1 to (art_map_ch.count-1)  do
  ( 

          each =i+1 ---自增的比较项。
    oop_oo=i as string
   for  m  in each to art_map_ch.count do
   (
    --  比较
    if art_map_ch[i] == art_map_ch[m] then
    ( oop_oo+= "-"+ m as string
    
    )else
    (
    --oop_oo+=""
    )
  
   if  (filterString  oop_oo "-" ).count  >1  then
   (
   
     add_mat_num[i] = oop_oo
    
   
   )
  )
     
  )---end for 

           add_mat_num
 
  if  add_mat_num.count <1 then return false
  for i in 1 to add_mat_num.count do
  (
   if add_mat_num [i] == undefined then
   ( 
    add_mat_num [i] = "undefined"
   
    append gt_aryu  (add_mat_num [i] )   

   )---end if     --deleteItem  add_mat_num  i
  )
   for i in add_mat_num  do
   (

    if  findItem  gt_aryu   i ==0 then  append aty_1  i
   )
  
   add_mat_num = aty_1
  
   --*****************************************************
if  add_mat_num.count >1 then
(
 yytadd_mat_dao=#()
 map_ = add_mat_num.count-1
 map__= add_mat_num.count
 -- print  (add_mat_num as string )
 for m in 1 to  map_  do
 (
 ecct= m+1
 for each  in ecct to  map__ do
 (
    if( findString  add_mat_num[m]  add_mat_num[each] != undefined )  then
      (      
       --   yytadd_mat_dao[m] =  add_mat_num[each]
      
       append  yytadd_mat_dao  add_mat_num[each]
      )
 )

 )
  
  for nu in  add_mat_num  do
  (
   if  findItem  yytadd_mat_dao  nu ==0 then
    append   xin   nu
  
  ) ----上面是新算法,还是用的递归。
 
  add_mat_num = xin 
)
  
       return add_mat_num
 
 )---rnd fn

---选择1 个以上的物体有警告 的经典写法

   fn gt_selctt    =
  (   
   kol =1
     if $selection.count >1 then
  (
        if AboutRollout != undefined then destroydialog AboutRollout
  rollout AboutRollout "About"
  (
  label lbl5  "选择数量大于1 将不执行," pos:[10,10]
  label lbl3 "以此提醒。"
  timer tmclose "" interval:1000 active:true
  on AboutRollout rbuttonup press do destroydialog AboutRollout ------ 右键进行消除
  on tmclose tick do destroydialog AboutRollout  --时间按点到消除  给我提供了思路。
  )createdialog AboutRollout 200 100  modal:true style:#(#style_border,#style_sysmenu,#style_sunkenedge)
  
  kol+=1
   return kol
  )else ( return kol )
 
  )

---以上是我在项目中的写法,这个函数以后用得到 在此一击 

--下面是我对 ck 的一些效果

on gt_unnamedRollout open do
 ( 

  ------------------------------------------------------------
 
    for i in gt_unnamedRollout.controls  do
  (
   i.enabled =false
  )
  Callbacks.AddScript #SelectionSetChanged  "Fn_CallBack_duoweicazhi()"  ID:#gt_mat_met
 )---end on
 on gt_unnamedRollout close do
 (
  callbacks.removescripts #selectionSetChanged ID:#gt_mat_met
 )---end on
 
 
 )
 createDialog  gt_unnamedRollout
 
     
callbacks.removescripts #selectionSetChanged ID:#gt_mat_met        
fn   Fn_CallBack_duoweicazhi =
(
 
 TheSelection = Selection as array
 
 if $== undefined then
 (
  for i in gt_unnamedRollout.controls  do
  (
   i.enabled =false
  )
 )else
 (
 
 if  (classof TheSelection[1].Material) == Multimaterial then
 (  
  for i in gt_unnamedRollout.controls  do
  (
   i.enabled =true
  )
 
 )else
 (
  for i in gt_unnamedRollout.controls  do
  (
   i.enabled =false
  )
 
 ) --end else
)---end else


Callbacks.AddScript #SelectionSetChanged  "Fn_CallBack_duoweicazhi()"  ID:#gt_mat_met

需要注意的是 在应用时最好把 id 的地址改掉新的

posted on 2011-04-08 10:44  盖天00  阅读(268)  评论(0编辑  收藏  举报

导航