一半君的总结纸

听话只听一半君

#43 How do I get the assigned Shading Group for an object or face component?

To determine which Shading Group is assigned to an object, trace downstream of the object’s shape node for all ‘shadingEngine’ nodes (a.k.a. Shading Groups).

// ////////////////////////////////////////////////////////////////////
//  getSGsFromShape
//
// Description: Returns an array of the Shading Groups (shadingEngine
//  nodes) responsible for shading the specified 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 can return duplicates within its list.
    // The select below is a quick trick to avoid dupes in the
    // returned array.
    if ( size( $dest ) )
    {
      string $select[] = `ls -sl`;
      select -r -ne $dest;
      $shadingEngines = `ls -sl`;
      select -r $select;
    }
  }

  return $shadingEngines;
}

Getting the Assigned Shading Group for a Face Component

Get a list of all Shading Groups in your scene and query the membership for each set to check if the target component is shaded by that shader.

proc string getFacetSG( string $facet )
// Input (string) - facet component to query (e.g. "pSphere1.f[0]")
// Result (string) - Shading Group shading facet (e.g. "lambert2SG")
{
  string $facetSG = "";

  // Get array of all Shading Groups
  string $shadingGroups[] = `ls -type shadingEngine`;

  for ( $shadingGroup in $shadingGroups )
  {
    // If this facet is a member of the shading set for this
    // Shading Group, tag this as the facet's shader
    if ( `sets -isMember $shadingGroup $facet` )
    {
      $facetSG = $shadingGroup;
      break;
    }
  }

  return $facetSG;
}

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