Home Marmoset

Bake mech with multiple material sets via python

Hi guys,

I'm baking a lot of stuff in marmoset using python api, however today I've found that when I set baker.multipleTextureSets = True Marmoset found 0 texture sets in my model: baker.getTextureSetCount() retrns 0. Model is ok and have materials properly set: if I select baker in scene tree view by hand it refreshes its data and now it is ready to bake.
That's pretty annoying because I bake tens of similar objects in a batch, so I don't want to do it by hand each time.
How can I make marmoset to select my baker in list? I can't access its GUI, only to created by script.
Or maybe there is a way to make my baker update texture set list in python?
Thanks!

Just in case here's my code. Of course forum will kill all the identation but you'll got the idea. I set environment vars before launch it.

----------------------------------------------

import mset
import sys
import os

baker = None

tgt = os.getenv('MyMarmVarTgt')
lopath = os.getenv('MyMarmVarLo')
hipath = os.getenv('MyMarmVarHi')
res = os.getenv('MyMarmVarRes')
onlyVertexColor = os.getenv('MyMarmVarVc')
template_scene = os.getenv('MyMarmVarTemplate')

print(tgt)
print(lopath)
print(hipath)
print(template_scene)

mset.loadScene(template_scene)

try:
objlo = mset.importModel(lopath)
objhi = mset.importModel(hipath)
except Exception:
mset.quit()

# Find a baker:
for obj in mset.getAllObjects():
if isinstance(obj, mset.BakerObject):
baker = obj

try:
if baker != None:
# Setting up the baker
baker.outputPath = tgt
baker.outputBits = 8
baker.outputSamples = 16
baker.edgePadding = "Custom"
baker.edgePaddingSize = 16
baker.outputSoften = 0
baker.useHiddenMeshes = True
baker.ignoreTransforms = False
baker.smoothCage = True
baker.ignoreBackfaces = True
baker.multipleTextureSets = True

# These settings only apply if texture sets aren't enabled:
res_int = 4096
if res != '':
res_int = int(res)
baker.outputWidth = res_int
baker.outputHeight = res_int

for i in range(0, baker.getTextureSetCount() - 1):
baker.setTextureSetEnabled(i, True)
baker.setTextureSetWidth(i, res_int)
baker.setTextureSetHeight(i, res_int)
#baker.loadPreset("All")
#print(type(objlo).__name__+"\n")

vc_enable = False
if onlyVertexColor == "true":
vc_enable = True


normalMap = baker.getMap("Normals")
normalMap.suffix = 'normal_base' #'normal-from-mesh'
normalMap.enabled = True

normalMap = baker.getMap("Vertex Color")
normalMap.suffix = 'id' # 'color-from-mesh'
normalMap.enabled = True

normalMap = baker.getMap("Curvature")
normalMap.suffix = 'curvature'
normalMap.enabled = not vc_enable


normalMap = baker.getMap("Normals (Object)")
normalMap.suffix = 'world_space_normals' # 'normal-world-space'
normalMap.enabled = not vc_enable


normalMap = baker.getMap("Position")
normalMap.suffix = 'position' #'position-from-mesh'
normalMap.enabled = not vc_enable

normalMap = baker.getMap("Ambient Occlusion")
normalMap.suffix = 'ambient_occlusion' #'ambient-occlusion-from-mesh'
normalMap.enabled = not vc_enable

#baker.savePreset("My Python Preset")

bg = baker.findInChildren('Bake Group')
bglo = bg.findInChildren('Low')
bghi = bg.findInChildren('High')
objlo.parent = bglo
objhi.parent = bghi

print("baking...\n")
mset.bakeAll(0)
#try:
# baker.bake()
#except Exception:
# print(Exception)
# mset.quit()


else:
print("Could not find baker!")

except Exception:
mset.quit()


#mset.quit()


Replies

Sign In or Register to comment.