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 load(filename, name=None, format=None, scene=None): scMgr = cm.sceMgr() scene = cm.scene(scene) gformat, gname, comp = guessFormatFromFname(filename, format) print("guessed format: ", gformat) print("guessed objname: ", gname) print("guessed comp mode: ", comp) if format is None: format = gformat['name'] if name is None: name = gname ncat = getReaderCategoryID(format) if ncat == 0: obj = loadObject(filename, name, scene, format) renderer.setupDefaultRenderer(obj) return obj elif ncat == 3: return loadScene(filename, name, scene, format) else: # Unknown category ID, throw exception here raise RuntimeError("Unknown category ID:"+str(ncat))
def bg_color(colstr, aScene=None): scene = cm.scene(aScene) col = cm.col(colstr) if col is None: # TO DO: report error return with cm.UndoTxn("Change background color", scene): scene.bgcolor = col
def __init__(self, aMsg=None, aScene=None): # print('__init__') if aScene == None: self.scene = cuemol.scene() else: self.scene = aScene if aMsg == None: self.msg = "" else: self.msg = aMsg
def fetch(pdbid, scene=None): sc = cm.scene(scene) url_tmpl = "http://files.rcsb.org/download/{}.cif.gz" obj = load_url(url_tmpl.format(pdbid.lower())) obj.name = pdbid sc.addObject(obj) print("obj.scene:", obj.getScene()) renderer.setupDefaultRenderer(obj) return obj
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 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 loadScene(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cm.scene(aScene) strMgr = cm.strMgr() 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._wrapped, k, v) reader.setPath(aFileName) reader.attach(scene) reader.read() reader.detach() if aName is not 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 loadObject(aFileName, aName, aScene, aFmtName, aOpts=None): scene = cm.scene(aScene) strMgr = cm.strMgr() reader = strMgr.createHandler(aFmtName, 0) if aOpts is not None: for k,v in aOpts.items(): print("reader:",reader._wrapped) print("reader set prop: k=",k,"v=",v) ci.setProp(reader._wrapped, k, v) print(ci.getProp(reader._wrapped, k)) reader.setPath(aFileName) newobj = reader.createDefaultObj() reader.attach(newobj) reader.read(); reader.detach(); if aName is not None: newobj.name = aName scene.addObject(newobj) return newobj
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 bgcolor(aCol): sc = cuemol.scene() col = aCol if isinstance(aCol, str): col = cuemol.col(aCol, sc.uid) sc.bgcolor = col
def redo(aScene=None): scene = cm.scene(aScene) scene.redo(0)
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)
def del_scene(scene): if scene is None: raise RuntimeError("scene is None") s = cm.scene(scene) mgr = cm.sceMgr() mgr.destroyScene(s.uid)
def undo(aScene=None): scene = cm.scene(aScene) scene.undo(0)
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)