Applies To
FindObjects command
Description
This example demonstrates how to use the FindObjects command.
Code
/* This example demonstrates how FindObjects can be used to quickly find all instances of a particular type of shader. This approach can be faster than doing a recursive search through all the scene shader trees. */ SetupDemoScene() ; LogMessage( DiscoverCloudClassID() ) ; //INFO : {A85CBE5F-DDD7-11D1-804A-00A0C906835D} LogMessage( DiscoverImageClassID() ) ; //INFO : {1C500B61-023C-11D3-8C03-00A0243E3672} var oAllClouds = FindCloudShaders() ; PrintCollection( oAllClouds, "All Cloud Shaders" ) ; //INFO : ------------------------------------------------ //INFO : All Cloud Shaders //INFO : ------------------------------------------------ //INFO : Sources.Materials.DefaultLib.Material.Phong.Cloud1 //INFO : Sources.Materials.DefaultLib.Material.Phong.Cloud1.Cloud2 //INFO : Sources.Materials.DefaultLib.Material1.Lambert.Cloud3 //INFO : Sources.Materials.DefaultLib.Material1.Lambert.Cloud3.Cloud4 //INFO : Sources.Materials.DefaultLib.Material1.Lambert.Cloud5 var oAllImages = FindImageShaders() ; PrintCollection( oAllImages, "All Image Shaders" ) ; //INFO : ------------------------------------------------ //INFO : All Image Shaders //INFO : ------------------------------------------------ //INFO : Sources.Materials.DefaultLib.Material.Phong.Image function FindCloudShaders() { // This GUID was determined by calling DiscoverCloudClassID(). // Because it never changes it can be hardcoded rather than // being re-discovered each time the script is run return FindObjects( null, "{A85CBE5F-DDD7-11D1-804A-00A0C906835D}" ) ; } function FindImageShaders() { // Using GUID returned by DiscoverImageClassID() return FindObjects( null, "{1C500B61-023C-11D3-8C03-00A0243E3672}" ) ; } // Function to determine the ClassID of the Cloud Shader // Similar code can work for custom shaders, and the GUID can also // be read from the SPDL file and is visible in the SDK Explorer function DiscoverCloudClassID() { var oTempCloud = XSIFactory.CreateObjectFromPreset( "Cloud", "Texture Shaders" ) ; var oCloudGUID = GetClassID( oTempCloud ) ; // Delete the shader right away so it doesn't appear when we search DeleteObj( oTempCloud ) ; return oCloudGUID ; } function DiscoverImageClassID() { var oTempImageNode = XSIFactory.CreateObjectFromPreset( "Image", "Texture Shaders" ) ; var oImageGUID = GetClassID( oTempImageNode ) ; DeleteObj( oTempImageNode ) ; return oImageGUID ; } // Determine the ClassID GUID of a particular object. // All other instances of this object have this same GUID // and it never changes. function GetClassID( in_ExampleObject ) { oDataRepository = XSIUtils.DataRepository ; return oDataRepository.GetIdentifier( in_ExampleObject, siObjectCLSID ) ; } // Build some render trees with the Object Model // They don't make any sense in terms of rendering // a nice texture, but show nodes connected in various ways function SetupDemoScene() { NewScene( null, false ) ; // First render tree oSphere = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" ) ; oSphere.AddMaterial( "Phong" ) ; var oPhongShader = oSphere.Material.Shaders(0) ; ImageFile1 = XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), "Data", "XSI_SAMPLES", "Pictures", "jaiqua_face.jpg" ) ; var oImageClip1 = SICreateImageClip2( ImageFile1 ).Item(0) ; var oAmbientParam = oPhongShader.Parameters( "ambient" ) var oImageNode1 = oAmbientParam.connectfrompreset("Image", siTextureShaderFamily) ; oImageNode1.Parameters( "tex" ).Connect( oImageClip1 ) ; var oDiffuseParam = oPhongShader.Parameters( "diffuse" ) var oCloud1 = oDiffuseParam.connectfrompreset("Cloud", siTextureShaderFamily) ; oCloud1.Name = "Cloud1" ; var oCloud1Color1 = oCloud1.Parameters("color1") ; var oCloud2 = oCloud1Color1.connectfrompreset("Cloud", siTextureShaderFamily) ; oCloud2.Name = "Cloud2" ; //Second render tree oCone = ActiveSceneRoot.AddGeometry( "Cone", "MeshSurface" ) ; oCone.AddMaterial( "Lambert" ) ; var oLamberShader = oCone.Material.Shaders(0) ; oDiffuseParam = oLamberShader.Parameters( "diffuse" ) ; var oCloud3= oDiffuseParam.connectfrompreset("Cloud", siTextureShaderFamily); oCloud3.Name = "Cloud3" ; oCloud3Color2 = oCloud3.Parameters( "color2" ) ; oCloud4= oCloud3Color2.connectfrompreset("Cloud", siTextureShaderFamily); oCloud4.Name = "Cloud4" // Fractal is connected twice. This can provide a tricky // scenario for recursive scans of a shader tree, because the // same shaders can appear multiple times. // But FindObjects() would have not trouble finding just one instance // of this object oCloud3Color1 = oCloud3.Parameters( "color1" ) ; oCloud3Color1.Connect( oCloud4 ) ; oAmbientParam = oLamberShader.Parameters( "ambient" ) ; oCloud5 = oAmbientParam.connectfrompreset("Cloud", siTextureShaderFamily) ; oCloud5.Name = "Cloud5" ; } // Show contents of a XSICollection object in the Script history function PrintCollection( in_col, in_title ) { LogMessage( "------------------------------------------------" ) ; LogMessage( in_title ) ; LogMessage( "------------------------------------------------" ) ; for ( var i = 0 ; i < in_col.Count ; i++ ) { LogMessage( in_col(i).FullName ) ; } }
Related Examples
Keywords
FindObjects
Autodesk Softimage 2011