三种形状匹配脚本

----吸附到模型表面

rollout unnamedRollout "Untitled" width:149 height:191
(
 button btn1 "start" pos:[41,146] width:61 height:25
 pickButton Souce "Souce" pos:[19,31] width:109 height:36
 pickButton Target "Target" pos:[19,80] width:109 height:36
 groupBox grp1 "拾取模型" pos:[9,7] width:130 height:127
 
 on Souce picked obj do
    (
     if obj != undefined do

  (
     Souce.text = obj.name
  )
 )
 
 on Target picked obj do
    (
     if obj != undefined do

  (
     Target.text = obj.name
  )
 )

 on btn1 pressed do
 (
  if Souce.object != undefined and Target.object != undefined do
  (
   raydir = Target.object.pos - Souce.object.pos
   raypos = Souce.object.pos
   getray = ray raypos raydir
   
   temp = intersectray Target.object getray
   Souce.object.pos = temp.pos
  )
 )
 
)
createDialog unnamedRollout 149 191

 

---顶点匹配形状
rollout unnamedRollout "Untitled" width:149 height:191
(
 button btn1 "start" pos:[41,146] width:61 height:25
 pickButton Souce "Souce" pos:[19,31] width:109 height:36
 pickButton Target "Target" pos:[19,80] width:109 height:36
 groupBox grp1 "拾取模型" pos:[9,7] width:130 height:127
 label lab1 "" pos:[30,185]
 on Souce picked obj do
    (
     if obj != undefined do

  (
     Souce.text = obj.name
  )
 )
 
 on Target picked obj do
    (
     if obj != undefined do

  (
     Target.text = obj.name
  )
 )

 on btn1 pressed do
 (
  if Souce.object != undefined and Target.object != undefined do
  (
   if superclassof Souce.object == geometryclass and classof Souce.object != bonegeometry do
   (
    convertTo Souce.object TriMeshGeometry
    souceVerts = Souce.object.verts --点集合
    souceNumber = souceVerts.count --点总数
    try
    (
     for i = 1 to souceNumber do
     (
      
      raydir = Target.object.pos - souceVerts[i].pos
      raypos = souceVerts[i].pos
      getray = ray raypos raydir
      
      temp = intersectray Target.object getray
      souceVerts[i].pos  = temp.pos
     )
     
     update Souce.object geometry:true
    )catch()
   )
  )
 )
 
)
createDialog unnamedRollout 149 210

--顶点匹配到Z平面


rollout unnamedRollout "Untitled" width:149 height:191
(
 button btn1 "start" pos:[41,146] width:61 height:25
 pickButton Souce "Souce" pos:[19,31] width:109 height:36
 pickButton Target "Target" pos:[19,80] width:109 height:36
 groupBox grp1 "拾取模型" pos:[9,7] width:130 height:127
 label lab1 "" pos:[30,185]
 on Souce picked obj do
    (
     if obj != undefined do

  (
     Souce.text = obj.name
  )
 )
 
 on Target picked obj do
    (
     if obj != undefined do

  (
     Target.text = obj.name
  )
 )
 on btn1 pressed do
 (
  if Souce.object != undefined and Target.object != undefined do
  (
   if superclassof Souce.object == GeometryClass and classof Souce.object != bonegeometry do
   (
    convertTo Souce.object TriMeshGeometry
    local souceVerts = Souce.object.verts --点集合
    local souceNumber = souceVerts.count --点总数
    try
    (
     for i = 1 to souceNumber do
     (
      s = [0,0,-1]
      --raydir = Target.object.pos - souceVerts[i].pos 
      raypos = souceVerts[i].pos
      getray = ray raypos s--raydir
      
      temp = intersectray Target.object getray
      if temp != undefined do
      (
        souceVerts[i].pos  = temp.pos
      )
     )
     
     update Souce.object geometry:true
    )catch()
   )
  )
 )
 
)
createDialog unnamedRollout 149 210


/*x = $Dummy001
y = $Sphere001
raydir =   y.pos - x.pos
raypos = x.pos
getray = ray raypos raydir

temp = intersectray y getray
x.pos = temp.pos

 

你可能感兴趣的:(脚本)