Skip to content

Instantly share code, notes, and snippets.

@alaingalvan
Last active July 9, 2023 08:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaingalvan/4bd4b8b94737c655a16cb58188410f76 to your computer and use it in GitHub Desktop.
Save alaingalvan/4bd4b8b94737c655a16cb58188410f76 to your computer and use it in GitHub Desktop.
A Marmoset Toolbag 3 plugin for rendering batches of scene data automatically.
"""
Batch Rendering
To render a set of scenes individually, you could create a scene with the lights/camera set up
how you would like, then run this plugin after configuring a list of files you want to render.
"""
import mset
import os.path
# List of scenes to load and render
sceneList = [
""
]
# Renders all scenes in the scene list
def batchRender(renderVideo=False):
for index, sceneFile in enumerate(sceneList):
if(not os.path.isfile(sceneFile)):
print("Scene " + sceneFile + " does not exist! Continuing...")
continue
try:
mset.loadScene(sceneFile)
if renderVideo:
videoOut = os.path.abspath(os.path.join(
mset.getScenePath(), "..", 'video'+str(index)+".avi"))
mset.exportVideo(path=videoOut)
else:
mset.exportScreenshot()
except FileNotFoundError:
print("The file is not a scene file!")
# UI Functionality
window = mset.UIWindow("Batch Renderer")
window.visible = True
def addScene():
path = mset.showOpenFileDialog()
if path != '':
sceneList.append(path)
renderUI()
def editScene(field, index):
path = mset.showOpenFileDialog()
if path != '':
field.value = path
sceneList[index] = path
def renderUI():
window.clearElements()
add_button = mset.UIButton("Add Scene")
add_button.onClick = addScene
window.addElement(add_button)
window.addReturn()
for index, scene in enumerate(sceneList):
field = mset.UITextField()
field.value = scene
window.addElement(field)
file_button = mset.UIButton("...")
file_button.onClick = lambda f=field, i=index: editScene(f, i)
window.addElement(file_button)
window.addReturn()
window.addReturn()
render_button = mset.UIButton("Render Image")
render_button.onClick = lambda: batchRender(False)
window.addElement(render_button)
video_button = mset.UIButton("Render Animation")
video_button.onClick = lambda: batchRender(True)
window.addElement(video_button)
close_button = mset.UIButton("Close")
close_button.onClick = lambda: mset.shutdownPlugin()
window.addElement(close_button)
renderUI()
@Jeranand
Copy link

Jeranand commented May 5, 2021

Can this work for Marmoset Toolbag 3? I'm trying to render a few animated scenes overnight. I tried using this script but all that's coming out are a PNG sequence that is just the first frame all the way.

@alaingalvan
Copy link
Author

Hi @Jeranand, I'm having trouble reproducing this issue on my end, I was able to change line 26 to .png and it exported the sequence correctly.

Could you provide an example of what you're seeing?

@pfinnn
Copy link

pfinnn commented Jan 24, 2022

Hey Alain, does this work with marmoset 4 aswell?

@31onMusk
Copy link

31onMusk commented Dec 13, 2022

I have over 3000 Scenes, and I want to start render in the night, and it will render Scenes in queue. Is it possible? I use Marmoset Toolbag 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment