Skip to content

Commit 32e53bf

Browse files
authored
Merge pull request #13 from ynput/bugfix/AY-4222_3dsMax-Multicam-uses-the-same-camera
Make sure multicamera render uses correct camera
2 parents 62f79ac + c16c538 commit 32e53bf

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

client/ayon_max/api/lib_renderproducts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def get_beauty(self, container):
4040
def get_multiple_beauty(self, outputs, cameras):
4141
beauty_output_frames = dict()
4242
for output, camera in zip(outputs, cameras):
43+
camera = camera.replace(":", "_")
4344
filename, ext = os.path.splitext(output)
4445
filename = filename.replace(".", "")
4546
ext = ext.replace(".", "")
@@ -59,6 +60,7 @@ def get_multiple_aovs(self, outputs, cameras):
5960
renderer = str(renderer_class).split(":")[0]
6061
aovs_frames = {}
6162
for output, camera in zip(outputs, cameras):
63+
camera = camera.replace(":", "_")
6264
filename, ext = os.path.splitext(output)
6365
filename = filename.replace(".", "")
6466
ext = ext.replace(".", "")

client/ayon_max/api/lib_rendersettings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def get_batch_render_elements(self, container,
181181
for i in range(render_elem_num):
182182
renderlayer_name = render_elem.GetRenderElement(i)
183183
target, renderpass = str(renderlayer_name).split(":")
184+
camera = camera.replace(":", "_")
184185
aov_name = f"{output}_{camera}_{renderpass}..{img_fmt}"
185186
render_element_list.append(aov_name)
186187
return render_element_list
@@ -222,6 +223,7 @@ def batch_render_layer(self, container,
222223
renderlayer = rt.batchRenderMgr.GetView(layer_no)
223224
# use camera name as renderlayer name
224225
renderlayer.name = cam
226+
cam = cam.replace(":", "_")
225227
renderlayer.outputFilename = f"{output}_{cam}..{img_fmt}"
226228
outputs.append(renderlayer.outputFilename)
227229
return outputs

client/ayon_max/plugins/publish/collect_render.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def process(self, instance):
6767
instance.data["files"] = list()
6868
instance.data["expectedFiles"].append(files_by_aov)
6969
instance.data["files"].append(files_by_aov)
70-
7170
img_format = RenderProducts().image_format()
7271
# OCIO config not support in
7372
# most of the 3dsmax renderers

client/ayon_max/plugins/publish/save_scenes_for_cameras.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pyblish.api
22
import os
33
import sys
4+
import platform
45
import tempfile
56

7+
68
from pymxs import runtime as rt
79
from ayon_core.lib import run_subprocess
810
from ayon_max.api.lib_rendersettings import RenderSettings
@@ -41,7 +43,8 @@ def process(self, instance):
4143
for camera in cameras:
4244
new_output = RenderSettings().get_batch_render_output(camera) # noqa
4345
new_output = new_output.replace("\\", "/")
44-
new_filename = f"{filename}_{camera}{ext}"
46+
camera_name = camera.replace(":", "_")
47+
new_filename = f"{filename}_{camera_name}{ext}"
4548
new_filepath = os.path.join(new_folder, new_filename)
4649
new_filepath = new_filepath.replace("\\", "/")
4750
camera_scene_files.append(new_filepath)
@@ -55,17 +58,22 @@ def process(self, instance):
5558
new_filepath = "{new_filepath}"
5659
new_output = "{new_output}"
5760
camera = "{camera}"
61+
camera_name = camera.replace(":", "_")
62+
target_camera_node = rt.getNodeByName(camera)
63+
rt.viewport.setCamera(target_camera_node)
5864
rt.rendOutputFilename = new_output
5965
directory = os.path.dirname(rt.rendOutputFilename)
6066
directory = os.path.join(directory, filename)
67+
if not os.path.exists(directory):
68+
os.mkdir(directory)
6169
render_elem = rt.maxOps.GetCurRenderElementMgr()
6270
render_elem_num = render_elem.NumRenderElements()
6371
if render_elem_num > 0:
6472
ext = "{ext}"
6573
for i in range(render_elem_num):
6674
renderlayer_name = render_elem.GetRenderElement(i)
6775
target, renderpass = str(renderlayer_name).split(":")
68-
aov_name = f"{{directory}}_{camera}_{{renderpass}}..{ext}"
76+
aov_name = f"{{directory}}_{{camera_name}}_{{renderpass}}..{ext}"
6977
render_elem.SetRenderElementFileName(i, aov_name)
7078
rt.saveMaxFile(new_filepath)
7179
""").format(filename=instance.name,
@@ -74,11 +82,10 @@ def process(self, instance):
7482
camera=camera,
7583
ext=fmt)
7684
scripts.append(script)
77-
7885
maxbatch_exe = os.path.join(
7986
os.path.dirname(sys.executable), "3dsmaxbatch")
8087
maxbatch_exe = maxbatch_exe.replace("\\", "/")
81-
if sys.platform == "windows":
88+
if platform.system().lower() == "windows":
8289
maxbatch_exe += ".exe"
8390
maxbatch_exe = os.path.normpath(maxbatch_exe)
8491
with tempfile.TemporaryDirectory() as tmp_dir_name:
@@ -90,16 +97,18 @@ def process(self, instance):
9097
for script in scripts:
9198
tmp.write(script + "\n")
9299

93-
try:
94-
current_filepath = current_filepath.replace("\\", "/")
95-
tmp_script_path = tmp_script_path.replace("\\", "/")
96-
run_subprocess([maxbatch_exe, tmp_script_path,
97-
"-sceneFile", current_filepath])
98-
except RuntimeError:
99-
self.log.debug("Checking the scene files existing")
100+
full_script = "\n".join(scripts)
101+
self.log.debug(f"Failed running script {tmp_script_path}:\n{full_script}")
102+
current_filepath = current_filepath.replace("\\", "/")
103+
tmp_script_path = tmp_script_path.replace("\\", "/")
104+
run_subprocess([maxbatch_exe, tmp_script_path,
105+
"-sceneFile", current_filepath],
106+
logger=self.log)
100107

101108
for camera_scene in camera_scene_files:
102109
if not os.path.exists(camera_scene):
110+
full_script = "\n".join(scripts)
111+
self.log.debug(f"Failed running script {tmp_script_path}:\n{full_script}")
103112
self.log.error("Camera scene files not existed yet!")
104113
raise RuntimeError("MaxBatch.exe doesn't run as expected")
105114
self.log.debug(f"Found Camera scene:{camera_scene}")

0 commit comments

Comments
 (0)