2010年4月17日 星期六

把曲線貼到模型表面上( attach curve to surface )




使用方法: 先選 curve, 再選模型,然後執行以下程式既可把curve 貼到模型表面上.

MEL:
{
string $selected[]=`ls -sl`;

if(size($selected)>1)
{
string $curve = $selected[0];
string $obj = $selected[1];

string $allCVs[] = `ls -fl ($curve+".cv[*]")`;

for($cv in $allCVs)
{
float $oriPos[] =`pointPosition -w $cv`;
string $newLoc[]=`spaceLocator -p $oriPos[0] $oriPos[1] $oriPos[2]`;
CenterPivot;
select -r $obj;
select -add $newLoc[0];
geometryConstraint -w 1;
float $newPos[]=`pointPosition -w $newLoc[0]`;
move -a $newPos[0] $newPos[1] $newPos[2] $cv;
delete $newLoc;
}
}

select -r $selected;
}

Pymel 1.0 :
from pymel.core import *
def curveToSurface():
selection = ls(sl=1)

currCurve = selection[0]
currObject = selection[1]



for each in currCurve.cv:
pos = each.getPosition(space='world')
newLoc = spaceLocator(p=pos)
mel.eval('CenterPivot')
select(currObject,r=1)
select(newLoc,add=1)
geometryConstraint(w=1)
locPos = pointPosition(newLoc,w=1)

each.setPosition(locPos,space='world')
delete(newLoc)



為何會想到要寫這工具呢?因為有時候要做配件(prop)模型時,會需要把物件與角色位子對(例如把戒指對到手指大小). 利用這工具就可以先建一些 curve, 然後使用 extrude/loft 把戒子生出來.

3 則留言: