Initial commit and push

This commit is contained in:
2021-05-12 16:38:14 -05:00
parent d9b8ad1292
commit f2efb7c42d
104 changed files with 34330 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
'''
UI functionality for the cloth dialog.
'''
xsi = Application
from win32com.client import constants as const
import win32com.client
import softimage
sigen = softimage.SIGeneral()
ADDONPATH = xsi.InstallationPath(const.siUserAddonPath)
def del_prop_OnClicked():
ppg = PPG.Inspected(0)
remove_fixed(PPG.Inspected(0))
xsi.DeleteObj(ppg)
PPG.Close()
def pick_fixed_OnClicked():
ppg = PPG.Inspected(0)
xsi.SelectObj(ppg.Parent)
xsi.SetPointSelectionFilter()
picked = xsi.PickElement('point', 'Pick Points', 'Pick Points')
remove_fixed(PPG.Inspected(0))
xsi.CreateClusterFromSubComponent(picked[2], 'ZEFixedPoints')
def remove_fixed_OnClicked():
remove_fixed(PPG.Inspected(0))
def add_fixed_OnClicked():
xsi.SetPointSelectionFilter()
picked = xsi.PickElement('point', 'Pick Points', 'Pick Points')
fixed = get_fixed_cluster(PPG.Inspected(0).Parent)
if fixed:
xsi.SIAddToCluster(fixed, picked[2])
return
xsi.CreateClusterFromSubComponent(picked[2], 'ZEFixedPoints')
def pick_coll_OnClicked():
picked = xsi.PickElement('object', 'Pick Collision Object(s)', 'Pick Collision Object(s)')
ppg = PPG.Inspected(0)
ppg.Parameters('collisions').Value = ','.join(element.FullName for element in picked[2])
def remove_coll_OnClicked():
ppg = PPG.Inspected(0)
ppg.Parameters('collisions').Value = ''
def add_coll_OnClicked():
ppg = PPG.Inspected(0)
ppg.Parameters('collisions').Value = ','.join(element.FullName for element in xsi.Selection)
def select_coll_OnClicked():
ppg = PPG.Inspected(0)
if ppg.Parameters('collisions').Value:
collisions = ppg.Parameters('collisions').Value.split(',')
xsi.SelectObj(collisions)
####################################################################
def remove_fixed(ppg):
if not ppg.Parent.ActivePrimitive.GetGeometry2(0):
return
fixed = get_fixed_cluster(ppg.Parent)
if fixed:
xsi.DeleteObj(fixed)
def find_model(objName):
xsifact = win32com.client.Dispatch("XSI.Factory")
oColl = xsifact.CreateObject("XSI.Collection")
oColl.items = objName
if oColl.Count > 0:
return oColl(0)
else:
return False
def get_fixed_cluster(model):
geo = model.ActivePrimitive.GetGeometry2(0)
for cls in geo.Clusters:
if 'ZEFixed' in cls.Name:
return cls
def get_cloth_prop(model):
try:
if model:
for prop in model.Properties:
if 'ZECLoth' in prop.Name:
return prop
except:
return False

View File

