def current(rend_name=None, aScene=None): scMgr = cm.svc("SceneManager") scene = cm.scene(aScene) curr_rendid = scene.activeRendID if rend_name is None: # print current renderer if curr_rendid==0: cm.println("No current renderer") return rend = scMgr.getRenderer(curr_rendid) if rend is None: msg = "Invalid current renderer (ID="+str(curr_rendid)+")" cm.println(msg) return obj = rend.getClientObj() cm.println("Current renderer:") cm.println(" id="+str(curr_rendid)) cm.println(" name="+rend.name+" ("+rend.type_name+")") cm.println(" Object="+obj.name+" ("+ci.getClassName(obj)+")") return else: # set current renderer rend = scene.getRendByName(rend_name) if rend is None: cm.println("Error, renderer name="+rend_name+" is not found.") return; scene.activeRendID = rend.uid cm.println("Current renderer is changed to "+rend_name+" ("+rend.type_name+")") return
def guessFormatFromFname(aPathName, aFmt): sm = cuemol.svc("StreamManager") info = json.loads(sm.getInfoJSON2()) # print("", info) # Check compression fileext basenm, ext = os.path.splitext(aPathName) comp = "" filenm = aPathName if ext == ".gz": comp = "gz" filenm = basenm elif ext == ".xz": comp = "xz" filenm = basenm basenm = os.path.basename(filenm) # Search matching fext in info data for elem in info: if not aFmt == None: # Format name is specified if aFmt == elem["name"]: return (elem, basenm, comp) else: # Guess format from file name fext = elem["fext"] for aex in fext.split("; "): aster, ext = os.path.splitext(aex) if filenm.endswith(ext): print("fext=", ext, "") return (elem, basenm, comp) raise RuntimeError("cannot guess file format from pathname: " + aPathName)
def saveObject(aObj, aFileName, aFmtName, aOpts=None): obj = cuemol.obj(aObj) strMgr = cuemol.svc("StreamManager") writer = strMgr.createHandler(aFmtName, 1) writer.setPath(aFileName) writer.attach(obj) writer.write() writer.detach()
def loadScene(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cuemol.scene(aScene) strMgr = cuemol.svc("StreamManager") reader = strMgr.createHandler(aFmtName, 3) reader.setPath(aFileName) reader.attach(scene) reader.read() reader.detach() if not aName == None: scene.setName(aName) return scene
def loadObject(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cuemol.scene(aScene) strMgr = cuemol.svc("StreamManager") reader = strMgr.createHandler(aFmtName, 0) reader.setPath(aFileName) newobj = reader.createDefaultObj() reader.attach(newobj) reader.read() reader.detach() if not aName == None: newobj.name = aName scene.addObject(newobj) return newobj
def saveObject(aObj, aFileName, aFmtName, aOpts=None): obj = cuemol.obj(aObj) strMgr = cuemol.svc("StreamManager") writer = strMgr.createHandler(aFmtName, 1) if aOpts is not None: for k, v in aOpts.items(): print("writer set prop: k=", k, "v=", v) ci.setProp(writer, k, v) writer.setPath(aFileName) writer.attach(obj) writer.write() writer.detach()
def loadScene(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cuemol.scene(aScene) strMgr = cuemol.svc("StreamManager") reader = strMgr.createHandler(aFmtName, 3) if aOpts is not None: for k, v in aOpts.items(): print("scene reader set prop: k=", k, "v=", v) ci.setProp(reader, k, v) reader.setPath(aFileName) reader.attach(scene) reader.read() reader.detach() if not aName == None: scene.setName(aName) return scene
def loadObject(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cuemol.scene(aScene) strMgr = cuemol.svc("StreamManager") reader = strMgr.createHandler(aFmtName, 0) if aOpts is not None: for k, v in aOpts.items(): print("reader set prop: k=", k, "v=", v) ci.setProp(reader, k, v) reader.setPath(aFileName) newobj = reader.createDefaultObj() reader.attach(newobj) reader.read() reader.detach() if not aName == None: newobj.name = aName scene.addObject(newobj) return newobj
def launchCueMol(confpath): ci.initCueMol(confpath) evm = main.event.getEventManager() logMgr = cm.svc("MsgLog") accumMsg = logMgr.getAccumMsg() logMgr.removeAccumMsg() # evm = event.getEventManager() app = QApplication(sys.argv) main_window = main.MainWindow() QtMolWidget.setupTextRender() QtMolWidget.setupEventTimer() widget = main.ConsoleWidget() widget.show() #main_window.show() sys.exit(app.exec_())
def current(rend_name=None, aScene=None): scMgr = cm.svc("SceneManager") scene = cm.scene(aScene) curr_rendid = scene.activeRendID if rend_name is None: # print current renderer if curr_rendid == 0: cm.println("No current renderer") return rend = scMgr.getRenderer(curr_rendid) if rend is None: msg = "Invalid current renderer (ID=" + str(curr_rendid) + ")" cm.println(msg) return obj = rend.getClientObj() cm.println("Current renderer:") cm.println(" id=" + str(curr_rendid)) cm.println(" name=" + rend.name + " (" + rend.type_name + ")") cm.println(" Object=" + obj.name + " (" + ci.getClassName(obj) + ")") return else: # set current renderer rend = scene.getRendByName(rend_name) if rend is None: cm.println("Error, renderer name=" + rend_name + " is not found.") return scene.activeRendID = rend.uid cm.println("Current renderer is changed to " + rend_name + " (" + rend.type_name + ")") return
def render(scene, out_png_file, width=640, height=480, camera="__current", nthr=1): scene.loadViewFromCam(scene.activeViewID, camera) scene.saveViewToCam(scene.activeViewID, "__current") strMgr = cm.svc("StreamManager") exporter = strMgr.createHandler("pov", 2) if exporter is None: raise RuntimeError("cannot create exporter for pov") sc = cm.scene(scene) if sc is None: raise RuntimeError("Scene ({}) does not exist".format(str(scene))) # Make pov tmp file fd, pov_fname = tempfile.mkstemp(suffix=".pov") os.close(fd) print("pov_fname", pov_fname) # Make inc tmp file fd, inc_fname = tempfile.mkstemp(suffix=".inc") os.close(fd) print("inc_fname", inc_fname) exporter.useClipZ = True #this.mbClip; exporter.perspective = False #!this.bOrtho; exporter.usePostBlend = True exporter.showEdgeLines = True #this.mbShowEdgeLines; exporter.usePixImgs = True #this.mbUsePixImgs; exporter.makeRelIncPath = False exporter.camera = camera exporter.width = width exporter.height = height exporter.attach(sc) exporter.setPath(pov_fname) exporter.setSubPath("inc", inc_fname) exporter.write() exporter.detach() if exporter.blendTable: print("BlendTab JSON:", exporter.blendTable) blend_tab = json.loads(exporter.blendTable) if exporter.imgFileNames: print("Img pix fnames:", exporter.imgFileNames) povfile_dir = Path(pov_fname).parent args = [POVRAY_BIN, "Input_File_Name='{}'".format(pov_fname), "Output_File_Name='{}'".format(out_png_file), "Library_Path='{}'".format(POVRAY_INC), "Library_Path='{}'".format(povfile_dir), "Declare=_stereo={}".format(0), "Declare=_iod={}".format(0), "Declare=_perspective={}".format(0), "Declare=_shadow={}".format(0), "Declare=_light_inten={}".format(1.3), "Declare=_flash_frac={}".format(0.8/1.3), "Declare=_amb_frac={}".format(0), "File_Gamma=1", "-D", "+WT{}".format(nthr), "+W{}".format(width), "+H{}".format(height), "+FN8", "Quality=11", "Antialias=On", "Antialias_Depth=3", "Antialias_Threshold=0.1", "Jitter=Off"] cmd = ' '.join(map(lambda x: shlex.quote(str(x)), args)) + " 2>&1" print(cmd, flush=True) res = subprocess.call(cmd, shell=True) if res != 0 or not Path(out_png_file).is_file(): raise RuntimeError("render failed: "+pov_fname) os.remove(pov_fname) os.remove(inc_fname)
def render(scene, out_png_file, width=640, height=480, camera="__current"): scene.loadViewFromCam(scene.activeViewID, camera) scene.saveViewToCam(scene.activeViewID, "__current") strMgr = cm.svc("StreamManager") exporter = strMgr.createHandler("pov", 2) if exporter is None: raise RuntimeError("cannot create exporter for pov") sc = cm.scene(scene) if sc is None: raise RuntimeError("Scene ({}) does not exist".format(str(scene))) # Make pov tmp file fd, pov_fname = tempfile.mkstemp(suffix=".pov") os.close(fd) print("pov_fname", pov_fname) # Make inc tmp file fd, inc_fname = tempfile.mkstemp(suffix=".inc") os.close(fd) print("inc_fname", inc_fname) exporter.useClipZ = True #this.mbClip; exporter.perspective = False #!this.bOrtho; exporter.usePostBlend = True exporter.showEdgeLines = True #this.mbShowEdgeLines; exporter.usePixImgs = True #this.mbUsePixImgs; exporter.makeRelIncPath = False exporter.camera = camera exporter.width = width exporter.height = height exporter.attach(sc) exporter.setPath(pov_fname) exporter.setSubPath("inc", inc_fname) exporter.write() exporter.detach() if exporter.blendTable: print("BlendTab JSON:", exporter.blendTable) blend_tab = json.loads(exporter.blendTable) if exporter.imgFileNames: print("Img pix fnames:", exporter.imgFileNames) povfile_dir = Path(pov_fname).parent args = [POVRAY_BIN, "Input_File_Name='{}'".format(pov_fname), "Output_File_Name='{}'".format(out_png_file), "Library_Path='{}'".format(POVRAY_INC), "Library_Path='{}'".format(povfile_dir), "Declare=_stereo={}".format(0), "Declare=_iod={}".format(0), "Declare=_perspective={}".format(0), "Declare=_shadow={}".format(0), "Declare=_light_inten={}".format(1.3), "Declare=_flash_frac={}".format(0.8/1.3), "Declare=_amb_frac={}".format(0), "File_Gamma=1", "-D", "+WT{}".format(1), "+W{}".format(width), "+H{}".format(height), "+FN8", "Quality=11", "Antialias=On", "Antialias_Depth=3", "Antialias_Threshold=0.1", "Jitter=Off"] cmd = ' '.join(map(lambda x: shlex.quote(str(x)), args)) + " 2>&1" print(cmd, flush=True) res = subprocess.call(cmd, shell=True) if res != 0 or not Path(out_png_file).is_file(): raise RuntimeError("render failed: "+pov_fname) os.remove(pov_fname) os.remove(inc_fname)