示例#1
0
    def _launch_render(self, clip, range_in, range_out, clip_start_offset):
        self.create_data_dirs_if_needed()

        self.render_range_in = range_in
        self.render_range_out = range_out
        self.clip_start_offset = clip_start_offset

        blenderheadless.clear_flag_files(self.get_container_program_id())
        # We need data to be available for render process,
        # create video_render_data object with default values if not available.
        if self.container_data.render_data == None:
            self.container_data.render_data = toolsencoding.create_container_clip_default_render_data_object(
                current_sequence().profile)

        blenderheadless.set_render_data(self.get_container_program_id(),
                                        self.container_data.render_data)

        # Write current render target container clip for blenderrendersetup.py
        cont_info_id_path = userfolders.get_cache_dir(
        ) + "blender_render_container_id"
        with atomicfile.AtomicFileWriter(cont_info_id_path, "w") as afw:
            outfile = afw.get_file()
            outfile.write(str(self.get_container_program_id()))

        # Write current render set up exec lines for blenderrendersetup.py
        render_exec_lines = 'bpy.context.scene.render.filepath = "' + self.get_rendered_media_dir() + '/frame"' + NEWLINE \
        + 'bpy.context.scene.render.fps = 24' + NEWLINE \
        + 'bpy.context.scene.render.image_settings.file_format = "PNG"' + NEWLINE \
        + 'bpy.context.scene.render.image_settings.color_mode = "RGBA"' + NEWLINE \
        + 'bpy.context.scene.render.film_transparent = 1' + NEWLINE \
        + 'bpy.context.scene.render.resolution_x = '+ str(current_sequence().profile.width()) + NEWLINE \
        + 'bpy.context.scene.render.resolution_y = ' + str(current_sequence().profile.height()) + NEWLINE \
        + 'bpy.context.scene.render.resolution_percentage = 100' + NEWLINE \
        + 'bpy.context.scene.frame_start = ' + str(range_in) + NEWLINE \
        + 'bpy.context.scene.frame_end = ' + str(range_out)  + NEWLINE

        objects = self.blender_objects()
        for obj in objects:
            # objects are [name, type, editorlist], see  blenderprojectinit.py
            obj_name = obj[0]
            editor_lines = []
            for editor_data in obj[2]:
                # editor_data is [prop_path, label, tooltip, editor_type, value], see containerprogramedit.EditorManagerWindow.get_current_editor_data()
                prop_path = editor_data[0]
                value = editor_data[4]

                render_exec_lines += 'obj = bpy.data.objects["' + obj_name + '"]' + NEWLINE
                render_exec_lines += 'obj.' + prop_path + " = " + value + NEWLINE

        exec_lines_file_path = self.get_session_dir(
        ) + "/blender_render_exec_lines"
        with atomicfile.AtomicFileWriter(exec_lines_file_path, "w") as afw:
            outfile = afw.get_file()
            outfile.write(render_exec_lines)

        args = ("session_id:" + self.get_container_program_id(),
                "project_path:" + self.container_data.program, "range_in:" +
                str(range_in), "range_out:" + str(range_out), "profile_desc:" +
                PROJECT().profile.description().replace(" ", "_"))

        # Run with nice to lower priority if requested (currently hard coded to lower)
        nice_command = "nice -n " + str(
            10) + " " + respaths.LAUNCH_DIR + "flowbladeblenderheadless"
        for arg in args:
            nice_command += " "
            nice_command += arg

        subprocess.Popen([nice_command], shell=True)
示例#2
0
    def _launch_render(self, clip, range_in, range_out, clip_start_offset):
        self.create_data_dirs_if_needed()

        job_msg = self.get_job_queue_message()
        job_msg.text = _("Render Starting...")
        job_msg.status = jobs.RENDERING
        jobs.update_job_queue(job_msg)

        self.render_range_in = range_in
        self.render_range_out = range_out
        self.clip_start_offset = clip_start_offset

        blenderheadless.clear_flag_files(self.get_container_program_id())
        # We need data to be available for render process,
        # create video_render_data object with default values if not available.
        if self.container_data.render_data == None:
            self.container_data.render_data = toolsencoding.create_container_clip_default_render_data_object(
                current_sequence().profile)

        # Make sure preview render does not try to create video clip.
        render_data = copy.deepcopy(self.container_data.render_data)
        if self.render_type == PREVIEW_RENDER:
            render_data.do_video_render = False
            render_data.is_preview_render = True

        blenderheadless.set_render_data(self.get_container_program_id(),
                                        render_data)

        # Write current render target container clip for blenderrendersetup.py
        cont_info_id_path = userfolders.get_cache_dir(
        ) + "blender_render_container_id"
        with atomicfile.AtomicFileWriter(cont_info_id_path, "w") as afw:
            outfile = afw.get_file()
            outfile.write(str(self.get_container_program_id()))

        # Write current render set up exec lines for blenderrendersetup.py
        if self.render_type != PREVIEW_RENDER:
            file_path_str = 'bpy.context.scene.render.filepath = "' + self.get_rendered_media_dir(
            ) + '/frame"' + NEWLINE
        else:
            file_path_str = 'bpy.context.scene.render.filepath = "' + self.get_preview_media_dir(
            ) + '/frame"' + NEWLINE
            if not os.path.exists(self.get_preview_media_dir()):
                os.mkdir(self.get_preview_media_dir())

        render_exec_lines = file_path_str \
        + 'bpy.context.scene.render.fps = 24' + NEWLINE \
        + 'bpy.context.scene.render.image_settings.file_format = "PNG"' + NEWLINE \
        + 'bpy.context.scene.render.image_settings.color_mode = "RGBA"' + NEWLINE \
        + 'bpy.context.scene.render.film_transparent = 1' + NEWLINE \
        + 'bpy.context.scene.render.resolution_x = '+ str(current_sequence().profile.width()) + NEWLINE \
        + 'bpy.context.scene.render.resolution_y = ' + str(current_sequence().profile.height()) + NEWLINE \
        + 'bpy.context.scene.render.resolution_percentage = 100' + NEWLINE \
        + 'bpy.context.scene.frame_start = ' + str(range_in) + NEWLINE \
        + 'bpy.context.scene.frame_end = ' + str(range_out)  + NEWLINE

        render_exec_lines = self._write_exec_lines_for_obj_type(
            render_exec_lines, "objects")
        render_exec_lines = self._write_exec_lines_for_obj_type(
            render_exec_lines, "materials")
        render_exec_lines = self._write_exec_lines_for_obj_type(
            render_exec_lines, "curves")

        exec_lines_file_path = self.get_session_dir(
        ) + "/blender_render_exec_lines"
        with atomicfile.AtomicFileWriter(exec_lines_file_path, "w") as afw:
            outfile = afw.get_file()
            outfile.write(render_exec_lines)

        args = (
            "session_id:" + self.get_container_program_id(),
            "project_path:" + utils.escape_shell_path(
                self.container_data.program
            ),  #.replace(" ", "\ "),   # This is going through Popen shell=True and needs escaped spaces.
            "range_in:" + str(range_in),
            "range_out:" + str(range_out),
            "profile_desc:" +
            PROJECT().profile.description().replace(" ", "_"))

        # Run with nice to lower priority if requested (currently hard coded to lower)
        nice_command = "nice -n " + str(10) + " " + str(
            respaths.LAUNCH_DIR + "flowbladeblenderheadless").replace(
                " ", "\ ")
        for arg in args:
            nice_command += " "
            nice_command += arg

        subprocess.Popen([nice_command], shell=True)