render methods do not rename output filenames

This commit is contained in:
iLLiCiTiT 2021-04-29 12:29:53 +02:00
parent 8ed7ae029d
commit c19dc55431

View file

@ -69,22 +69,19 @@ class ExtractSequence(pyblish.api.Extractor):
) )
if instance.data["family"] == "review": if instance.data["family"] == "review":
repre_files, thumbnail_fullpath = self.render_review( output_filenames, thumbnail_fullpath = self.render_review(
filename_template, output_dir, filename_template, output_dir, mark_in, mark_out
mark_in, mark_out,
frame_start, frame_end
) )
else: else:
# Render output # Render output
repre_files, thumbnail_fullpath = self.render( output_filenames, thumbnail_fullpath = self.render(
filename_template, output_dir, filename_template, output_dir,
mark_in, mark_out, mark_in, mark_out,
frame_start, frame_end,
filtered_layers filtered_layers
) )
# Sequence of one frame # Sequence of one frame
if not repre_files: if not output_filenames:
self.log.warning("Extractor did not create any output.") self.log.warning("Extractor did not create any output.")
return return
@ -150,10 +147,7 @@ class ExtractSequence(pyblish.api.Extractor):
return "{{frame:0>{}}}".format(frame_padding) + ".png" return "{{frame:0>{}}}".format(frame_padding) + ".png"
def render_review( def render_review(self, filename_template, output_dir, mark_in, mark_out):
self, filename_template, output_dir, mark_in, mark_out,
frame_start, frame_end
):
""" Export images from TVPaint using `tv_savesequence` command. """ Export images from TVPaint using `tv_savesequence` command.
Args: Args:
@ -162,8 +156,8 @@ class ExtractSequence(pyblish.api.Extractor):
keyword argument `{frame}` or index argument (for same value). keyword argument `{frame}` or index argument (for same value).
Extension in template must match `save_mode`. Extension in template must match `save_mode`.
output_dir (str): Directory where files will be stored. output_dir (str): Directory where files will be stored.
first_frame (int): Starting frame from which export will begin. mark_in (int): Starting frame index from which export will begin.
last_frame (int): On which frame export will end. mark_out (int): On which frame index export will end.
Retruns: Retruns:
tuple: With 2 items first is list of filenames second is path to tuple: With 2 items first is list of filenames second is path to
@ -186,28 +180,22 @@ class ExtractSequence(pyblish.api.Extractor):
] ]
lib.execute_george_through_file("\n".join(george_script_lines)) lib.execute_george_through_file("\n".join(george_script_lines))
reversed_repre_filepaths = []
marks_range = range(mark_out, mark_in - 1, -1)
frames_range = range(frame_end, frame_start - 1, -1)
for mark, frame in zip(marks_range, frames_range):
new_filename = filename_template.format(frame=frame)
new_filepath = os.path.join(output_dir, new_filename)
reversed_repre_filepaths.append(new_filepath)
if mark != frame:
old_filename = filename_template.format(frame=mark)
old_filepath = os.path.join(output_dir, old_filename)
os.rename(old_filepath, new_filepath)
repre_filepaths = list(reversed(reversed_repre_filepaths))
repre_files = [
os.path.basename(path)
for path in repre_filepaths
]
first_frame_filepath = None first_frame_filepath = None
if repre_filepaths: output_filenames = []
first_frame_filepath = repre_filepaths[0] for frame in range(mark_in, mark_out + 1):
filename = filename_template.format(frame=frame)
output_filenames.append(filename)
filepath = os.path.join(output_dir, filename)
if not os.path.exists(filepath):
raise AssertionError(
"Output was not rendered. File was not found {}".format(
filepath
)
)
if first_frame_filepath is None:
first_frame_filepath = filepath
thumbnail_filepath = os.path.join(output_dir, "thumbnail.jpg") thumbnail_filepath = os.path.join(output_dir, "thumbnail.jpg")
if first_frame_filepath and os.path.exists(first_frame_filepath): if first_frame_filepath and os.path.exists(first_frame_filepath):
@ -215,12 +203,10 @@ class ExtractSequence(pyblish.api.Extractor):
thumbnail_obj = Image.new("RGB", source_img.size, (255, 255, 255)) thumbnail_obj = Image.new("RGB", source_img.size, (255, 255, 255))
thumbnail_obj.paste(source_img) thumbnail_obj.paste(source_img)
thumbnail_obj.save(thumbnail_filepath) thumbnail_obj.save(thumbnail_filepath)
return repre_files, thumbnail_filepath
def render( return output_filenames, thumbnail_filepath
self, filename_template, output_dir, mark_in, mark_out,
frame_start, frame_end, layers def render(self, filename_template, output_dir, mark_in, mark_out, layers):
):
""" Export images from TVPaint. """ Export images from TVPaint.
Args: Args:
@ -229,8 +215,8 @@ class ExtractSequence(pyblish.api.Extractor):
keyword argument `{frame}` or index argument (for same value). keyword argument `{frame}` or index argument (for same value).
Extension in template must match `save_mode`. Extension in template must match `save_mode`.
output_dir (str): Directory where files will be stored. output_dir (str): Directory where files will be stored.
first_frame (int): Starting frame from which export will begin. mark_in (int): Starting frame index from which export will begin.
last_frame (int): On which frame export will end. mark_out (int): On which frame index export will end.
layers (list): List of layers to be exported. layers (list): List of layers to be exported.
Retruns: Retruns:
@ -290,7 +276,7 @@ class ExtractSequence(pyblish.api.Extractor):
) )
return [], None return [], None
output_filepaths_by_frame = self._composite_files( output_filepaths = self._composite_files(
files_by_position, files_by_position,
mark_in, mark_in,
mark_out, mark_out,
@ -299,27 +285,14 @@ class ExtractSequence(pyblish.api.Extractor):
) )
self._cleanup_tmp_files(files_by_position) self._cleanup_tmp_files(files_by_position)
reversed_repre_filepaths = [] output_filenames = [
marks_range = range(mark_out, mark_in - 1, -1) os.path.basename(filepath)
frames_range = range(frame_end, frame_start - 1, -1) for filepath in output_filepaths
for mark, frame in zip(marks_range, frames_range):
new_filename = filename_template.format(frame=frame)
new_filepath = os.path.join(output_dir, new_filename)
reversed_repre_filepaths.append(new_filepath)
if mark != frame:
old_filepath = output_filepaths_by_frame[mark]
os.rename(old_filepath, new_filepath)
repre_filepaths = list(reversed(reversed_repre_filepaths))
repre_files = [
os.path.basename(path)
for path in repre_filepaths
] ]
thumbnail_src_filepath = None thumbnail_src_filepath = None
if repre_filepaths: if output_filepaths:
thumbnail_src_filepath = repre_filepaths[0] thumbnail_src_filepath = output_filepaths[0]
thumbnail_filepath = None thumbnail_filepath = None
if thumbnail_src_filepath and os.path.exists(thumbnail_src_filepath): if thumbnail_src_filepath and os.path.exists(thumbnail_src_filepath):
@ -329,7 +302,7 @@ class ExtractSequence(pyblish.api.Extractor):
thumbnail_obj.paste(source_img) thumbnail_obj.paste(source_img)
thumbnail_obj.save(thumbnail_filepath) thumbnail_obj.save(thumbnail_filepath)
return repre_files, thumbnail_filepath return output_filenames, thumbnail_filepath
def _render_layer( def _render_layer(
self, self,
@ -604,14 +577,14 @@ class ExtractSequence(pyblish.api.Extractor):
filepath = position_data[frame_idx] filepath = position_data[frame_idx]
images_by_frame[frame_idx].append(filepath) images_by_frame[frame_idx].append(filepath)
output_filepaths_by_frame = {} output_filepaths = []
missing_frame_paths = [] missing_frame_paths = []
random_frame_path = None random_frame_path = None
for frame_idx in sorted(images_by_frame.keys()): for frame_idx in sorted(images_by_frame.keys()):
image_filepaths = images_by_frame[frame_idx] image_filepaths = images_by_frame[frame_idx]
output_filename = filename_template.format(frame=frame_idx + 1) output_filename = filename_template.format(frame=frame_idx)
output_filepath = os.path.join(output_dir, output_filename) output_filepath = os.path.join(output_dir, output_filename)
output_filepaths_by_frame[frame_idx] = output_filepath output_filepaths.append(output_filepath)
# Store information about missing frame and skip # Store information about missing frame and skip
if not image_filepaths: if not image_filepaths:
@ -647,7 +620,7 @@ class ExtractSequence(pyblish.api.Extractor):
transparent_filepath = filepath transparent_filepath = filepath
else: else:
self._copy_image(transparent_filepath, filepath) self._copy_image(transparent_filepath, filepath)
return output_filepaths_by_frame return output_filepaths
def _cleanup_tmp_files(self, files_by_position): def _cleanup_tmp_files(self, files_by_position):
"""Remove temporary files that were used for compositing.""" """Remove temporary files that were used for compositing."""