一半君的总结纸

听话只听一半君

#91 How do I determine which Shading Group is associated with a Material?

To determine which Material is associated to a Shading Group, get a list of all connection from the Material’s “.outColor” attribute. Iterate this array to find all Shading Groups. The ‘nodeType’ command will identify a Shading Group with the string “shadingEngine”.

// ////////////////////////////////////////////////////////////////////
//  getSGFromMaterial
//
// Description: Returns the Shading Group set whose '.surfaceShader'
//  attribute is being fed by the specified Material.
//
//  Returns an array for all Shading Groups using the Material.

global proc string[] getSGFromMaterial( string $material )
{
  string $SG[];

  // First, assert that $material is a Material.
  // (Returns a string array, unfortunately, so requires variable.)
  string $class[] = getClassification( `nodeType $material` );

  if ( $class[0] == "shader/surface" )
  {
    // Assert that there is a connection from the Material's .outColor
    if ( `connectionInfo -is ( $material + ".outColor" )` )
    {
      // There may be more than one connection...
      string $dests[] = `connectionInfo -dfs ( $material + ".outColor" )`;
      for ( $dest in $dests )
      {
        // Iterate through connections and identify ShadingGroup sets.
        if ( "shadingEngine" == `nodeType $dest` )
        {
          $SG[`size $SG`] = rootNode( $dest );
          break;
        }
      }
    }
  }

  return $SG;
}

Note: The following ‘rootNode()’ procedure is required by the procedures above.

// //////////////////////////////////////////////////////////////
//  rootNode
//
// Description: Strips the dot-suffix of the specified string.
//  e.g. "object.attribute" is returned as "object"

proc string rootNode( string $object )
{
  string $buffer[];
  tokenize $object "." $buffer;
  return $buffer[0];
}

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