一半君的总结纸

听话只听一半君

#69 How do I change a Material’s type – from Lambert to Blinn, for example – using MEL?

The drop-down menu in the Attribute Editor looks deceptively simple. By appearances it is simply switching a Material attribute from “Lambert” to “Blinn”, or some such.

In reality, what’s happening when you change the shading type is that Maya creates a brand new Material node of a different type, and uses the magic command replaceNode to match it to the original. This all happens from the Attribute Editor template script:

\AW\Maya3.0\scripts\AETemplates\AEshaderTypeNew.mel

The replaceNode command (implemented via a MEL script) can be found here:

\AW\Maya3.0\scripts\others\replaceNode.mel

Here are the commands to do it yourself:

// This would be your existing Lambert Material
string $shaderNode = "myLambert";

// This would be the desired Material type
string $replaceType = "blinn";

string $replaceWith = `createNode $replaceType`;

replaceNode $shaderNode $replaceWith;

// Not strictly necessary...
showEditor $replaceWith;

delete $shaderNode;

// Rename the new node to match the original.
rename $replaceWith $shaderNode;

Wednesday, August 29, 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 博主赞过: