一半君的总结纸

听话只听一半君

#03 怎样得到当前选中的多边形(polymesh)的面(face)所包含的所有点(vertex)或边(edge)? (或者反之得到选择的面)

有个隐藏的(其实并不能算隐藏,只是他的名字不是那么望文生义)的MEL命令可以达到我们的目的(最初在Quang Tran的edgePath/facePath工具里被用到):

polyListComponentConversion

上面的命令会把当前选择的面(face)或边(edge)转换成边或者点(vertex),并返回他们, 所以只要把返回值赋给一个字符串数组(string array)就可以了:

// 把face转成vertex
string $vtx[] = `polyListComponentConversion -toVertexFace pCube1.f[5]`;
// Result: pCube1.vtx[0] pCube1.vtx[2] pCube1.vtx[4] pCube1.vtx[6] //

// 找到组成face的edge
string $edge[] = `polyListComponentConversion -toEdge pCube1.f[1]`;
// Result: pCube1.e[1:2] pCube1.e[6:7] //

// edge两端的vertex
string $vtx[] = `polyListComponentConversion -toVertex pCube1.e[1]`;
// Result: pCube1.vtx[2:3] //

// 找到组成face的vertex
string $face[] = `polyListComponentConversion -toFace pCube1.vtx[1]`;
// Result: pCube1.f[0] pCube1.f[3:4] //

 

# Vertices associated with face
vtx = pm.PyNode('pCube1.f[5]').getVertices()
# Result: [6, 0, 2, 4] #

# Edges associated with face
edge = pm.PyNode('pCube1.f[1]').getEdges()
# Result: [1, 7, 2, 6] #

# Vertices associated with edge
vtx = pm.PyNode('pCube1.e[1]').connectedVertices()
# Result: (MeshVertex(u'pCubeShape1.vtx[2]'), MeshVertex(u'pCubeShape1.vtx[3]')) #

# Faces associated with vertex
pm.PyNode('pCube1.vtx[1]').connectedFaces()
# Result: MeshFace(u'pCubeShape1.f[0,3:4]') #

以前的老方法是

我以前用的是一个自己写的procedure,用穷举的方法解析’listAttr’命令的返回值,以此来得到face所包含的vertex.

proc int[] facetVertices( string $facet )
{
   int $vertices[];
   int $numVertices = 0;

   string $attr[] = `listAttr $facet`;

   for ( $i = 0; $i < size( $attr ); $i+=4 )
   {
      $vertices[$numVertices++] = match( "[0-9]+", $attr[$i] );
   }

   return $vertices;
}

 

pm.PyNode(facet).getVertices()

Related How-To’s

Thursday, January 18, 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 博主赞过: