一半君的总结纸

听话只听一半君

#43 如何得到一个物体或者面所在的Shading Group?

如果想找到赋予一个物体的 Shading Group , 你可以找到这个物体的 shape node 下游的所有 ‘shadingEngine’ nodes (又称为 Shading Groups).

// ////////////////////////////////////////////////////////////////////
//  getSGsFromShape
//
// Description: 返回一个 Shading Groups (shadingEngine
//  nodes) 数组, 其中的元素都是用来 shading 指定的 shape node的.

proc string[] getSGsFromShape( string $shape )
{
  string $shadingEngines[];

  if ( `objExists $shape` )
  {
    string $dest[] = `listConnections -destination true -source false
      -plugs false -type "shadingEngine" $shape`;

    // listConnections 可能会返回重复的结果.
    // 下面的select是为了避免结果中重复的元素
    if ( size( $dest ) )
    {
      string $select[] = `ls -sl`;
      select -r -ne $dest;
      $shadingEngines = `ls -sl`;
      select -r $select;
    }
  }

  return $shadingEngines;
}

得到面的Shading Group

得到场景中所有的 Shading Groups ,然后查询每个set,看要找的面是不是被这个shader shade的.

proc string getFacetSG( string $facet )
// 输入 (string) - 要查询的面 (如. "pSphere1.f[0]")
// 结果 (string) - 这个面的Shading Group (如. "lambert2SG")
{
  string $facetSG = "";

  // 找到所有的 Shading Groups,返回array
  string $shadingGroups[] = `ls -type shadingEngine`;

  for ( $shadingGroup in $shadingGroups )
  {
    // 如果这个面是这个 shading set 的member
    // 那说明这个面的shading group就是他
    if ( `sets -isMember $shadingGroup $facet` )
    {
      $facetSG = $shadingGroup;
      break;
    }
  }

  return $facetSG;
}

加强版:

pyNode = pm.PyNode('pCube1')
pyNode.shadingGroups()
# Result: [nt.ShadingEngine(u'initialShadingGroup')] #

pyNode = pm.PyNode('pCube1.f[4]')
pyNode.node().shadingGroups()
# Result: [nt.ShadingEngine(u'initialShadingGroup'), nt.ShadingEngine(u'blinn1SG')] #

pyNode = pm.PyNode('blinn1SG')
pyNode.members(flatten=True)
# Result: [MeshFace(u'pCubeShape1.f[4]')] #

Related How-To’s

Friday, September 14, 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 博主赞过: