8,484
edits
Paradox-01 (talk | contribs) No edit summary  | 
				Paradox-01 (talk | contribs)  m (TwoSided-ness for main material, looking forward to do the same for polygon clusters ~cough cough sarcasm~)  | 
				||
| Line 164: | Line 164: | ||
====Materials and textures====  | |||
'''get all targets of an image clip'''  | '''get all targets of an image clip'''  | ||
| Line 202: | Line 203: | ||
'''check an object's main material for TwoSided-ness'''  | |||
 ' test and toggles an object's main material for TwoSided-ness  | |||
 ' this is also a prerequired test for transparency  | |||
 ' the difficulty is to get the TextureObject (often named Image)  | |||
 ' the magic happens at FindShaders, I often fail to find such trivial stuff  | |||
 ' imo the xsi is terrible incomplete/unintuitive  | |||
 ' e.g. look at "Find (ShaderCollection)" in the help  | |||
 ' it will give you information about meshes such as cubes ...  | |||
 matLib = selection(0).Materials(0).Library.name  | |||
 set mat = selection(0).Material  | |||
 materialName = mat.name  | |||
 ' let us see if there is an Image TextureObject  | |||
 set shaders = mat.FindShaders(siShaderFilter)  | |||
 textureObj = "Image"  | |||
 'if typename(shaders(textureObj)) = "Texture" then ' if not it is Nothing  | |||
 '	logmessage "material has texture object ""Image"""  | |||
 'end if  | |||
 Set list = CreateObject("System.Collections.ArrayList")  | |||
 for each n in shaders  | |||
 	list.Add n.name  | |||
 next  | |||
 foundShaderParameterTransparency = false  | |||
 'foundUniqueShaderName = false  | |||
 shaderName = ""  | |||
 if list.Contains(textureObj) = true then  | |||
 	set oColorShareShader = GetValue("Sources.Materials." & matLib & "." & mat.name & "." & textureObj)  | |||
 	set oTargets = oColorShareShader.GetShaderParameterTargets("")  | |||
 	scriptObjArray = split(oTargets(0), ".")  | |||
 	'logmessage scriptObjArray(0) ' Sources (fixed name? Could be considered a folder.)  | |||
 	'logmessage scriptObjArray(1) ' Materials (fixed name? Could be considered a folder.)  | |||
 	'logmessage scriptObjArray(2) ' MaterialsLib (usually each object has its own MaterialsLib)  | |||
 	'logmessage scriptObjArray(3) ' Material  | |||
 	'logmessage scriptObjArray(4) ' Shader e.g. Phong  | |||
 	shaderName = scriptObjArray(4)  | |||
 	for each t in oTargets  | |||
 		logmessage t  | |||
 		if t.name = "transparency" then  | |||
 			foundShaderParameterTransparency = true  | |||
 			exit for  | |||
 		end if  | |||
 	next  | |||
 end if  | |||
 if foundShaderParameterTransparency = false then  | |||
 	logmessage "material is not TwoSided, lets reverse now"  | |||
 	SIConnectShaderToCnxPoint "Sources.Materials." & matLib & "." & materialName & ".Image", "Sources.Materials." & matLib & "." & materialName & "." & shaderName & ".transparency", False  | |||
 else  | |||
 	logmessage "material is TwoSided, lets reverse now"  | |||
 	RemoveAllShadersFromCnxPoint "Sources.Materials." & matLib & "." & materialName & "." & shaderName & ".transparency", siShaderCnxPointBasePorts  | |||
 end if  | |||
Output example:  | |||
 ' INFO : Sources.Materials.DefaultLib.Material.Phong.diffuse  | |||
 ' INFO : material is not TwoSided, lets reverse now  | |||
 SIConnectShaderToCnxPoint "Sources.Materials.DefaultLib.Material.Image", "Sources.Materials.DefaultLib.Material.Phong.transparency", False  | |||
 ' INFO : Sources.Materials.DefaultLib.Material.Phong.diffuse  | |||
 ' INFO : Sources.Materials.DefaultLib.Material.Phong.transparency  | |||
 ' INFO : material is TwoSided, lets reverse now  | |||
 RemoveAllShadersFromCnxPoint "Sources.Materials.DefaultLib.Material.Phong.transparency", siShaderCnxPointBasePorts  | |||
====Clusters====  | |||
 'does a certain cluster type exist ?  | |||
 'set cls = selection(0).activeprimitive.geometry.clusters.find( siPolygonCluster )  | |||
 ' more interesting is how many of that type exist  | |||
 for each n in selection(0).activeprimitive.geometry.clusters  | |||
    logmessage "Cluster " & n.name & " is of type " & n.type  | |||
 next  | |||
 ' "poly" = polygon cluster  | |||
 ' "sample" = UV cluster  | |||
Output example:  | |||
 ' INFO : Cluster Polygon4 is of type poly  | |||
 ' INFO : Cluster Polygon1 is of type poly  | |||
 ' INFO : Cluster Texture_Coordinates_AUTO is of type sample  | |||
====layers====  | |||
'''check if obj is member of layer'''  | '''check if obj is member of layer'''  | ||
  logmessage isMemberOfLayer(selection(0), "layerNameToTest")  |   logmessage isMemberOfLayer(selection(0), "layerNameToTest")  | ||
edits