Skip to content

Instantly share code, notes, and snippets.

@alaingalvan
Last active August 28, 2020 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaingalvan/070a0da87e5234b9299072b004e23251 to your computer and use it in GitHub Desktop.
Save alaingalvan/070a0da87e5234b9299072b004e23251 to your computer and use it in GitHub Desktop.
A Marmoset Toolbag plugin showcasing how to design a custom importer for the baker.
import mset
# Create a new BakerObject
baker = mset.BakerObject()
# Import model
myMesh = mset.importModel("E:/MyMesh.fbx")
# Traverse myMesh and find objects I want to be "High" or "Low"
bakerDict = {}
def traverseMesh(o):
if isinstance(o, mset.MeshObject):
if "_low" in o.name:
key = o.name.replace("_low", "").lower()
if key in bakerDict:
bakerDict[key]["low"] = o
else:
bakerDict[key] = {"low": o, "high": None}
if "_high" in o.name:
key = o.name.replace("_high", "").lower()
if key in bakerDict:
bakerDict[key]["high"] = o
else:
bakerDict[key] = {"low": None, "high": o}
for obj in o.getChildren():
traverseMesh(obj)
# Traverse the imported mesh file
traverseMesh(myMesh)
# Convert bakerDict to baker scene hierarchy
for key in bakerDict.keys():
if bakerDict[key]["low"] != None and bakerDict[key]["high"] != None:
curGroup = None
for child in baker.getChildren():
if key in child.name.lower():
curGroup = child
if curGroup == None:
curGroup = baker.addGroup(key)
for gc in curGroup.getChildren():
if gc.name == "Low":
bakerDict[key]["low"].parent = gc
if gc.name == "High":
bakerDict[key]["high"].parent = gc
# Done adding model, now we can bake
baker.bake()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment