一半君的总结纸

听话只听一半君

#92 如何从一个Shading Group得到和他相关的Material或者File Texture?

如果你查询 Shading Group 的所有上游节点,首先会找到 Material, 然后会找到 File Texture. 如果想得到 File Texture的图片文件名字, 可以查询file node的 ‘.fileTextureName’ attribute.

// ////////////////////////////////////////////////////////////////////
//  getMaterialFromSG
//
// Description: 返回连接到指定的Shading Group node (shadingEngine)的
// '.surfaceShader' 属性的Material node

proc string getMaterialFromSG( string $SG )
{
  string $material = "";

  if ( "shadingEngine" == `nodeType $SG` &&
    `connectionInfo -id ( $SG + ".surfaceShader" )` )
  {
    $material = rootNode( `connectionInfo -sfd
      ( $SG + ".surfaceShader" )` );
  }

  return $material;
}

// ////////////////////////////////////////////////////////
//   getTextureFromMaterial
//
// Description: 返回连接到指定的Material node的 '.color'
// 属性的 File Texture node

proc string getTextureFromMaterial( string $material )
{
  string $texture = "";

  string $class[] = getClassification( `nodeType $material` );

  if ( "shader/surface" == $class[0] && `connectionInfo -id
       ( $material + ".color" )` )
  {
    $texture = rootNode( `connectionInfo -sfd ( $material + ".color" )` );
  }

  return $texture;
}

加强版:

# 测试一下 怎么知道一个node是不是shader, 好弱感觉应该有更好的办法
pyNode = pm.PyNode('lambert2')
pyNode.classification()
# Result: [u'drawdb/shader/surface/lambert', u'shader/surface'] #
# lz不知道怎么返回所有shader的类型,所以就脑残的列出了最基本的几种
# 主要是想说明这样可以找到lambert2SG的所有upstream nodes里是指定类型的那些nodes
cmds.ls(*cmds.listHistory('lambert2SG'),type=['file','lambert','blinn','phong','phongE','anisotropic'])
# Result: [u'lambert2', u'file1'] #

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