@@ -0,0 +1,122 @@
'''
UI functionality for the export dialog.
'''
from win32com.client import constants as const
import win32com.client
import softimage
import zetcore
import zetexport
reload(zetcore)
reload(softimage)
reload(zetexport)
xsi = Application
addonpath = xsi.InstallationPath(const.siUserAddonPath)
sigen = softimage.SIGeneral()
def store_flags_OnClicked():
settings = zetcore.load_settings('export', PPG.Inspected(0))
zetcore.save_settings('export', settings)
sigen.msg('Stored.')
return
def exportbutton_OnClicked():
settings = zetcore.load_settings('export', PPG.Inspected(0))
export = zetexport.Export(xsi, settings)
try:
export.export()
except SystemExit:
return
except Exception as e:
if sigen.msg('Encountered an error while exporting, copy error to clipboard?', const.siMsgYesNo) == 6:
import win32clipboard, traceback
log_path = zetcore.get_export_log_path()
lines = []
if log_path:
with open(log_path, 'r') as file_handle:
lines = file_handle.readlines()[-15:]
message = ['Last 15 log lines:', '\n']
message.extend(['\t{0}'.format(line.strip('\n')) for line in lines])
message.extend(('\n', 'Traceback:', '\n'))
message.extend(['\t{0}'.format(element) for element in traceback.format_exc().split('\n')])
message = '\n'.join(message)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(message, win32clipboard.CF_TEXT)
win32clipboard.CloseClipboard()
else:
raise
return
def check_sel_OnClicked():
mdls = sigen.get_all_children(xsi.Selection(0))
if not mdls:
sigen.msg('No models selected.')
return
checksel = zetcore.CheckSel(xsi, mdls, xsi.ActiveSceneRoot, softimage.SIProgressBar())
checksel.check()
checksel.build_UI()
def help_OnClicked():
ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'Export Help')
lay = ps.PPGLayout
lay.Language = "pythonscript"
agr = lay.AddGroup
egr = lay.EndGroup
text = lay.AddStaticText
agr('Auto-Overwrite', 1)
text('Overwrites output files if they already exist.')
egr()
agr('Root model name for .msh filename')
text('''Usees the name of the hierarchy root as filename.
Has to be enabled when using Batch Export.''')
egr()
agr('Batch Export', 1)
text('''Loops through all direct children of the current
selection and exports each one with all its children. Root
model name for .msh filename has to be enabled for this.''')
egr()
agr('Animation')
text('''Exports animation from the current frame range.
Current frame as Basepose only exports the selected frame
and the following to minimize file size. Export Animation
has to be enabled.''')
egr()
agr('Buttons')
text('''Check Sel iterates through the current hierarchy and analyses
every model for problems which could break the export and smaller
problems like unnecessary clusters.
Store Flags stores the current config(path, checked boxes etc).
Export should be self-explanatory.''')
egr()
xsi.InspectObj(ps, '', 'Export Help', 4, False)
for prop in xsi.ActiveSceneRoot.Properties:
if prop.Name == 'Export_Help':
xsi.DeleteObj('Export_Help')
def basepose_OnChanged():
ppg = PPG.Inspected(0)
if ppg.Parameters('basepose').Value:
ppg.Parameters('anim').Value = True
def anim_OnChanged():
ppg = PPG.Inspected(0)
if not ppg.Parameters('anim').Value:
ppg.Parameters('basepose').Value = False
def batch_OnChanged():
ppg = PPG.Inspected(0)
if ppg.Parameters('batch').Value:
ppg.Parameters('rootname').Value = True
def EClose_OnClicked():
PPG.Close()
xsi.DeleteObj('MSHExport')

View File

@@ -0,0 +1,115 @@
'''
UI functionality for the import dialog.
'''
import softimage
import zetcore
import zetimport
reload(softimage)
reload(zetcore)
reload(zetimport)
from win32com.client import constants as const
xsi = Application
ADDONPATH = xsi.InstallationPath(const.siUserAddonPath)
sigen = softimage.SIGeneral()
def store_flags_OnClicked():
settings = zetcore.load_settings('import', PPG.Inspected(0))
zetcore.save_settings('import', settings)
sigen.msg('Stored.')
return
def btexpath_OnChanged():
ppg = PPG.Inspected(0)
checked = ppg.Parameters('btexpath').Value
texpath = ppg.Parameters('texpath')
texpath.SetCapabilityFlag(2, not checked)
def help_OnClicked():
ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'ImportHelp')
lay = ps.PPGLayout
lay.Language = "pythonscript"
agr = lay.AddGroup
egr = lay.EndGroup
text = lay.AddStaticText
agr('Import')
text('Imports null-chain and animations from an animation .msh.')
egr()
agr('Texture Folder')
text('''Sets the texture paths to that folder. If the box is unchecked the paths
will be set to the path of the .msh file.''')
egr()
agr('Set Frame Range')
text('''Automatically sets the frame range from the animated frames in the
.msh file.''')
egr()
agr('Apply animation')
text('''Only applies the unpacked animation to the selected hierarchy. Doesn't
import geometry/models or materials.''')
egr()
agr('Null Display Size')
text('''Sets the display size of Nulls. Improves cleanness of the null
chain after import.''')
egr()
agr('Ignore Geometry')
text('''Ignore geometry on import.''')
egr()
agr('Ignore Geometry')
text('''Ignore animation on import.''')
egr()
agr('Color Nulls')
text('''Colors nulls according to type(bone, root, eff).''')
egr()
agr('Hide Effs/Roots')
text('''Hides nulls of the specified type on import.
Type is defined from certain strings appearing in the name:
bone_l_leg is a bone, even if it's no animated/weighted to.''')
egr()
agr('Weld Boundary Edges')
text('''Applies a Weld Op to all geo models with a value of 0.01. The Operator
will persist after the import.''')
egr()
xsi.InspectObj(ps, '', 'ImportHelp', 4, False)
for prop in xsi.ActiveSceneRoot.Properties:
if prop.Name == 'ImportHelp':
xsi.DeleteObj('ImportHelp')
def importbutton_OnClicked():
settings = zetcore.load_settings('import', PPG.Inspected(0))
import_ = zetimport.Import(xsi, settings)
try:
import_.import_()
except SystemExit:
return
except Exception as e:
if sigen.msg('Encountered an error while importing, copy error to clipboard?', const.siMsgYesNo) == 6:
import win32clipboard, traceback
log_path = zetcore.get_import_log_path()
lines = []
if log_path:
with open(log_path, 'r') as file_handle:
lines = file_handle.readlines()[-15:]
message = ['Last 15 log lines:', '\n']
message.extend(['\t{0}'.format(line.strip('\n')) for line in lines])
message.extend(('\n', 'Traceback:', '\n'))
message.extend(['\t{0}'.format(element) for element in traceback.format_exc().split('\n')])
message = '\n'.join(message)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
try:
win32clipboard.SetClipboardText(message, win32clipboard.CF_TEXT)
except TypeError:
win32clipboard.SetClipboardText(message)
win32clipboard.CloseClipboard()
else:
raise
return
def EClose_OnClicked():
PPG.Close()
xsi.DeleteObj('MSHImport')

