Created
October 2, 2022 18:24
-
-
Save MineClever/b2f9001a02ed9aeb8362db630dc5e061 to your computer and use it in GitHub Desktop.
a simple script for Marmoset Toolbag help to make a ui add custom tangent setting for selected mesh / mesh group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _*_ coding=utf-8 _*_ | |
# a simple script help to make a ui add custom tangent setting for selected mesh / mesh group | |
import mset | |
class MTangentType (object): | |
tangent_type = ("Custom", | |
"Marmoset", | |
"Mikk", | |
"Maya", | |
"3D Studio Max", | |
"Unity") | |
# set Window | |
class MUIWindows (object): | |
def __init__(self): | |
self.window_title = "Set Custom Tangent Type" | |
self.ui_elements = [] | |
self.window = None | |
def draw_ui (self): | |
# Setup scroll box | |
scroll_box = mset.UIScrollBox() | |
scroll_box_window = mset.UIWindow(name="Scroll box Window") | |
scroll_box.containedControl = scroll_box_window | |
# add label | |
tip_label = mset.UILabel() | |
tip_label.fixedWidth = 10.0 | |
tip_label.text = u"This Tool Created By MineClever\nEmail:[email protected]\nChoose Model(s) To set TangentSpace !\n" | |
scroll_box_window.addElement(tip_label) | |
scroll_box_window.addStretchSpace() | |
scroll_box_window.addReturn() | |
# add close button | |
close_button = mset.UIButton("Close") | |
close_button.onClick = self.close_windows | |
# add set button | |
set_button = mset.UIButton("Set Tangent") | |
drawer = mset.UIDrawer(name="Settings") | |
drawer_window = mset.UIWindow(name="Drawer Window") | |
drawer.containedControl = drawer_window | |
drawer_window.addElement(close_button) | |
drawer_window.addReturn() | |
drawer_window.addElement(set_button) | |
# 📃 Lists | |
my_list = mset.UIListBox("Mode") | |
for item in MTangentType.tangent_type: | |
my_list.addItem(item) | |
my_list.selectItemByName(MTangentType.tangent_type[0]) | |
def set_function (): | |
mesh_tool = MSetAllMeshSelections(MMsetHelper.get_current_selections()) | |
mesh_tool.set_mesh_custom_tangent(custom_tangent_id=my_list.selectedItem) | |
set_button.onClick = set_function | |
drawer_window.addElement(my_list) | |
drawer_window.addReturn() | |
scroll_box_window.addElement(drawer) | |
scroll_box_window.addReturn() | |
self.ui_elements.append(scroll_box_window) | |
# 🎚️ Sliders | |
# slider = mset.UISliderInt(min=5, max=128, name="Slider") | |
# self.ui_elements.append(slider) | |
def close_windows(*args,**kw): | |
print ("close plugin \n") | |
mset.shutdownPlugin() | |
def show_windows(self): | |
print("draw window !\n") | |
window = mset.UIWindow(self.window_title) | |
self.window = window | |
self.draw_ui() | |
window.addStretchSpace() | |
window.addSpace(1.0) | |
for element in self.ui_elements: | |
window.addElement(element) | |
window.addReturn() | |
class MMsetHelper (object): | |
def __init__(self) -> None: | |
self.scene_objects : list[mset.SceneObject] = [] | |
pass | |
def refresh_all_scene_objects (self): | |
# Obtain a list of all toolbag objects | |
self.scene_objects = mset.getAllObjects() | |
# Print them out | |
print( "Scene Objects:" ) | |
for object in self.scene_objects: | |
print ( " - " + object.name ) | |
@staticmethod | |
def get_current_selections (): | |
selections = mset.getSelectedObjects() | |
# Print them out | |
print( "Selected Objects:" ) | |
for object in selections: | |
print ( " - " + object.name ) | |
return selections | |
class MSetAllMeshSelections(object): | |
def __init__(self, input_object_list): | |
# type: (list[mset.SceneObject]) -> None | |
self.mesh_list = [] # type:list[mset.MeshObject] | |
self.filter_mesh_objects(input_object_list) | |
def filter_mesh_objects (self,input_object_list): | |
# type:(list[mset.SceneObject]) -> None | |
temp_mesh_list = [] | |
for obj in input_object_list: | |
if isinstance(obj,mset.MeshObject): | |
temp_mesh_list.append(obj) | |
if isinstance(obj,mset.ExternalObject): | |
all_children = obj.getChildren() | |
for child in all_children: | |
if isinstance(child,mset.MeshObject): | |
temp_mesh_list.append(child) | |
self.mesh_list = temp_mesh_list | |
def set_mesh_custom_tangent (self,custom_tangent_id = 0): | |
# Marmoset cant load Enum, why ? | |
tangent_type = MTangentType.tangent_type | |
mesh_list = self.mesh_list | |
enum_custom_tangent = tangent_type[custom_tangent_id] | |
print ("set mesh tangent as : %s" % enum_custom_tangent) | |
for mesh in mesh_list: | |
mesh.tangentSpace = enum_custom_tangent | |
def run_script (*args, **kw): | |
ui_window = MUIWindows() | |
ui_window.show_windows() | |
if __name__ == "__main__": | |
print ("auto run !") | |
run_script() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment