Getting the image clips for a material


Given this render tree:

here’s a few snippets of JScript that show how to get the image clips for certain ports on the material (in this example, the diffuse and bump ports):

First, get the image clips from the sub-tree that’s plugged into the bump port:

SelectObj("Sources.Materials.DefaultLib.Material1.Lambert", null, null);

var s = Selection(0);
var sp = s.bump;

oEnum = new Enumerator( sp.Sources(0).Parent.ImageClips ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oSelItem = oEnum.item() ;
	LogMessage( classname( oSelItem ) + " " + oSelItem.Name );
}

Second, how to get the image clips when a port uses texture layers:

SelectObj("Sources.Materials.DefaultLib.Material1.Lambert", null, null);

var s = Selection(0);
var sp = s.diffuse;

var tl = s.TextureLayers(0);
var d = tl.TextureLayerPorts("diffuse_port")
if  ( d != null )
{
	LogMessage("diffuse driven by a Texture Layer");
}


oEnum = new Enumerator( tl.Parameters("Color").Source.Parent.ImageClips ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oSelItem = oEnum.item() ;
	LogMessage( classname( oSelItem ) + " " + oSelItem.Name );
}

Leave a Reply

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 /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s