View File

@@ -0,0 +1,256 @@
'''
UI functionality for the material manager.
'''
from win32com.client import constants as const
import win32com.client
xsi = Application
addonpath = xsi.InstallationPath(const.siUserAddonPath)
PROJECTPATH = xsi.InstallationPath(const.siProjectPath)
def close_mat_OnClicked():
PPG.Close()
xsi.DeleteObj('MaterialEdit')
def help_mat_OnClicked():
ps = xsi.ActiveSceneRoot.AddProperty('CustomProperty', False, 'MatManagerHelp')
lay = ps.PPGLayout
lay.Language = 'pythonscript'
agr = lay.AddGroup
egr = lay.EndGroup
text = lay.AddStaticText
agr('Create', 1)
text('''Create a phong material(the only supported material type)
with the specified name(line edit to the left of this button.''')
egr()
agr('Edit', 1)
text('''Inspect the first selected material ZE flags and options can be
found here, too.''')
egr()
agr('ZEify / De-ZEify', 1)
text('''Adds/Removes Zero Engine flags and material settings to the
selected material(s).''')
egr()
agr('Remove', 1)
text('''Removes the selected material(s).''')
egr()
agr('Assign Tex', 1)
text('''A shortcut to assign a texture to the diffuse slot of
the selected material. This will launch a file browser.''')
egr()
agr('Assign / Unassign', 1)
text('''Assigns/unassigns the first selected material to the
currently selected models.''')
egr()
xsi.InspectObj(ps, '', 'MatManagerHelp', 4, False)
for prop in xsi.ActiveSceneRoot.Properties:
if prop.Name == 'MatManagerHelp':
xsi.DeleteObj('MatManagerHelp')
def del_mat_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
lay = ppg.PPGLayout
listbox = lay.Item('materials')
items = listbox.UIItems
items2 = list(items[:])
for matname in split:
for mat in materials:
if mat.Name == matname:
xsi.DeleteObj(mat)
break
refresh()
PPG.Refresh()
def create_mat_OnClicked():
ppg = PPG.Inspected(0)
name = ppg.Parameters('mat_name').Value
args = '$XSI_DSPRESETS\\Shaders\\Material\\Phong', name, '', '', False, ''
xsi.SICreateMaterial(*args)
refresh()
def edit_mat_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
for mat in materials:
if mat.Name == split[0]:
xsi.InspectObj(mat)
def add_flags_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
for matname in split:
for mat in materials:
if mat.Name == matname:
if not get_msh_material_property(mat):
add_msh_material_flags(mat)
break
refresh()
def del_flags_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
for matname in split:
for mat in materials:
if mat.Name == matname:
prop = get_msh_material_property(mat)
if prop:
xsi.DeleteObj(prop)
break
refresh()
def unassign_mat_OnClicked():
if xsi.Selection.Count == 0:
msg_box('No objects selected.')
return
xsi.SIUnAssignMaterial(xsi.Selection)
def assign_mat_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
mat2assign = None
for mat in materials:
if mat.Name == split[0]:
mat2assign = mat
break
if xsi.Selection.Count == 0:
msg_box('No objects selected.')
return
for item in xsi.Selection:
if item.Type == 'polySubComponent':
cls = item.SubComponent.CreateCluster('matpolycls')
xsi.SIAssignMaterial(cls, mat2assign)
elif item.Type == 'poly':
xsi.SIAssignMaterial(item, mat2assign)
elif item.Type == 'polymsh':
xsi.SIAssignMaterial(item, mat2assign)
refresh()
def assign_tex_OnClicked():
materials = get_scene_materials()
ppg = PPG.Inspected(0)
sel = ppg.Parameters('materials').Value
split = sel.split(';')
mats = []
for matname in split:
for mat in materials:
if mat.Name == matname:
mats.append(mat)
break
xsiui = win32com.client.Dispatch('XSI.UIToolkit')
fb = xsiui.FileBrowser
fb.DialogTitle = 'Select a .tga file'
fb.InitialDirectory = PROJECTPATH
fb.Filter = 'TARGA (*.tga)|*.tga||'
fb.ShowOpen()
img_filepath = fb.FilePathName
if img_filepath:
for mat in mats:
shader = xsi.CreateShaderFromPreset('$XSI_DSPRESETS\\Shaders\\Texture\\Image.Preset', mat)
img_clip = xsi.SICreateImageClip2(img_filepath)
xsi.SIConnectShaderToCnxPoint(img_clip, shader.tex, False)
xsi.SIConnectShaderToCnxPoint(shader, mat.Shaders(0).Parameters('diffuse'), False)
##############################################################################
###################### HELPER FUNCTIONS ##################################
def refresh():
mats = get_scene_materials('variants')
PPG.Inspected(0).PPGLayout.Item('materials').UIItems = mats
PPG.Refresh()
def msg_box(message):
XSIUIToolkit.MsgBox(message, 0, 'XSIZETools')
return True
def get_msh_material_property(material):
for prop in material.Properties:
if 'ZeroEngine_Flags' in prop.Name:
return prop
def add_msh_material_flags(mat):
pset = mat.AddProperty('CustomProperty', False, 'ZeroEngine Flags')
pset.AddParameter3('tex1', const.siString)
pset.AddParameter3('tex2', const.siString)
pset.AddParameter3('tex3', const.siString)
pset.AddParameter3('emissive', const.siBool, 0, '', '', 0)
pset.AddParameter3('glow', const.siBool, 0, '', '', 0)
pset.AddParameter3('transparency', const.siInt4, 0, 0, 2, 0)
pset.AddParameter3('hardedged', const.siBool, 0, '', '', 0)
pset.AddParameter3('perpixel', const.siBool, 0, '', '', 0)
pset.AddParameter3('additive', const.siBool, 0, '', '', 0)
pset.AddParameter3('specular', const.siBool, 0, '', '', 0)
pset.AddParameter3('rendertype', const.siInt4, 0, 0, 31, 0)
pset.AddParameter3('data0', const.siInt4, 0, 0, 255, 0)
pset.AddParameter3('data1', const.siInt4, 0, 0, 255, 0)
lay = pset.PPGLayout
lay.AddGroup('ZeroEngine Material Flags', 1)
lay.AddGroup('Additional Textures', 1)
lay.AddItem('tex1', 'Texture 1')
lay.AddItem('tex2', 'Texture 2')
lay.AddItem('tex3', 'Texture 3')
lay.EndGroup()
lay.AddGroup('Flags', 1)
lay.AddItem('emissive', 'Emissive')
lay.AddItem('glow', 'Glow')
lay.AddItem('transparency', 'Transparency')
lay.AddItem('hardedged', 'Hardedged Transparency')
lay.AddItem('perpixel', 'Per-Pixel Lighting')
lay.AddItem('additive', 'Additive Transparency')
lay.AddItem('specular', 'Specular')
lay.AddItem('rendertype', 'RenderType')
lay.AddItem('data0', 'Data0')
lay.AddItem('data1', 'Data1')
lay.EndGroup()
lay.EndGroup()
def get_scene_materials(listtype='list'):
mats = []
matlibs = xsi.ActiveProject.ActiveScene.MaterialLibraries
for lib in matlibs:
for mat in lib.Items:
mats.append(mat)
if listtype == 'variants':
newmats = []
for index, mat in enumerate(mats):
name = [mat.Name]
prop = get_msh_material_property(mat)
usedby = mat.UsedBy
if usedby.Count > 0:
if prop:
name.append(' - ZE | {0}'.format(usedby.Count))
else:
name.append(' - {0}'.format(usedby.Count))
else:
if prop:
name.append(' - ZE')
newmats.append(''.join(name))
newmats.append(mat.Name)
return newmats
return mats

View File

@@ -0,0 +1,31 @@
'''
UI functionality for several misc dialogs.
'''
from win32com.client import constants as const
import webbrowser
xsi = Application
def close_csr_OnClicked():
PPG.Close()
xsi.DeleteObj('CSR')
def ERClose_OnClicked():
PPG.Close()
xsi.DeleteObj('ExportReport')
def launch_gt_OnClicked():
url = 'http://gametoast.com/viewtopic.php?f=36&t=26664'
webbrowser.open_new_tab(url)
def launch_website_OnClicked():
url = 'http://schlechtwetterfront.github.io/xsizetools/'
webbrowser.open_new_tab(url)
def Close_OnClicked():
PPG.Close()
xsi.DeleteObj('ZETH')

View File

@@ -0,0 +1,46 @@
'''
UI functionality for the msh2text dialog.
'''
xsi = Application
import msh2
reload(msh2)
import msh2_unpack
reload(msh2_unpack)
import os
TXTPATH = 'C:\\SWBF2_ModTools\\data_TST\\Worlds\\TST\\msh\\test\\abc.txt'
MSHPATH = 'C:\\SWBF2_ModTools\\data_TST\\Worlds\\TST\\msh\\nab2_prop_fountain.msh'
USE_HARD_PATHS = False
def get_paths():
params = PPG.Inspected(0).Parameters
if USE_HARD_PATHS or params('dev').Value:
return MSHPATH, TXTPATH
return params('mshpath').Value, params('txtpath').Value
def msh2txt_OnClicked():
mshpath, txtpath = get_paths()
if not mshpath or not txtpath:
return
unpacker = msh2_unpack.MSHUnpack(mshpath)
msh = unpacker.unpack()
if PPG.Inspected(0).Parameters('segmented').Value is True:
msh.save_segmented_json(os.path.dirname(txtpath), os.path.basename(txtpath.split('.')[0]))
else:
msh.save_json(txtpath)
def txt2msh_OnClicked():
mshpath, txtpath = get_paths()
if not mshpath or not txtpath:
return
if PPG.Inspected(0).Parameters('segmented').Value is True:
msh = msh2.Msh.load_segmented_json(os.path.dirname(txtpath), os.path.basename(txtpath.split('.')[0]))
else:
msh = msh2.Msh.load_json(txtpath)
if PPG.Inspected(0).Parameters('dev').Value:
msh.save(mshpath + '.msh')
else:
msh.save(mshpath)

