一半君的总结纸

听话只听一半君

#73 如何得到NURBS curve的长度?

Using ‘arclen’

此方法是由 Adrian Graham 提供的(commandpostTOYBOX).

The ‘arclen’ MEL command 可以用来查询一条 NURBS curve 的总长度:

string $curve = `curve -d 1 -p -2.1 0.0 -2.0 -p 0.5 1.0 -3.2 -p 1.4 0.3 -1.2 -k 0 -k 1 -k 2`;
// Result: curve1 //

float $curveLength = `arclen $curve`;
// Result: 5.335323 //

如果在使用时加上了 ‘-constructionHistory’ flag ,那么Maya将会创建一个 “curveInfo” node. 你就可以一直监视这条曲线的长度变化了.

string $curveInfo = `arclen -ch true $curve`;
// Result: curveInfo1 //

getAttr ( $curveInfo + ".arcLength" );
// Result: 5.335323 //

move -r -os -wd 0 0 1.0 ( $curve + ".cv[1]" );

getAttr ( $curveInfo + ".arcLength" );
// Result: 4.309423 //

Using ‘arcLengthDimension’

创建一个 “arcDimension” node,并把他连到曲线的最后一个CV上, 然后读取‘.arcLength’ attribute.

string $curve = `curve -d 3 -p -5.4 0.0 -5.5 -p -6.0 0.0  4.1
                            -p  3.4 0.0 -4.7 -p  7.8 0.0 -0.7
                            -p  0.3 0.0  2.3
                            -k -2 -k -1 -k 0 -k 1 -k 2 -k 3 -k 4`;

// 得到曲线的 U 参数的范围.
float $maxU = `getAttr ( $curve + ".maxValue" )`;

// 创建一个 arcLengthDimension node, 把曲线连接到他上面.
string $arcLD = `arcLengthDimension ( $curve + ".u[" + $maxU + "]" )`;

float $arcLength = `getAttr ( $arcLD + ".arcLength" )`;
// Result: 1246.701327 //

NOTE: 这样返回的弧长的单位是 centimeters ,不管你Maya的UI Unit Preference设置的是多少.

这个方法的好处是可以查询曲线在任意参数值处的弧长.

setAttr ( $arcLD + ".uParamValue" ) 1.0;
$arcLength = `getAttr ( $arcLD + ".arcLength" )`;
// Result: 784.586627 //

setAttr ( $arcLD + ".uParamValue" ) 0.7071;
$arcLength = `getAttr ( $arcLD + ".arcLength" )`;
// Result: 539.611324 //

arcLengthDimension” command 返回的是 shape node. 如果你想删除 ‘arcLengthDimension’ node, 那必须先从shape得到 $arcLD 然后再删除 transform.

string $transform[] = `listRelatives -parent $arcLD`;
delete $transform[0];

Acknowledgements

Related How-To’s

Wednesday, October 10, 2001

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: