# -*- coding: utf-8 -*- # AUTHOR Luxion # VERSION 0.1.9 # Add frames of a Alembic/Maya file to render queue. import os, re def cleanExt(ext): while ext.startswith("."): ext = ext[1:] return ext def checkDialogOptions(opts): if len(opts["ifold"]) == 0: raise Exception("Input folder cannot be empty! Please specify a folder.") if opts["start"] > opts["end"]: raise Exception("Start frame cannot be larger than end frame!") if len(opts["ofold"]) == 0: raise Exception("Output folder cannot be empty! Please specify a folder.") if opts["samples"] == 0: raise Exception("Invalid render option!") if len(opts["iext"]) == 0: raise Exception("Input extension cannot be empty!") def getUpdateGeometryImportOptions(): io = lux.getImportOptions() io['adjust_camera_look_at'] = False io['adjust_environment'] = False io['update_mode'] = True io['merge'] = True io['new_import'] = False io['camera_import'] = True return io def updategeometry(fld, iext, io): for f in [f for f in os.listdir(fld) if f.endswith(iext)]: path = fld + os.path.sep + f if(len(path) != 0): print("Importing {}".format(path)) if not lux.importFile(path, False, True, io): raise Exception("Error in import! User cancelled?") def setRenderOptions(renderType, samples, alpha, clown, depth, normal, layers): ro = lux.getRenderOptions() ro.setAddToQueue(True) if renderType[1] == "Max Samples": ro.setMaxSamplesRendering(samples) if renderType[1] == "Max Time": ro.setMaxTimeRendering(samples) ro.setOutputAlphaChannel(alpha) ro.setOutputClownPass(clown) ro.setOutputDepthPass(depth) ro.setOutputNormalsPass(normal) ro.setOutputRenderLayers(layers) return ro def main(): nfo = lux.getSceneInfo() scenen = nfo.get('name') fmtcombo = ["jpeg", "png", "tiff", "exr"] iextcombo = ["abc", "mb"] renderCombo = ["Max Time", "Max Samples"] values = [(lux.DIALOG_LABEL, "Input Alembic or Maya files:"), ("ifold", lux.DIALOG_FOLDER, "Folder to import from:", None), ("iext", lux.DIALOG_ITEM, "Input file format to read:", "abc", iextcombo), (lux.DIALOG_LABEL, "--"), ("start", lux.DIALOG_INTEGER, "Start frame:", 0, (0, 10000)), ("end", lux.DIALOG_INTEGER, "End frame:", 10, (0, 10000)), ("kframes", lux.DIALOG_CHECK, "Increase KeyShot Animation frames", False), (lux.DIALOG_LABEL, "--"), ("oext", lux.DIALOG_ITEM, "Output image format:", "png", fmtcombo), ("ofold", lux.DIALOG_FOLDER, "Output folder:", None), ("width", lux.DIALOG_INTEGER, "Render width:", 500, (1, 10000)), ("height", lux.DIALOG_INTEGER, "Render height:", 500, (1, 10000)), ("cam", lux.DIALOG_TEXT, "Use camera. Leave blank for current:", lux.getCamera()), ("render_type", lux.DIALOG_ITEM, "Render Type:", renderCombo[0], renderCombo), ("samples", lux.DIALOG_INTEGER, "Samples / Seconds", 32, (0, 10000)), (lux.DIALOG_LABEL, "--"), (lux.DIALOG_LABEL, "Options:"), ("alpha", lux.DIALOG_CHECK, "Output images with alpha channel", False), ("clown", lux.DIALOG_CHECK, "Output clown pass", False), ("depth", lux.DIALOG_CHECK, "Output depth pass", False), ("normal", lux.DIALOG_CHECK, "Output normal pass", False), ("layers", lux.DIALOG_CHECK, "Output render layers", False), ("process", lux.DIALOG_CHECK, "Process queue after running script", False)] print(values) opts = lux.getInputDialog(title = "Add deformable mesh frames to queue", desc = "", values = values, id = "add_deform_mesh_frames.py.luxion") if not opts: return checkDialogOptions(opts) fld = opts["ifold"] iext = opts["iext"][1] reFiles = re.compile(".*{}".format(iext)) found = False for f in os.listdir(fld): if reFiles.match(f): found = True break if not found: raise Exception("Could not find any input files matching the extension \"{}\" in \"{}\"!" .format(iext, fld)) oext = opts["oext"][1] ofold = opts["ofold"] start = opts["start"] end = opts["end"] width = opts["width"] height = opts["height"] cam = opts["cam"] increaseFrames = opts["kframes"] renderType = opts["render_type"] samples = opts["samples"] alpha = opts["alpha"] clown = opts["clown"] depth = opts["depth"] normal = opts["normal"] layers = opts["layers"] process = opts["process"] io = getUpdateGeometryImportOptions() ro = setRenderOptions(renderType, samples, alpha, clown, depth, normal, layers) for i in range (start, end+1): io['frame'] = i updategeometry(fld, iext, io) if len(cam) != 0: lux.setCamera(cam) if increaseFrames: lux.setAnimationFrame(i) path = ofold + os.path.sep + scenen path = os.path.splitext(path)[0] + "." + str(i).zfill(5) + "." + str(oext) print("Rendering {}".format(path)) if not lux.renderImage(path, width, height, ro): raise Exception("Error in render! User cancelled?") if process: print("Processing queue") lux.processQueue() main()