一半君的总结纸

听话只听一半君

#32 已知图片路径,如何创建 Lambert shading network ?

下面是一个完整例子.

// 为了支持 Maya v4.5 里的新加的 place2dTexture 
proc float mayaVersion()
{
  float $version = (float)`about -v`;
  return $version;
}

// 一个辅助 procedure ,用来连接两个相同属性名字的 plugs 
proc connect( string $attr, string $place, string $file )
{
  connectAttr -f ( $place + "." + $attr ) ( $file + "." + $attr );
}

global proc makeShader( string $file )
{
  // 创建一个 Lambert Material 附带他的 Shading Group
  string $material = `shadingNode -asShader lambert -name myLambert`;
  string $SG = `sets -renderable true -noSurfaceShader true -empty -name myLambertSG`;
  connectAttr -f ( $material + ".outColor" ) ( $SG + ".surfaceShader" );

  // 创建一个 File Texture 节点并连接到 Material color
  string $fileNode = `shadingNode -asTexture file -name myFile`;
  connectAttr -f ( $fileNode + ".outColor" ) ( $material + ".color" );

  // 把图片文件路径赋予 file 节点
  setAttr -type "string" ( $fileNode + ".fileTextureName" ) $file;

  // 如果你想要一个 place2dTexture node, 如下运行
  string $placeName = ( "place_" + $fileNode );
  $placeName = `shadingNode -asUtility place2dTexture -name $placeName`;

  // 连接 place2dTexture node 上的属性
  // 注意: 下面用到了上面定义的 connect() proc 
  connect "coverage" $placeName $fileNode;
  connect "translateFrame" $placeName $fileNode;
  connect "rotateFrame" $placeName $fileNode;
  connect "stagger" $placeName $fileNode;
  connect "wrapU" $placeName $fileNode;
  connect "wrapV" $placeName $fileNode;
  connect "repeatUV" $placeName $fileNode;
  connect "offset" $placeName $fileNode;
  connect "rotateUV" $placeName $fileNode;

  // Maya v4.5 把 '.mirror' attribute 分成了
  // 'mirrorU' 和 '.mirrorV'
  if ( mayaVersion() < 4.5 )
  {
    connect "mirror" $placeName $fileNode;
  }
  else
  {
    connect "mirrorU" $placeName $fileNode;
    connect "mirrorV" $placeName $fileNode;
  }

  // 把 placement UV plugs 连接到 file node
  connectAttr -f ( $placeName + ".outUV" ) ( $fileNode + ".uv" );
  connectAttr -f ( $placeName + ".outUvFilterSize" ) ( $fileNode + ".uvFilterSize" );
}

使用方法, 调用 ‘makeShader’ 后面加上图片文件的路径; 如:

makeShader "D:/projects/images/scalySkin.iff";

22 December 2002

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