#-------------IMPORT LIBRARIES-------------# import win32com from win32com.client import constants as c xsi = win32com.client.Dispatch( 'XSI.Application' ).application #-------------INSTANTIATE VARIABLES-------------# xsi = win32com.client.Dispatch( 'XSI.Application' ).application oObj = Application.Selection log = xsi.LogMessage #-------------DEFINE FUNCTIONS-------------# def generate_wf_uvs ( inputObject ): xsi.CreateProjection(str(inputObject), "siTxtCubic", "siTxtDefaultCubic", "", "UV1", "", "", "") xsi.GenerateUniqueUVs(str(inputObject), "UV2", "", "", "", "", "", "", "") xsi.FreezeObj(str(inputObject), "", "") def DeleteAllClusters( inputObj ): inputObj = xsi.Selection(0) try: for oCluster in inputObj.activeprimitive.geometry.clusters: if xsi.classname( oCluster ) == 'Cluster' and oCluster.type == 'poly': xsi.DeleteObj(oCluster) except: pass def oSaveFile(): oUIToolkit = win32com.client.Dispatch( "XSI.UIToolKit" ) initialDir = "C:\\wf_trunk\\3d_objects\\" oFileBrowser = oUIToolkit.FileBrowser oFileBrowser.DialogTitle = "Save a file" oFileBrowser.InitialDirectory = initialDir oFileBrowser.Filter = "All Files (*.*)|*.*||" oFileBrowser.ShowSave() return oFileBrowser def querySampleCluster (inputObj, oGeoClusters): oClusterArray = [] for i in oGeoClusters: if (i.type not in oClusterArray): oClusterArray.append(str(i.type)) return oClusterArray def renderAO ( inputObj ): oSelection = inputObj(0) originalSelection = inputObj(0).FullName initialPath = oSaveFile () if (initialPath.FilePathName != "" ): xsi.LogMessage( '\nDetails on the file that was selected:' ) xsi.LogMessage( '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') xsi.LogMessage( 'File path name : ' + initialPath.FilePathName) xsi.LogMessage( 'File Name : ' + initialPath.FileName) xsi.LogMessage( 'File base name : ' + initialPath.FileBaseName) xsi.LogMessage( 'File extension : ' + initialPath.FileExtension) xsi.LogMessage( 'Path : ' + initialPath.FilePath) xsi.ToggleVisibility("", "", "") xsi.Duplicate(inputObj, "", 2, 0, 1, 0, 0, 1, 0, 0, "", "", "", "", "", "", "", "", "", "", 0) xsi.SetValue(".Name", "ao_msh", "") xsi.ToggleVisibility("", "", "") oRenderMapSel = xsi.SelectObj("ao_msh", "", "") xsi.FreezeObj("", "", "") DeleteAllClusters( oRenderMapSel ) xsi.MakeLocal(str(oSelection.FullName) + ".geomapprox", "siDefaultPropagation") xsi.SetValue(str(oSelection.FullName) +".geomapprox.gapproxmoan", 100, "") xsi.CopyPaste("", "C:\\wf_trunk\\resources\\xsi_shaders\\shaders\\ambient_occlusion_mat.Preset", "ao_msh", 2) xsi.AddProp("RenderMap", "", "", "", "") xsi.SetValue("ao_msh.RenderMap.attribute", 3, "") xsi.SetInstanceDataValue("", "ao_msh.RenderMap.uvprop", "UV2") xsi.SetValue("ao_msh.RenderMap.resolutionx", "1024", "") xsi.SetValue("ao_msh.RenderMap.imageformat", "png", "") xsi.SetValue("ao_msh.RenderMap.imagedatatype", "RGB", "") xsi.SetValue("ao_msh.RenderMap.imagefilepath", str(initialPath.FilePathName), "") xsi.RegenerateMaps("ao_msh.RenderMap") xsi.DeleteObj("ao_msh.RenderMap") xsi.DeleteObj("ao_msh") xsi.ToggleVisibility(oSelection.FullName, "", "") else: xsi.LogMessage("User pressed cancel" ) #-------------MAIN SOURCE -------------# if (oObj(0) > 0): oGeometry = oObj(0).ActivePrimitive.Geometry oClusters = oGeometry.Clusters #log ("The number of clusters in this object is " + str(oObj.count) ) if (oClusters.count == 0): log ("No clusters.......") generate_wf_uvs (oObj(0)) elif (oClusters.count > 0): if ('sample' not in querySampleCluster (oObj(0), oClusters)): log ("No UV channels... \nGenerating UV1 and UV2") generate_wf_uvs (oObj(0)) for i in range( oClusters.count): if (oClusters(i).type == 'sample'): UVSampleName = (oClusters(i).name) oLocalProps = oClusters(i).localproperties if (oClusters(i).localproperties.count == 0): log("Cluster.type \"sample\" exists but no UV sets.... \n Generate UV1 and UV2 SecondPart") generate_wf_uvs (oObj(0)) for i in range(oLocalProps.count): if (oLocalProps.count == 1): log("generating UV2") xsi.RenamePropAndRebind(str(oObj(0).FullName) + ".polymsh.cls." + str(UVSampleName) + "." + str(oLocalProps(0).Name), "UV1", "", "", "") xsi.GenerateUniqueUVs(str(oObj(0).FullName), "UV2", "", "", "", "", "", "", "") xsi.SetValue(str(oObj(0).FullName) + ".polymsh.cls." + str(UVSampleName) + ".UV2.PolyPackUV.grouptol", 30, "") xsi.FreezeObj(str(oObj(0).FullName), "", "") elif (oLocalProps(0).name != 'UV1' ): log("Renaming " + str(oLocalProps(0).FullName) + " to UV1") xsi.RenamePropAndRebind(str(oObj(0).FullName) + ".polymsh.cls." + str(UVSampleName) + "." + str(oLocalProps(0).Name), "UV1", "", "", "") elif (oLocalProps(1).name != 'UV2'): xsi.RenamePropAndRebind(str(oObj(0).FullName) + ".polymsh.cls." + str(UVSampleName) + "." + str(oLocalProps(1).Name), "UV2", "", "", "") renderAO(oObj) elif (xsi.Selection.count == 0): log ("Select a polymesh")