一半君的总结纸

听话只听一半君

#08 如何找到Transform的Shape node? 或者反之如何从Shape node找到Transform?

可以这样找到Transform下的所有Shape nodes :

proc string[] getShapes( string $xform )
{
   string $shapes[];

   $shapes[0] = $xform;

   if ( "transform" == `nodeType $xform` )
   // 假设给定的node不是transform, 那就假设他是一个shape
   // 直接返回
   {
      $shapes = `listRelatives -fullPath -shapes $xform`;
   }

   return $shapes;
}

注意上面返回的是一个字符串数组(string array), 因为一个transform下可能会有多个shape nodes.

下面是如何从 Shape node找到Transform:

proc string getTransform( string $shape )
{
   string $transform = "";

   if ( "transform" != `nodeType $shape` )
   // 如果给定的node已经是一个 transform了, 那就直接返回
   {
      string $parents[] = `listRelatives -fullPath -parent $shape`;
      $transform = $parents[0];
   }

   return $transform;
}

增强版:

pyNode = pm.PyNode('pCube1')
pyNode.getShapes()
# Result: [nt.Mesh(u'pCubeShape1')] #

pyNode = pm.PyNode('pCubeShape1')
pyNode.getParent()
# Result: nt.Transform(u'pCube1') #

Related How-To’s

11 May 2003

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 博主赞过: