Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static image rend #262

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 89 additions & 89 deletions pymod/python/cuemol/povrender.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _run_povray(self, aPovFileName, aOutImgPath, aOptArgs):
args.append(f"Declare=_radiosity={self.mnRadMode}")

if not self.use_fog:
args.append("Declare=_no_fog=1");
args.append("Declare=_no_fog=1")

if aOptArgs:
args = args + aOptArgs
Expand All @@ -130,7 +130,9 @@ def _run_povray(self, aPovFileName, aOutImgPath, aOptArgs):
# subprocess.call(args)
os.system(" ".join(args))

def _writePovFiles(self, pov_base: str, scene: Any, animMgr: Any) -> list[Any]:
def _writePovFiles(
self, pov_base: str, scene: Any, animMgr: Optional[Any] = None
) -> list[Any]:

# create exporter obj
strMgr = cm.svc("StreamManager")
Expand Down Expand Up @@ -161,7 +163,7 @@ def _writePovFiles(self, pov_base: str, scene: Any, animMgr: Any) -> list[Any]:
exporter.setPath(povFileName)
exporter.setSubPath("inc", incFileName)

if animMgr:
if animMgr is not None:
animMgr.writeFrame(exporter)
else:
exporter.attach(scene)
Expand Down Expand Up @@ -260,112 +262,110 @@ def render_anim(self, scene: Any, basename: str, startfrm: int, nfrms: int) -> N
animMgr = scene.getAnimMgr()

if animMgr.size <= 0:
print("No animation in scene: {scene.name}")
print(f"No animation in scene: {scene.name}")
return

animMgr.startcam = self.camera
tv_st = cm.timeval(itv)
tv_en = animMgr.length

if tv_st.millisec > tv_en.millisec:
print("start frame out of range: {startfrm}")
print(f"start frame out of range: {startfrm}")
return

nallfrms = animMgr.setupRender(tv_st, tv_en, self.mFPS)
print(f"Render anim frames: {nallfrms}")
if nfrms < 0:
nfrms = nallfrms

for ifrm in range(startfrm, startfrm + nfrms):
outbase = f"{basename}-{ifrm:04d}" # sys.argv[2] + "-" + ("%04d" % ifrm)
blendtab = self._writePovFiles(outbase, scene, animMgr)
self._render_blend_pov(outbase, blendtab)

def render_simple(
self, scene, out_png_file, width=640, height=480, camera="__current", nthr=1
):
scene.loadViewFromCam(scene.activeViewID, camera)
scene.saveViewToCam(scene.activeViewID, "__current")
def render_simple(self, scene: Any, basename: str) -> None:
# 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 = self.perspective
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)
print(blend_tab)

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)
blendtab = self._writePovFiles(basename, scene)
self._render_blend_pov(basename, blendtab)

# # 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 = self.perspective
# 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)
# print(blend_tab)

# 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)
Loading