PDA

View Full Version : Shader branches?


varunbondwal
09-08-2008, 03:19 PM
Is there any way to check which nodes of a shader ( like surface, realtime, volume etc) are conected to some other node. a way to check which nodes have connections and which have not?

varunbondwal
09-09-2008, 02:41 AM
i've found out how to do it .... :) thnx anyway

JDex
09-09-2008, 02:43 AM
i've found out how to do it .... :) thnx anyway

If you share your solution... someone searching for the same issue will get an answer.

varunbondwal
09-10-2008, 01:12 PM
oh sure.. will do, when i get it working perfect

varunbondwal
09-18-2008, 03:47 AM
OK guys.. heres the code for this one



// Finds all the materials used in the scene and then uses a recursive loop to browse //through the parameters (surface, volume, displacement.. etc) and find the image clips //used in those nodes
// Right now i've set it only to show images connected to surface and realtime nodes
// It may not necessarily show all the images in the XSI file as it doesnt consider the //materials not applied in the scene
// varunbondwal@yahoo.com, varunbondwal@exigent3d.com



// recursive function to find image clips nested in the surface node
function findShaderTarget(in_oSource)
{
if ((in_oSource.Parameters(1).Name=="tex")||(in_oSource.Parameters(1).Name=="input")||(in_oSource.Parameters(1).Name=="previous"))
{
for(var k=0;k<in_oSource.Parameters.Count;k++)
if(in_oSource.Parameters(k).Source!=null)
return findShaderTarget(in_oSource.Parameters(k).Source)
}
else
return in_oSource
}


// generalized recursive function to find image clips in any node, this instance is called for the realtime node from the main program
function findShaderTargetTree(in_oSource)
{
if ((in_oSource.Parameters(1).Name=="tex")||(in_oSource.Parameters(1).Name=="input")||(in_oSource.Parameters(1).Name=="previous"))
{
for(var k=0;k<in_oSource.Parameters.Count;k++)
if(in_oSource.Parameters(k).Source!=null)
findShaderTargetTree(in_oSource.Parameters(k).Source)
}
else
{
imageNodeNames.Add(in_oSource)
}
return 0
}





var oMaterial;
var in_oChildren = Application.ActiveSceneRoot.FindChildren() ;
var oColl = new ActiveXObject("XSI.Collection") ;
var oColl2 = new ActiveXObject("XSI.Collection") ;

var imageNodeNames = new ActiveXObject("XSI.Collection") ;

var oShaderParamColl = new ActiveXObject("XSI.Collection") ;

var oDataRep = XSIUtils.DataRepository ;
var imageClassID = "{22C3E8F8-CCEA-11D2-B35B-00105A1E70DE}"



for ( var j=0 ; j<in_oChildren.Count ; j++ )
{
if((in_oChildren.Item(j).Type=="polymsh")||(in_oChildren.Item(j).Type=="surfmsh")||(in_oChildren.Item(j).Type=="crvlist"))
{
oMaterial = in_oChildren.Item(j).Material;
oColl.Add(oMaterial ) ;
for(var i=0; i<oMaterial.Parameters.Count;i++)
{
if (oMaterial.Parameters(i).Source!= null)
{
var source2=oMaterial.Parameters(i).Source;
}
}
var abc = GetValue("Sources.Materials.DefaultLib." + oMaterial.Name + ".Surface.Name")
}
}

for (var iCounter = 0 ; iCounter < oColl.Count ; iCounter++ )
{
oColl2.Add(oColl(iCounter));
for(var count2=iCounter+1;count2<oColl.Count;count2++)
{
if(oColl(iCounter).Name==oColl(count2).Name)
{
oColl.RemoveItems(oColl(count2));
}
}
}
oColl.RemoveAll();
for (var iCounter = 0 ; iCounter < oColl2.Count ; iCounter++ )
{
oColl.Add(oColl2(iCounter));
for(var count2=iCounter+1;count2<oColl2.Count;count2++)
{
if(oColl2(iCounter).Name==oColl2(count2).Name)
oColl2.RemoveItems(oColl2(count2));
}
}
for (var iCounter = 0 ; iCounter < oColl.Count ; iCounter++ )
{
LogMessage("Images used in the material " + oColl(iCounter).Name ) ;

oMaterial=oColl(iCounter)
if(oMaterial.Surface.Source!=null)
{
oSurfMat=oMaterial.Surface.Source
LogMessage("The surface shader is " + oSurfMat.Name)

for(var i =0; i<oSurfMat.Parameters.Count;i++)
{
var param=oSurfMat.Parameters(i)
if(param.Source!=null)
{
result = findShaderTarget(param.Source)
var resultClassID = oDataRep.GetIdentifier( result, siObjectCLSID );
if(resultClassID==imageClassID)
{
LogMessage(" " + param.Name + ": " + result.Name + ": " + result.Source.Parameters("XRes").Value + "X" + result.Source.Parameters("YRes").Value)
}
}
}
}

if(oMaterial.Realtime.Source!=null)
{
oRealtimeMat=oMaterial.Realtime.Source
LogMessage("The realtime shader is " + oRealtimeMat.Name)
for(var i =0; i<oRealtimeMat.Parameters.Count;i++)
{
var param=oRealtimeMat.Parameters(i)
if(param.Source!=null)
{
result = findShaderTargetTree(param.Source)
}
}
}

LogMessage(imageNodeNames.Count + " maps are used in the realtime node")
for(var i=0; i<imageNodeNames.Count;i++)
{
var instance=imageNodeNames(i);
LogMessage(" " + instance.Parent.Name + ": " + instance.Name + " " +instance.Source.Parameters("XRes").Value + "X" + imageNodeNames(i).Source.Parameters("YRes").Value)
}
imageNodeNames.RemoveAll()
LogMessage("\n")
}

ThE_JacO
09-18-2008, 06:15 AM
btw you can post code within code tags, it will make for a much better layout by preserving formatting and using a monospaced font.
same as quotes but with code in the tag, like:

this is a [ code] tag and code goes here

CGTalk Moderation
09-18-2008, 06:15 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.