View File

@@ -0,0 +1,43 @@
'''
Scripts UI functionality.
'''
from win32com.client import constants as const
import softimage
reload(softimage)
xsi = Application
addonpath = xsi.InstallationPath(const.siUserAddonPath)
def makeaddon_OnClicked():
oPPG = PPG.Inspected(0)
addon_bone = oPPG.Parameters("addon_bone").Value
print addon_bone, type(addon_bone)
# Make sure the item is valid.
# If no bones were found the item will be set to '1'.
if addon_bone == '1':
return
addon_root_name = oPPG.Parameters("addon_root_name").Value
xsi.GetPrim("Null", addon_root_name)
xsi.MatchTransform(addon_root_name, addon_bone)
def setmesh_OnClicked():
sel = xsi.Selection
if sel.Count > 0:
params = PPG.Inspected(0).Parameters
root_name = params("addon_root_name").Value
is_shadowvolume = params("addon_is_shadowvolume").Value
if softimage.Softimage.get_object(root_name):
if is_shadowvolume is True:
xsi.CopyPaste(sel[0], '', root_name)
selected_name = sel[0].Name
sel[0].Name = "sv_" + selected_name
elif is_shadowvolume is False:
for item in sel:
xsi.CopyPaste(item, '', root_name)
def groupbones_OnClicked():
bones = softimage.Softimage.get_objects('bone*')
if bones:
xsi.CreateGroup('Bones', bones)