2017-01-13 17:24:37 +01:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
"""Flamenco interface.
|
|
|
|
|
|
|
|
The preferences are managed blender.py, the rest of the Flamenco-specific stuff is here.
|
|
|
|
"""
|
2017-07-03 08:41:26 +02:00
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
import functools
|
2017-01-13 17:24:37 +01:00
|
|
|
import logging
|
2017-07-03 08:41:26 +02:00
|
|
|
import os
|
2017-01-18 14:31:25 +01:00
|
|
|
from pathlib import Path, PurePath
|
2017-01-17 16:03:46 +01:00
|
|
|
import typing
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-06-22 14:43:37 +02:00
|
|
|
if "bpy" in locals():
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
try:
|
2018-03-15 12:36:05 +01:00
|
|
|
bat_interface = importlib.reload(bat_interface)
|
2017-06-22 14:43:37 +02:00
|
|
|
sdk = importlib.reload(sdk)
|
2018-09-04 13:47:44 +02:00
|
|
|
blender = importlib.reload(blender)
|
2017-06-22 14:43:37 +02:00
|
|
|
except NameError:
|
2018-03-15 12:36:05 +01:00
|
|
|
from . import bat_interface, sdk
|
2021-02-16 11:33:48 +01:00
|
|
|
from .. import blender
|
2017-06-22 14:43:37 +02:00
|
|
|
else:
|
2018-03-15 12:36:05 +01:00
|
|
|
from . import bat_interface, sdk
|
2021-02-16 11:33:48 +01:00
|
|
|
from .. import blender
|
2017-06-22 14:43:37 +02:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
import bpy
|
|
|
|
from bpy.types import AddonPreferences, Operator, WindowManager, Scene, PropertyGroup
|
2021-02-16 11:21:06 +01:00
|
|
|
from bpy.props import (
|
|
|
|
StringProperty,
|
|
|
|
EnumProperty,
|
|
|
|
PointerProperty,
|
|
|
|
BoolProperty,
|
|
|
|
IntProperty,
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2018-12-05 12:57:39 +01:00
|
|
|
from .. import async_loop, pillar, project_specific, utils
|
2017-01-13 17:24:37 +01:00
|
|
|
from ..utils import pyside_cache, redraw
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
# Global flag used to determine whether panels etc. can be drawn.
|
|
|
|
flamenco_is_active = False
|
|
|
|
|
2018-11-21 14:23:32 +01:00
|
|
|
# 'image' file formats that actually produce a video.
|
2021-02-16 11:21:06 +01:00
|
|
|
VIDEO_FILE_FORMATS = {"FFMPEG", "AVI_RAW", "AVI_JPEG"}
|
2018-11-21 14:23:32 +01:00
|
|
|
|
2018-12-06 15:47:13 +01:00
|
|
|
# Video container name (from bpy.context.scene.render.ffmpeg.format) to file
|
|
|
|
# extension mapping. Any container name not listed here will be converted to
|
|
|
|
# lower case and prepended with a period. This is basically copied from
|
|
|
|
# Blender's source, get_file_extensions() in writeffmpeg.c.
|
|
|
|
VIDEO_CONTAINER_TO_EXTENSION = {
|
2021-02-16 11:21:06 +01:00
|
|
|
"QUICKTIME": ".mov",
|
|
|
|
"MPEG1": ".mpg",
|
|
|
|
"MPEG2": ".dvd",
|
|
|
|
"MPEG4": ".mp4",
|
|
|
|
"OGG": ".ogv",
|
|
|
|
"FLASH": ".flv",
|
2018-12-06 15:47:13 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
SHAMAN_URL_SCHEMES = {"shaman://", "shaman+http://", "shaman+https://"}
|
2019-02-28 12:53:29 +01:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2019-01-30 16:01:02 +01:00
|
|
|
def scene_sample_count(scene) -> int:
|
|
|
|
"""Determine nr of render samples for this scene."""
|
2021-02-16 11:21:06 +01:00
|
|
|
if scene.cycles.progressive == "BRANCHED_PATH":
|
2019-01-30 16:01:02 +01:00
|
|
|
samples = scene.cycles.aa_samples
|
|
|
|
else:
|
|
|
|
samples = scene.cycles.samples
|
|
|
|
|
|
|
|
if scene.cycles.use_square_samples:
|
|
|
|
samples **= 2
|
|
|
|
|
|
|
|
return samples
|
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
@pyside_cache("manager")
|
2017-01-13 17:24:37 +01:00
|
|
|
def available_managers(self, context):
|
|
|
|
"""Returns the list of items used by a manager-selector EnumProperty."""
|
|
|
|
|
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
mngrs = preferences().flamenco_manager.available_managers
|
|
|
|
if not mngrs:
|
2021-02-16 11:21:06 +01:00
|
|
|
return [("", "No managers available in your Blender Cloud", "")]
|
|
|
|
return [(p["_id"], p["name"], "") for p in mngrs]
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
def manager_updated(self: "FlamencoManagerGroup", context):
|
2018-11-16 16:52:02 +01:00
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
flamenco_manager_id = self.manager
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("manager updated to %r", flamenco_manager_id)
|
2018-11-16 16:52:02 +01:00
|
|
|
|
|
|
|
prefs = preferences()
|
|
|
|
project_id = prefs.project.project
|
2021-02-16 11:21:06 +01:00
|
|
|
ps = prefs.get("project_settings", {}).get(project_id, {})
|
2018-11-16 16:52:02 +01:00
|
|
|
|
|
|
|
# Load per-project, per-manager settings for the current Manager.
|
|
|
|
try:
|
2021-02-16 11:21:06 +01:00
|
|
|
pppm = ps["flamenco_managers_settings"][flamenco_manager_id]
|
2018-11-16 16:52:02 +01:00
|
|
|
except KeyError:
|
|
|
|
# No settings for this manager, so nothing to do.
|
|
|
|
return
|
|
|
|
|
|
|
|
with project_specific.mark_as_loading():
|
2021-02-16 11:21:06 +01:00
|
|
|
project_specific.update_preferences(
|
|
|
|
prefs, project_specific.FLAMENCO_PER_PROJECT_PER_MANAGER, pppm
|
|
|
|
)
|
2018-11-16 16:52:02 +01:00
|
|
|
|
|
|
|
|
2019-01-31 14:42:50 +01:00
|
|
|
def silently_quit_blender():
|
|
|
|
"""Quit Blender without any confirmation popup."""
|
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
prefs = bpy.context.preferences
|
|
|
|
prefs.view.use_save_prompt = False
|
2021-02-16 11:34:35 +01:00
|
|
|
prefs.use_preferences_save = False
|
2019-01-31 14:42:50 +01:00
|
|
|
bpy.ops.wm.quit_blender()
|
|
|
|
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
class FlamencoManagerGroup(PropertyGroup):
|
2021-02-16 11:33:48 +01:00
|
|
|
manager: EnumProperty(
|
2017-01-13 17:24:37 +01:00
|
|
|
items=available_managers,
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Flamenco Manager",
|
|
|
|
description="Which Flamenco Manager to use for jobs",
|
2018-11-16 16:52:02 +01:00
|
|
|
update=manager_updated,
|
2018-01-02 16:42:37 +01:00
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
status: EnumProperty(
|
2017-01-13 17:24:37 +01:00
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("NONE", "NONE", "We have done nothing at all yet"),
|
|
|
|
(
|
|
|
|
"IDLE",
|
|
|
|
"IDLE",
|
|
|
|
"User requested something, which is done, and we are now idle",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"FETCHING",
|
|
|
|
"FETCHING",
|
|
|
|
"Fetching available Flamenco managers from Blender Cloud",
|
|
|
|
),
|
2017-01-13 17:24:37 +01:00
|
|
|
],
|
2021-02-16 11:21:06 +01:00
|
|
|
name="status",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
# List of managers is stored in 'available_managers' ID property,
|
|
|
|
# because I don't know how to store a variable list of strings in a proper RNA property.
|
|
|
|
@property
|
|
|
|
def available_managers(self) -> list:
|
2021-02-16 11:21:06 +01:00
|
|
|
return self.get("available_managers", [])
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
@available_managers.setter
|
|
|
|
def available_managers(self, new_managers):
|
2021-02-16 11:21:06 +01:00
|
|
|
self["available_managers"] = new_managers
|
2018-09-04 17:38:21 +02:00
|
|
|
project_specific.store()
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
class FlamencoPollMixin:
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return flamenco_is_active
|
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class FLAMENCO_OT_fmanagers(
|
|
|
|
async_loop.AsyncModalOperatorMixin,
|
|
|
|
pillar.AuthenticatedPillarOperatorMixin,
|
|
|
|
FlamencoPollMixin,
|
|
|
|
Operator,
|
|
|
|
):
|
2017-01-13 17:24:37 +01:00
|
|
|
"""Fetches the Flamenco Managers available to the user"""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "flamenco.managers"
|
|
|
|
bl_label = "Fetch available Flamenco Managers"
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
stop_upon_exception = True
|
2021-02-16 11:21:06 +01:00
|
|
|
log = logging.getLogger("%s.FLAMENCO_OT_fmanagers" % __name__)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def mypref(self) -> FlamencoManagerGroup:
|
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
return preferences().flamenco_manager
|
|
|
|
|
|
|
|
async def async_execute(self, context):
|
|
|
|
if not await self.authenticate(context):
|
|
|
|
return
|
|
|
|
|
|
|
|
from .sdk import Manager
|
|
|
|
from ..pillar import pillar_call
|
2018-07-24 15:44:12 +02:00
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
prefs = preferences()
|
2019-03-26 12:35:27 +01:00
|
|
|
mypref = self.mypref
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Going to fetch managers for user %s", self.user_id)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
mypref.status = "FETCHING"
|
|
|
|
params = {"where": '{"projects" : "%s"}' % prefs.project.project}
|
2018-07-24 15:44:12 +02:00
|
|
|
managers = await pillar_call(Manager.all, params)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
# We need to convert to regular dicts before storing in ID properties.
|
|
|
|
# Also don't store more properties than we need.
|
2021-02-16 11:21:06 +01:00
|
|
|
as_list = [
|
|
|
|
{"_id": man["_id"], "name": man["name"]} for man in managers["_items"]
|
|
|
|
]
|
2019-03-26 12:35:27 +01:00
|
|
|
|
|
|
|
current_manager = mypref.manager
|
|
|
|
mypref.available_managers = as_list
|
|
|
|
|
|
|
|
# Prevent warnings about the current manager not being in the EnumProperty items.
|
2021-02-16 11:21:06 +01:00
|
|
|
if as_list and not any(man["_id"] == current_manager for man in as_list):
|
|
|
|
mypref.manager = as_list[0]["_id"]
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
self.quit()
|
|
|
|
|
|
|
|
def quit(self):
|
2021-02-16 11:21:06 +01:00
|
|
|
self.mypref.status = "IDLE"
|
2017-01-13 17:24:37 +01:00
|
|
|
super().quit()
|
|
|
|
|
|
|
|
|
2018-12-06 15:47:13 +01:00
|
|
|
def guess_output_file_extension(output_format: str, scene) -> str:
|
|
|
|
"""Return extension, including period, like '.png' or '.mkv'."""
|
|
|
|
if output_format not in VIDEO_FILE_FORMATS:
|
|
|
|
return scene.render.file_extension
|
|
|
|
|
|
|
|
container = scene.render.ffmpeg.format
|
|
|
|
try:
|
|
|
|
return VIDEO_CONTAINER_TO_EXTENSION[container]
|
|
|
|
except KeyError:
|
2021-02-16 11:21:06 +01:00
|
|
|
return "." + container.lower()
|
2018-12-06 15:47:13 +01:00
|
|
|
|
|
|
|
|
2020-03-03 10:37:44 +01:00
|
|
|
def is_shaman_url(path_or_url: str) -> bool:
|
|
|
|
"""Check whether the given string is a Shaman URL.
|
|
|
|
|
|
|
|
:param path_or_url: A string that may represent a filesystem path or a URL.
|
|
|
|
May not be a pathlib.Path, as that would break URL notation on Windows.
|
|
|
|
"""
|
|
|
|
assert isinstance(path_or_url, str)
|
|
|
|
return any(path_or_url.startswith(scheme) for scheme in SHAMAN_URL_SCHEMES)
|
|
|
|
|
|
|
|
|
|
|
|
def is_file_inside_job_storage(prefs, current_file: typing.Union[str, Path]) -> bool:
|
2019-10-25 13:34:34 +02:00
|
|
|
"""Check whether current blend file is inside the storage path.
|
|
|
|
|
|
|
|
:return: True when 'current_file' is inside the Flamenco
|
|
|
|
job storage directory already. In this case it won't be
|
|
|
|
BAT-packed, as it's assumed the job storage dir is
|
|
|
|
accessible by the workers already.
|
|
|
|
"""
|
2020-03-03 10:37:44 +01:00
|
|
|
|
|
|
|
if isinstance(current_file, str):
|
|
|
|
# Shaman URLs are always remote, so the current file cannot be in there.
|
|
|
|
if is_shaman_url(current_file):
|
|
|
|
return False
|
|
|
|
current_file = Path(current_file)
|
|
|
|
|
2019-10-25 13:34:34 +02:00
|
|
|
flamenco_job_file_path = Path(prefs.flamenco_job_file_path).absolute().resolve()
|
|
|
|
current_file = current_file.absolute().resolve()
|
|
|
|
try:
|
|
|
|
current_file.relative_to(flamenco_job_file_path)
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class FLAMENCO_OT_render(
|
|
|
|
async_loop.AsyncModalOperatorMixin,
|
|
|
|
pillar.AuthenticatedPillarOperatorMixin,
|
|
|
|
FlamencoPollMixin,
|
|
|
|
Operator,
|
|
|
|
):
|
2017-01-13 17:24:37 +01:00
|
|
|
"""Performs a Blender render on Flamenco."""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "flamenco.render"
|
|
|
|
bl_label = "Render on Flamenco"
|
|
|
|
bl_description = __doc__.rstrip(".")
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
stop_upon_exception = True
|
2021-02-16 11:21:06 +01:00
|
|
|
log = logging.getLogger("%s.FLAMENCO_OT_render" % __name__)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
quit_after_submit: BoolProperty()
|
2019-01-31 14:42:50 +01:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
async def async_execute(self, context):
|
2017-07-03 08:41:26 +02:00
|
|
|
# Refuse to start if the file hasn't been saved. It's okay if
|
|
|
|
# it's dirty, but we do need a filename and a location.
|
|
|
|
if not os.path.exists(context.blend_data.filepath):
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report(
|
|
|
|
{"ERROR"},
|
|
|
|
"Please save your Blend file before using " "the Blender Cloud addon.",
|
|
|
|
)
|
2017-07-03 08:41:26 +02:00
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
if not await self.authenticate(context):
|
|
|
|
return
|
|
|
|
|
2017-06-09 10:52:56 +02:00
|
|
|
import pillarsdk.exceptions
|
|
|
|
from .sdk import Manager
|
|
|
|
from ..pillar import pillar_call
|
2017-01-17 16:03:46 +01:00
|
|
|
from ..blender import preferences
|
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
scene = context.scene
|
|
|
|
|
2017-02-14 10:21:50 +01:00
|
|
|
# Save to a different file, specifically for Flamenco.
|
2021-02-16 11:21:06 +01:00
|
|
|
context.window_manager.flamenco_status = "SAVING"
|
2017-02-14 10:21:50 +01:00
|
|
|
filepath = await self._save_blendfile(context)
|
2017-01-18 14:31:25 +01:00
|
|
|
|
|
|
|
# Determine where the render output will be stored.
|
2017-01-24 14:39:49 +01:00
|
|
|
render_output = render_output_path(context, filepath)
|
2017-01-18 14:31:25 +01:00
|
|
|
if render_output is None:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"ERROR"}, "Current file is outside of project path.")
|
2017-01-18 14:31:25 +01:00
|
|
|
self.quit()
|
|
|
|
return
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Will output render files to %s", render_output)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-06-09 10:52:56 +02:00
|
|
|
# Fetch Manager for doing path replacement.
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Going to fetch manager %s", self.user_id)
|
2017-01-13 17:24:37 +01:00
|
|
|
prefs = preferences()
|
2017-01-18 14:31:25 +01:00
|
|
|
|
2017-06-09 10:52:56 +02:00
|
|
|
manager_id = prefs.flamenco_manager.manager
|
|
|
|
try:
|
|
|
|
manager = await pillar_call(Manager.find, manager_id)
|
|
|
|
except pillarsdk.exceptions.ResourceNotFound:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report(
|
|
|
|
{"ERROR"},
|
|
|
|
"Manager %s not found, refresh your managers in "
|
|
|
|
"the Blender Cloud add-on settings." % manager_id,
|
|
|
|
)
|
2017-06-09 10:52:56 +02:00
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
|
2018-12-06 15:47:13 +01:00
|
|
|
# Construct as much of the job settings as we can before BAT-packing.
|
|
|
|
# Validation should happen as soon as possible (BAT-packing can take minutes).
|
2021-02-16 11:21:06 +01:00
|
|
|
frame_range = scene.flamenco_render_frame_range.strip() or scene_frame_range(
|
|
|
|
context
|
|
|
|
)
|
|
|
|
settings = {
|
|
|
|
"blender_cmd": "{blender}",
|
|
|
|
"chunk_size": scene.flamenco_render_fchunk_size,
|
|
|
|
"frames": frame_range,
|
|
|
|
"render_output": manager.replace_path(render_output),
|
|
|
|
# Used for FFmpeg combining output frames into a video.
|
|
|
|
"fps": scene.render.fps / scene.render.fps_base,
|
|
|
|
"extract_audio": scene.render.ffmpeg.audio_codec != "NONE",
|
|
|
|
}
|
2017-01-30 10:38:35 +01:00
|
|
|
|
|
|
|
# Add extra settings specific to the job type
|
2021-02-16 11:21:06 +01:00
|
|
|
if scene.flamenco_render_job_type == "blender-render-progressive":
|
2019-01-30 16:01:02 +01:00
|
|
|
samples = scene_sample_count(scene)
|
2021-02-16 11:21:06 +01:00
|
|
|
settings["cycles_sample_cap"] = scene.flamenco_render_chunk_sample_cap
|
|
|
|
settings["cycles_sample_count"] = samples
|
|
|
|
settings["format"] = "OPEN_EXR"
|
2017-01-30 10:38:35 +01:00
|
|
|
|
2018-11-21 14:23:32 +01:00
|
|
|
# Let Flamenco Server know whether we'll output images or video.
|
2021-02-16 11:21:06 +01:00
|
|
|
output_format = (
|
|
|
|
settings.get("format") or scene.render.image_settings.file_format
|
|
|
|
)
|
2018-11-21 14:23:32 +01:00
|
|
|
if output_format in VIDEO_FILE_FORMATS:
|
2021-02-16 11:21:06 +01:00
|
|
|
settings["images_or_video"] = "video"
|
2018-11-21 14:23:32 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
settings["images_or_video"] = "images"
|
2018-11-21 14:23:32 +01:00
|
|
|
|
|
|
|
# Always pass the file format, even though it won't be
|
|
|
|
# necessary for the actual render command (the blend file
|
|
|
|
# already has the correct setting). It's used by other
|
|
|
|
# commands, such as FFmpeg combining output frames into
|
|
|
|
# a video.
|
|
|
|
#
|
|
|
|
# Note that this might be overridden above when the job type
|
|
|
|
# requires a specific file format.
|
2021-02-16 11:21:06 +01:00
|
|
|
settings.setdefault("format", scene.render.image_settings.file_format)
|
|
|
|
settings["output_file_extension"] = guess_output_file_extension(
|
|
|
|
output_format, scene
|
|
|
|
)
|
2018-12-06 15:47:13 +01:00
|
|
|
|
|
|
|
if not self.validate_job_settings(context, settings):
|
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
|
|
|
|
# Create the job at Flamenco Server.
|
2021-02-16 11:21:06 +01:00
|
|
|
context.window_manager.flamenco_status = "COMMUNICATING"
|
2018-12-05 12:57:39 +01:00
|
|
|
project_id = prefs.project.project
|
2019-02-13 15:17:50 +01:00
|
|
|
job_name = self._make_job_name(filepath)
|
2017-01-13 17:24:37 +01:00
|
|
|
try:
|
2021-02-16 11:21:06 +01:00
|
|
|
job_info = await create_job(
|
|
|
|
self.user_id,
|
|
|
|
project_id,
|
|
|
|
manager_id,
|
|
|
|
scene.flamenco_render_job_type,
|
|
|
|
settings,
|
|
|
|
job_name,
|
|
|
|
priority=scene.flamenco_render_job_priority,
|
|
|
|
start_paused=scene.flamenco_start_paused,
|
|
|
|
)
|
2017-01-31 18:29:00 +01:00
|
|
|
except Exception as ex:
|
2019-01-30 13:05:09 +01:00
|
|
|
message = str(ex)
|
|
|
|
if isinstance(ex, pillarsdk.exceptions.BadRequest):
|
|
|
|
payload = ex.response.json()
|
|
|
|
try:
|
2021-02-16 11:21:06 +01:00
|
|
|
message = payload["_error"]["message"]
|
2019-01-30 13:05:09 +01:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.exception("Error creating Flamenco job")
|
|
|
|
self.report({"ERROR"}, "Error creating Flamenco job: %s" % message)
|
2017-01-17 16:03:46 +01:00
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
# BAT-pack the files to the destination directory.
|
2021-02-16 11:21:06 +01:00
|
|
|
job_id = job_info["_id"]
|
2019-02-28 12:52:51 +01:00
|
|
|
outdir, outfile, missing_sources = await self.bat_pack(job_id, filepath)
|
|
|
|
if not outfile:
|
|
|
|
return
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
# Store the job ID in a file in the output dir, if we can.
|
|
|
|
# TODO: Make it possible to create this file first and then send it to BAT for packing.
|
|
|
|
if outdir is not None:
|
|
|
|
await self._create_jobinfo_json(
|
2021-02-16 11:21:06 +01:00
|
|
|
outdir, job_info, manager_id, project_id, missing_sources
|
|
|
|
)
|
2018-12-05 12:57:39 +01:00
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
# Now that the files have been transfered, PATCH the job at the Manager
|
|
|
|
# to kick off the job compilation.
|
|
|
|
job_filepath = manager.replace_path(outfile)
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Final file path: %s", job_filepath)
|
|
|
|
new_settings = {"filepath": job_filepath}
|
2019-02-28 12:52:51 +01:00
|
|
|
await self.compile_job(job_id, new_settings)
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2017-01-24 14:39:49 +01:00
|
|
|
# We can now remove the local copy we made with bpy.ops.wm.save_as_mainfile().
|
2018-03-15 12:36:05 +01:00
|
|
|
# Strictly speaking we can already remove it after the BAT-pack, but it may come in
|
2017-01-24 14:39:49 +01:00
|
|
|
# handy in case of failures.
|
|
|
|
try:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.info("Removing temporary file %s", filepath)
|
2017-01-24 14:39:49 +01:00
|
|
|
filepath.unlink()
|
|
|
|
except Exception as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"ERROR"}, "Unable to remove file: %s" % ex)
|
2017-01-24 14:39:49 +01:00
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
|
2017-01-24 15:14:43 +01:00
|
|
|
if prefs.flamenco_open_browser_after_submit:
|
|
|
|
import webbrowser
|
|
|
|
from urllib.parse import urljoin
|
|
|
|
from ..blender import PILLAR_WEB_SERVER_URL
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
url = urljoin(PILLAR_WEB_SERVER_URL, "/flamenco/jobs/%s/redir" % job_id)
|
2017-01-24 15:14:43 +01:00
|
|
|
webbrowser.open_new_tab(url)
|
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
# Do a final report.
|
|
|
|
if missing_sources:
|
|
|
|
names = (ms.name for ms in missing_sources)
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report(
|
|
|
|
{"WARNING"},
|
|
|
|
"Flamenco job created with missing files: %s" % "; ".join(names),
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"INFO"}, "Flamenco job created.")
|
2017-01-24 15:15:08 +01:00
|
|
|
|
2019-01-31 14:42:50 +01:00
|
|
|
if self.quit_after_submit:
|
|
|
|
silently_quit_blender()
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
self.quit()
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
async def _create_jobinfo_json(
|
|
|
|
self,
|
|
|
|
outdir: Path,
|
|
|
|
job_info: dict,
|
|
|
|
manager_id: str,
|
|
|
|
project_id: str,
|
|
|
|
missing_sources: typing.List[Path],
|
|
|
|
):
|
2019-02-28 12:52:51 +01:00
|
|
|
from ..blender import preferences
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
prefs = preferences()
|
2021-02-16 11:21:06 +01:00
|
|
|
with open(str(outdir / "jobinfo.json"), "w", encoding="utf8") as outfile:
|
2019-02-28 12:52:51 +01:00
|
|
|
import json
|
|
|
|
|
|
|
|
# Version 1: Only the job doc was saved, with 'missing_files' added inside it.
|
|
|
|
# Version 2:
|
|
|
|
# - '_meta' key was added to indicate version.
|
|
|
|
# - 'job' is saved in a 'job' key, 'misssing_files' still top-level key.
|
|
|
|
# - 'exclusion_filter', 'project_settings', and 'flamenco_manager_settings'
|
|
|
|
# keys were added.
|
2021-02-16 11:21:06 +01:00
|
|
|
project_settings = prefs.get("project_settings", {}).get(project_id, {})
|
|
|
|
if hasattr(project_settings, "to_dict"):
|
2019-02-28 12:52:51 +01:00
|
|
|
project_settings = project_settings.to_dict()
|
|
|
|
|
|
|
|
# Pop out some settings so that settings of irrelevant Managers are excluded.
|
2021-02-16 11:21:06 +01:00
|
|
|
flamenco_managers_settings = project_settings.pop(
|
|
|
|
"flamenco_managers_settings", {}
|
|
|
|
)
|
|
|
|
flamenco_manager_settings = flamenco_managers_settings.pop(
|
|
|
|
manager_id, "-unknown-"
|
|
|
|
)
|
2019-02-28 12:52:51 +01:00
|
|
|
|
|
|
|
info = {
|
2021-02-16 11:21:06 +01:00
|
|
|
"_meta": {"version": 2},
|
|
|
|
"job": job_info,
|
|
|
|
"missing_files": [str(mf) for mf in missing_sources],
|
|
|
|
"exclusion_filter": (prefs.flamenco_exclude_filter or "").strip(),
|
|
|
|
"project_settings": project_settings,
|
|
|
|
"flamenco_manager_settings": flamenco_manager_settings,
|
2019-02-28 12:52:51 +01:00
|
|
|
}
|
|
|
|
json.dump(info, outfile, sort_keys=True, indent=4, cls=utils.JSONEncoder)
|
|
|
|
|
2019-02-13 15:17:50 +01:00
|
|
|
def _make_job_name(self, filepath: Path) -> str:
|
|
|
|
"""Turn a file to render into the render job name."""
|
|
|
|
|
|
|
|
job_name = filepath.name
|
2021-02-16 11:21:06 +01:00
|
|
|
if job_name.endswith(".blend"):
|
2019-02-13 15:17:50 +01:00
|
|
|
job_name = job_name[:-6]
|
2021-02-16 11:21:06 +01:00
|
|
|
if job_name.endswith(".flamenco"):
|
2019-02-13 15:17:50 +01:00
|
|
|
job_name = job_name[:-9]
|
|
|
|
|
|
|
|
return job_name
|
|
|
|
|
2018-12-06 15:47:13 +01:00
|
|
|
def validate_job_settings(self, context, settings: dict) -> bool:
|
|
|
|
"""Perform settings validations for the selected job type.
|
|
|
|
|
|
|
|
:returns: True if ok, False if there was an error.
|
|
|
|
"""
|
|
|
|
|
|
|
|
job_type = context.scene.flamenco_render_job_type
|
2021-02-16 11:21:06 +01:00
|
|
|
if job_type == "blender-video-chunks":
|
2018-12-06 15:47:13 +01:00
|
|
|
# This is not really a requirement, but should catch the mistake where it was
|
|
|
|
# left at the default setting (at the moment of writing that's 1 frame per chunk).
|
|
|
|
if context.scene.flamenco_render_fchunk_size < 10:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report(
|
|
|
|
{"ERROR"}, "Job type requires chunks of at least 10 frames."
|
|
|
|
)
|
2018-12-06 15:47:13 +01:00
|
|
|
return False
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
if settings["output_file_extension"] not in {".mkv", ".mp4", ".mov"}:
|
|
|
|
self.report(
|
|
|
|
{"ERROR"},
|
|
|
|
"Job type requires rendering to Matroska or "
|
|
|
|
"MP4 files, not %r." % settings["output_file_extension"],
|
|
|
|
)
|
2018-12-06 15:47:13 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2018-03-16 12:26:16 +01:00
|
|
|
def quit(self):
|
2021-02-16 11:21:06 +01:00
|
|
|
if bpy.context.window_manager.flamenco_status != "ABORTED":
|
|
|
|
bpy.context.window_manager.flamenco_status = "DONE"
|
2018-03-16 12:26:16 +01:00
|
|
|
super().quit()
|
|
|
|
|
2017-02-14 10:21:50 +01:00
|
|
|
async def _save_blendfile(self, context):
|
|
|
|
"""Save to a different file, specifically for Flamenco.
|
|
|
|
|
|
|
|
We shouldn't overwrite the artist's file.
|
|
|
|
We can compress, since this file won't be managed by SVN and doesn't need diffability.
|
|
|
|
"""
|
|
|
|
|
|
|
|
render = context.scene.render
|
|
|
|
|
|
|
|
# Remember settings we need to restore after saving.
|
|
|
|
old_use_file_extension = render.use_file_extension
|
|
|
|
old_use_overwrite = render.use_overwrite
|
|
|
|
old_use_placeholder = render.use_placeholder
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
disable_denoiser = (
|
|
|
|
context.scene.flamenco_render_job_type == "blender-render-progressive"
|
|
|
|
and render.engine == "CYCLES"
|
|
|
|
)
|
2019-01-30 16:01:54 +01:00
|
|
|
if disable_denoiser:
|
2021-02-16 11:21:06 +01:00
|
|
|
use_denoising = [
|
|
|
|
layer.cycles.use_denoising for layer in context.scene.view_layers
|
|
|
|
]
|
2019-01-30 16:01:54 +01:00
|
|
|
else:
|
|
|
|
use_denoising = []
|
|
|
|
|
2017-02-14 10:21:50 +01:00
|
|
|
try:
|
|
|
|
|
|
|
|
# The file extension should be determined by the render settings, not necessarily
|
|
|
|
# by the setttings in the output panel.
|
|
|
|
render.use_file_extension = True
|
|
|
|
|
|
|
|
# Rescheduling should not overwrite existing frames.
|
|
|
|
render.use_overwrite = False
|
|
|
|
render.use_placeholder = False
|
|
|
|
|
2019-01-30 16:01:54 +01:00
|
|
|
if disable_denoiser:
|
|
|
|
for layer in context.scene.view_layers:
|
|
|
|
layer.cycles.use_denoising = False
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
filepath = Path(context.blend_data.filepath).with_suffix(".flamenco.blend")
|
|
|
|
self.log.info("Saving copy to temporary file %s", filepath)
|
|
|
|
bpy.ops.wm.save_as_mainfile(
|
|
|
|
filepath=str(filepath), compress=True, copy=True
|
|
|
|
)
|
2017-02-14 10:21:50 +01:00
|
|
|
finally:
|
|
|
|
# Restore the settings we changed, even after an exception.
|
|
|
|
render.use_file_extension = old_use_file_extension
|
|
|
|
render.use_overwrite = old_use_overwrite
|
|
|
|
render.use_placeholder = old_use_placeholder
|
|
|
|
|
2019-01-30 16:01:54 +01:00
|
|
|
if disable_denoiser:
|
|
|
|
for denoise, layer in zip(use_denoising, context.scene.view_layers):
|
|
|
|
layer.cycles.use_denoising = denoise
|
|
|
|
|
2017-02-14 10:21:50 +01:00
|
|
|
return filepath
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
async def bat_pack(
|
|
|
|
self, job_id: str, filepath: Path
|
|
|
|
) -> typing.Tuple[
|
|
|
|
typing.Optional[Path], typing.Optional[PurePath], typing.List[Path]
|
|
|
|
]:
|
2018-03-15 12:36:05 +01:00
|
|
|
"""BAT-packs the blendfile to the destination directory.
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
Returns the path of the destination blend file.
|
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
:param job_id: the job ID given to us by Flamenco Server.
|
2017-01-17 16:03:46 +01:00
|
|
|
:param filepath: the blend file to pack (i.e. the current blend file)
|
2019-02-28 12:52:51 +01:00
|
|
|
:returns: A tuple of:
|
|
|
|
- The destination directory, or None if it does not exist on a
|
|
|
|
locally-reachable filesystem (for example when sending files to
|
|
|
|
a Shaman server).
|
|
|
|
- The destination blend file, or None if there were errors BAT-packing,
|
|
|
|
- A list of missing paths.
|
2017-01-17 16:03:46 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
prefs = preferences()
|
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
proj_abspath = bpy.path.abspath(prefs.cloud_project_local_path)
|
|
|
|
projdir = Path(proj_abspath).resolve()
|
2021-02-16 11:21:06 +01:00
|
|
|
exclusion_filter = (prefs.flamenco_exclude_filter or "").strip()
|
2019-02-28 12:52:51 +01:00
|
|
|
relative_only = prefs.flamenco_relative_only
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.debug("projdir: %s", projdir)
|
2019-02-28 12:53:29 +01:00
|
|
|
|
2020-03-03 10:37:44 +01:00
|
|
|
if is_shaman_url(prefs.flamenco_job_file_path):
|
2021-02-16 11:21:06 +01:00
|
|
|
endpoint, _ = bat_interface.parse_shaman_endpoint(
|
|
|
|
prefs.flamenco_job_file_path
|
|
|
|
)
|
|
|
|
self.log.info("Sending BAT pack to Shaman at %s", endpoint)
|
2019-02-28 12:53:29 +01:00
|
|
|
try:
|
|
|
|
outfile, missing_sources = await bat_interface.copy(
|
2021-02-16 11:21:06 +01:00
|
|
|
bpy.context,
|
|
|
|
filepath,
|
|
|
|
projdir,
|
|
|
|
"/",
|
|
|
|
exclusion_filter,
|
2019-02-28 12:53:29 +01:00
|
|
|
packer_class=bat_interface.ShamanPacker,
|
|
|
|
relative_only=relative_only,
|
|
|
|
endpoint=endpoint,
|
|
|
|
checkout_id=job_id,
|
2019-03-13 15:09:24 +01:00
|
|
|
manager_id=prefs.flamenco_manager.manager,
|
2019-02-28 12:53:29 +01:00
|
|
|
)
|
|
|
|
except bat_interface.FileTransferError as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.error(
|
|
|
|
"Could not transfer %d files, starting with %s",
|
|
|
|
len(ex.files_remaining),
|
|
|
|
ex.files_remaining[0],
|
|
|
|
)
|
|
|
|
self.report(
|
|
|
|
{"ERROR"}, "Unable to transfer %d files" % len(ex.files_remaining)
|
|
|
|
)
|
2019-02-28 12:53:29 +01:00
|
|
|
self.quit()
|
|
|
|
return None, None, []
|
|
|
|
except bat_interface.Aborted:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.warning("BAT Pack was aborted")
|
|
|
|
self.report({"WARNING"}, "Aborted Flamenco file packing/transferring")
|
2019-02-28 12:53:29 +01:00
|
|
|
self.quit()
|
|
|
|
return None, None, []
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bpy.context.window_manager.flamenco_status = "DONE"
|
|
|
|
outfile = PurePath("{shaman}") / outfile
|
2019-02-28 12:53:29 +01:00
|
|
|
return None, outfile, missing_sources
|
|
|
|
|
2019-10-25 13:34:34 +02:00
|
|
|
if is_file_inside_job_storage(prefs, filepath):
|
|
|
|
# The blend file is contained in the job storage path, no need to copy anything.
|
|
|
|
# Since BAT doesn't run, we also don't know whether files are missing.
|
|
|
|
return filepath.parent, filepath, []
|
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
# Create a unique directory that is still more or less identifyable.
|
|
|
|
# This should work better than a random ID.
|
2021-02-16 11:21:06 +01:00
|
|
|
unique_dir = "%s-%s-%s" % (
|
|
|
|
datetime.now().isoformat("-").replace(":", ""),
|
|
|
|
self.db_user["username"],
|
|
|
|
filepath.stem,
|
|
|
|
)
|
2017-01-17 16:03:46 +01:00
|
|
|
outdir = Path(prefs.flamenco_job_file_path) / unique_dir
|
2017-04-21 18:15:59 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.debug("outdir : %s", outdir)
|
2018-07-12 11:53:30 +02:00
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
try:
|
|
|
|
outdir.mkdir(parents=True)
|
|
|
|
except Exception as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.exception("Unable to create output path %s", outdir)
|
|
|
|
self.report({"ERROR"}, "Unable to create output path: %s" % ex)
|
2017-01-17 16:03:46 +01:00
|
|
|
self.quit()
|
2018-03-21 16:05:20 +01:00
|
|
|
return outdir, None, []
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
try:
|
2018-03-16 12:15:53 +01:00
|
|
|
outfile, missing_sources = await bat_interface.copy(
|
2021-02-16 11:21:06 +01:00
|
|
|
bpy.context,
|
|
|
|
filepath,
|
|
|
|
projdir,
|
|
|
|
outdir,
|
|
|
|
exclusion_filter,
|
|
|
|
relative_only=relative_only,
|
|
|
|
)
|
2018-03-15 12:36:05 +01:00
|
|
|
except bat_interface.FileTransferError as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.error(
|
|
|
|
"Could not transfer %d files, starting with %s",
|
|
|
|
len(ex.files_remaining),
|
|
|
|
ex.files_remaining[0],
|
|
|
|
)
|
|
|
|
self.report(
|
|
|
|
{"ERROR"}, "Unable to transfer %d files" % len(ex.files_remaining)
|
|
|
|
)
|
2017-01-17 16:03:46 +01:00
|
|
|
self.quit()
|
2018-03-21 16:05:20 +01:00
|
|
|
return outdir, None, []
|
2018-03-16 12:41:09 +01:00
|
|
|
except bat_interface.Aborted:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.warning("BAT Pack was aborted")
|
|
|
|
self.report({"WARNING"}, "Aborted Flamenco file packing/transferring")
|
2018-03-16 12:41:09 +01:00
|
|
|
self.quit()
|
2018-03-21 16:05:20 +01:00
|
|
|
return outdir, None, []
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bpy.context.window_manager.flamenco_status = "DONE"
|
2018-03-21 16:05:20 +01:00
|
|
|
return outdir, outfile, missing_sources
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2019-02-28 12:52:51 +01:00
|
|
|
async def compile_job(self, job_id: str, new_settings: dict) -> None:
|
|
|
|
"""Request Flamenco Server to start compiling the job."""
|
|
|
|
|
|
|
|
payload = {
|
2021-02-16 11:21:06 +01:00
|
|
|
"op": "construct",
|
|
|
|
"settings": new_settings,
|
2019-02-28 12:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
from .sdk import Job
|
|
|
|
from ..pillar import pillar_call
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
job = Job({"_id": job_id})
|
2019-02-28 12:52:51 +01:00
|
|
|
await pillar_call(job.patch, payload, caching=False)
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-07-03 11:09:31 +02:00
|
|
|
def scene_frame_range(context) -> str:
|
|
|
|
"""Returns the frame range string for the current scene."""
|
|
|
|
|
|
|
|
s = context.scene
|
2021-02-16 11:21:06 +01:00
|
|
|
return "%i-%i" % (s.frame_start, s.frame_end)
|
2017-07-03 11:09:31 +02:00
|
|
|
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
class FLAMENCO_OT_scene_to_frame_range(FlamencoPollMixin, Operator):
|
2017-01-13 17:24:37 +01:00
|
|
|
"""Sets the scene frame range as the Flamenco render frame range."""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "flamenco.scene_to_frame_range"
|
|
|
|
bl_label = "Sets the scene frame range as the Flamenco render frame range"
|
|
|
|
bl_description = __doc__.rstrip(".")
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2017-07-03 11:09:31 +02:00
|
|
|
context.scene.flamenco_render_frame_range = scene_frame_range(context)
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class FLAMENCO_OT_copy_files(
|
|
|
|
Operator, FlamencoPollMixin, async_loop.AsyncModalOperatorMixin
|
|
|
|
):
|
2018-03-15 18:01:04 +01:00
|
|
|
"""Uses BAT to copy the current blendfile + dependencies to the target directory.
|
|
|
|
|
|
|
|
This operator is not used directly, but can be useful for testing.
|
|
|
|
"""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "flamenco.copy_files"
|
|
|
|
bl_label = "Copy files to target"
|
|
|
|
bl_description = __doc__.rstrip(".")
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
stop_upon_exception = True
|
|
|
|
|
2018-03-20 16:52:50 +01:00
|
|
|
async def async_execute(self, context) -> None:
|
2017-01-17 16:03:46 +01:00
|
|
|
from pathlib import Path
|
|
|
|
from ..blender import preferences
|
|
|
|
|
2018-03-15 12:36:05 +01:00
|
|
|
prefs = preferences()
|
2021-02-16 11:21:06 +01:00
|
|
|
exclusion_filter = (prefs.flamenco_exclude_filter or "").strip()
|
2017-01-24 14:55:39 +01:00
|
|
|
|
2018-03-20 16:52:50 +01:00
|
|
|
storage_path = prefs.flamenco_job_file_path # type: str
|
|
|
|
|
|
|
|
try:
|
|
|
|
outpath, missing_sources = await bat_interface.copy(
|
|
|
|
context,
|
|
|
|
Path(context.blend_data.filepath),
|
|
|
|
Path(prefs.cloud_project_local_path),
|
|
|
|
Path(storage_path),
|
2021-02-16 11:21:06 +01:00
|
|
|
exclusion_filter,
|
2018-03-20 16:52:50 +01:00
|
|
|
)
|
|
|
|
except bat_interface.FileTransferError as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.error(
|
|
|
|
"Could not transfer %d files, starting with %s",
|
|
|
|
len(ex.files_remaining),
|
|
|
|
ex.files_remaining[0],
|
|
|
|
)
|
|
|
|
self.report(
|
|
|
|
{"ERROR"}, "Unable to transfer %d files" % len(ex.files_remaining)
|
|
|
|
)
|
2018-03-20 16:52:50 +01:00
|
|
|
self.quit()
|
|
|
|
return
|
|
|
|
except bat_interface.Aborted:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.log.warning("BAT Pack was aborted")
|
|
|
|
self.report({"WARNING"}, "Aborted Flamenco file packing/transferring")
|
2018-03-20 16:52:50 +01:00
|
|
|
self.quit()
|
|
|
|
return
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
if missing_sources:
|
|
|
|
names = (ms.name for ms in missing_sources)
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"ERROR"}, "Missing source files: %s" % "; ".join(names))
|
2018-03-15 18:01:04 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report({"INFO"}, "Written %s" % outpath)
|
|
|
|
context.window_manager.flamenco_status = "DONE"
|
2017-01-17 16:03:46 +01:00
|
|
|
self.quit()
|
|
|
|
|
2018-03-16 12:15:53 +01:00
|
|
|
|
|
|
|
class FLAMENCO_OT_abort(Operator, FlamencoPollMixin):
|
|
|
|
"""Aborts a running Flamenco file packing/transfer operation."""
|
2021-02-16 11:21:06 +01:00
|
|
|
|
|
|
|
bl_idname = "flamenco.abort"
|
|
|
|
bl_label = "Abort"
|
|
|
|
bl_description = __doc__.rstrip(".")
|
2018-03-16 12:15:53 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
2021-02-16 11:21:06 +01:00
|
|
|
return (
|
|
|
|
super().poll(context)
|
|
|
|
and context.window_manager.flamenco_status != "ABORTING"
|
|
|
|
)
|
2018-03-16 12:15:53 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
2021-02-16 11:21:06 +01:00
|
|
|
context.window_manager.flamenco_status = "ABORTING"
|
2018-03-16 12:15:53 +01:00
|
|
|
bat_interface.abort()
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2017-01-24 14:55:39 +01:00
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
class FLAMENCO_OT_explore_file_path(FlamencoPollMixin, Operator):
|
2017-03-17 15:08:50 +01:00
|
|
|
"""Opens the Flamenco job storage path in a file explorer.
|
|
|
|
|
|
|
|
If the path cannot be found, this operator tries to open its parent.
|
|
|
|
"""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "flamenco.explore_file_path"
|
|
|
|
bl_label = "Open in file explorer"
|
|
|
|
bl_description = __doc__.rstrip(".")
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
path: StringProperty(name="Path", description="Path to explore", subtype="DIR_PATH")
|
2017-01-18 14:31:25 +01:00
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
def execute(self, context):
|
|
|
|
import platform
|
2017-03-17 15:08:50 +01:00
|
|
|
import pathlib
|
|
|
|
|
|
|
|
# Possibly open a parent of the path
|
|
|
|
to_open = pathlib.Path(self.path)
|
|
|
|
while to_open.parent != to_open: # while we're not at the root
|
|
|
|
if to_open.exists():
|
|
|
|
break
|
|
|
|
to_open = to_open.parent
|
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
self.report(
|
|
|
|
{"ERROR"}, "Unable to open %s or any of its parents." % self.path
|
|
|
|
)
|
|
|
|
return {"CANCELLED"}
|
2017-03-17 15:08:50 +01:00
|
|
|
to_open = str(to_open)
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
2017-03-17 15:08:50 +01:00
|
|
|
import os
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2017-03-17 15:08:50 +01:00
|
|
|
os.startfile(to_open)
|
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
elif platform.system() == "Darwin":
|
2017-03-17 15:08:50 +01:00
|
|
|
import subprocess
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2017-03-17 15:08:50 +01:00
|
|
|
subprocess.Popen(["open", to_open])
|
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
else:
|
2017-03-17 15:08:50 +01:00
|
|
|
import subprocess
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2017-03-17 15:08:50 +01:00
|
|
|
subprocess.Popen(["xdg-open", to_open])
|
2017-01-17 16:03:46 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2017-01-17 16:03:46 +01:00
|
|
|
|
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
class FLAMENCO_OT_enable_output_path_override(Operator):
|
|
|
|
"""Enables the 'override output path' setting."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "flamenco.enable_output_path_override"
|
|
|
|
bl_label = "Enable Overriding of Output Path"
|
|
|
|
bl_description = (
|
|
|
|
"Click to specify a non-default Output Path for this particular job"
|
|
|
|
)
|
2017-10-06 12:39:18 +02:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
context.scene.flamenco_do_override_output_path = True
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2017-10-06 12:39:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FLAMENCO_OT_disable_output_path_override(Operator):
|
|
|
|
"""Disables the 'override output path' setting."""
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "flamenco.disable_output_path_override"
|
|
|
|
bl_label = "disable Overriding of Output Path"
|
|
|
|
bl_description = "Click to use the default Output Path"
|
2017-10-06 12:39:18 +02:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
context.scene.flamenco_do_override_output_path = False
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
2017-10-06 12:39:18 +02:00
|
|
|
|
|
|
|
|
2019-01-30 16:01:02 +01:00
|
|
|
class FLAMENCO_OT_set_recommended_sample_cap(Operator):
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_idname = "flamenco.set_recommended_sample_cap"
|
|
|
|
bl_label = "Set Recommended Maximum Sample Count"
|
|
|
|
bl_description = "Set the recommended maximum samples per render task"
|
2019-01-30 16:01:02 +01:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
sample_cap: IntProperty()
|
2019-01-30 16:01:02 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
context.scene.flamenco_render_chunk_sample_cap = self.sample_cap
|
2021-02-16 11:21:06 +01:00
|
|
|
return {"FINISHED"}
|
|
|
|
|
|
|
|
|
|
|
|
async def create_job(
|
|
|
|
user_id: str,
|
|
|
|
project_id: str,
|
|
|
|
manager_id: str,
|
|
|
|
job_type: str,
|
|
|
|
job_settings: dict,
|
|
|
|
job_name: str = None,
|
|
|
|
*,
|
|
|
|
priority: int = 50,
|
|
|
|
job_description: str = None,
|
|
|
|
start_paused=False
|
|
|
|
) -> dict:
|
2017-01-17 16:03:46 +01:00
|
|
|
"""Creates a render job at Flamenco Server, returning the job object as dictionary."""
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
import json
|
|
|
|
from .sdk import Job
|
|
|
|
from ..pillar import pillar_call
|
|
|
|
|
|
|
|
job_attrs = {
|
2021-02-16 11:21:06 +01:00
|
|
|
"status": "waiting-for-files",
|
|
|
|
"priority": priority,
|
|
|
|
"name": job_name,
|
|
|
|
"settings": job_settings,
|
|
|
|
"job_type": job_type,
|
|
|
|
"user": user_id,
|
|
|
|
"manager": manager_id,
|
|
|
|
"project": project_id,
|
2017-01-13 17:24:37 +01:00
|
|
|
}
|
|
|
|
if job_description:
|
2021-02-16 11:21:06 +01:00
|
|
|
job_attrs["description"] = job_description
|
2018-07-12 11:54:13 +02:00
|
|
|
if start_paused:
|
2021-02-16 11:21:06 +01:00
|
|
|
job_attrs["start_paused"] = True
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
log.info(
|
|
|
|
"Going to create Flamenco job:\n%s",
|
|
|
|
json.dumps(job_attrs, indent=4, sort_keys=True),
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
job = Job(job_attrs)
|
|
|
|
await pillar_call(job.create)
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
log.info("Job created succesfully: %s", job._id)
|
2017-01-17 16:03:46 +01:00
|
|
|
return job.to_dict()
|
|
|
|
|
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
def is_image_type(render_output_type: str) -> bool:
|
|
|
|
"""Determines whether the render output type is an image (True) or video (False)."""
|
|
|
|
|
|
|
|
# This list is taken from rna_scene.c:273, rna_enum_image_type_items.
|
2021-02-16 11:21:06 +01:00
|
|
|
video_types = {"AVI_JPEG", "AVI_RAW", "FRAMESERVER", "FFMPEG", "QUICKTIME"}
|
2017-01-18 14:31:25 +01:00
|
|
|
return render_output_type not in video_types
|
|
|
|
|
|
|
|
|
|
|
|
@functools.lru_cache(1)
|
|
|
|
def _render_output_path(
|
2021-02-16 11:21:06 +01:00
|
|
|
local_project_path: str,
|
|
|
|
blend_filepath: Path,
|
|
|
|
flamenco_render_job_type: str,
|
|
|
|
flamenco_job_output_strip_components: int,
|
|
|
|
flamenco_job_output_path: str,
|
|
|
|
render_image_format: str,
|
|
|
|
flamenco_render_frame_range: str,
|
|
|
|
*,
|
|
|
|
include_rel_path: bool = True
|
|
|
|
) -> typing.Optional[PurePath]:
|
2017-01-18 14:31:25 +01:00
|
|
|
"""Cached version of render_output_path()
|
|
|
|
|
|
|
|
This ensures that redraws of the Flamenco Render and Add-on preferences panels
|
|
|
|
is fast.
|
|
|
|
"""
|
|
|
|
|
2017-02-01 14:00:46 +01:00
|
|
|
try:
|
|
|
|
project_path = Path(bpy.path.abspath(local_project_path)).resolve()
|
|
|
|
except FileNotFoundError:
|
|
|
|
# Path.resolve() will raise a FileNotFoundError if the project path doesn't exist.
|
|
|
|
return None
|
2017-01-18 14:31:25 +01:00
|
|
|
|
|
|
|
try:
|
2017-05-03 15:33:22 +02:00
|
|
|
blend_abspath = blend_filepath.resolve().absolute()
|
|
|
|
except FileNotFoundError:
|
|
|
|
# Path.resolve() will raise a FileNotFoundError if the path doesn't exist.
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
proj_rel = blend_abspath.parent.relative_to(project_path)
|
2017-01-18 14:31:25 +01:00
|
|
|
except ValueError:
|
|
|
|
return None
|
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
output_top = PurePath(flamenco_job_output_path)
|
2017-01-31 18:29:10 +01:00
|
|
|
|
|
|
|
# Strip off '.flamenco' too; we use 'xxx.flamenco.blend' as job file, but
|
|
|
|
# don't want to have all the output paths ending in '.flamenco'.
|
|
|
|
stem = blend_filepath.stem
|
2021-02-16 11:21:06 +01:00
|
|
|
if stem.endswith(".flamenco"):
|
2017-01-31 18:29:10 +01:00
|
|
|
stem = stem[:-9]
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
if flamenco_render_job_type == "blender-video-chunks":
|
|
|
|
return output_top / ("YYYY_MM_DD_SEQ-%s.mkv" % stem)
|
2018-12-06 15:47:13 +01:00
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
if include_rel_path:
|
|
|
|
rel_parts = proj_rel.parts[flamenco_job_output_strip_components:]
|
|
|
|
dir_components = output_top.joinpath(*rel_parts) / stem
|
|
|
|
else:
|
|
|
|
dir_components = output_top
|
2017-01-18 14:31:25 +01:00
|
|
|
|
|
|
|
# Blender will have to append the file extensions by itself.
|
|
|
|
if is_image_type(render_image_format):
|
2021-02-16 11:21:06 +01:00
|
|
|
return dir_components / "######"
|
2017-01-18 14:31:25 +01:00
|
|
|
return dir_components / flamenco_render_frame_range
|
|
|
|
|
|
|
|
|
2017-01-30 10:38:35 +01:00
|
|
|
def render_output_path(context, filepath: Path = None) -> typing.Optional[PurePath]:
|
2017-01-18 14:31:25 +01:00
|
|
|
"""Returns the render output path to be sent to Flamenco.
|
|
|
|
|
2017-01-24 14:39:49 +01:00
|
|
|
:param context: the Blender context (used to find Flamenco preferences etc.)
|
|
|
|
:param filepath: the Path of the blend file to render, or None for the current file.
|
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
Returns None when the current blend file is outside the project path.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ..blender import preferences
|
|
|
|
|
|
|
|
scene = context.scene
|
|
|
|
prefs = preferences()
|
|
|
|
|
2017-01-24 14:39:49 +01:00
|
|
|
if filepath is None:
|
|
|
|
filepath = Path(context.blend_data.filepath)
|
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
if scene.flamenco_do_override_output_path:
|
|
|
|
job_output_path = scene.flamenco_override_output_path
|
|
|
|
else:
|
|
|
|
job_output_path = prefs.flamenco_job_output_path
|
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
return _render_output_path(
|
2017-03-21 14:06:45 +01:00
|
|
|
prefs.cloud_project_local_path,
|
2017-01-24 14:39:49 +01:00
|
|
|
filepath,
|
2018-12-06 15:47:13 +01:00
|
|
|
scene.flamenco_render_job_type,
|
2017-01-18 14:31:25 +01:00
|
|
|
prefs.flamenco_job_output_strip_components,
|
2017-10-06 12:39:18 +02:00
|
|
|
job_output_path,
|
2017-01-18 14:31:25 +01:00
|
|
|
scene.render.image_settings.file_format,
|
|
|
|
scene.flamenco_render_frame_range,
|
2017-10-06 12:39:18 +02:00
|
|
|
include_rel_path=not scene.flamenco_do_override_output_path,
|
2017-01-18 14:31:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
class FLAMENCO_PT_render(bpy.types.Panel, FlamencoPollMixin):
|
2017-01-17 16:03:46 +01:00
|
|
|
bl_label = "Flamenco Render"
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_space_type = "PROPERTIES"
|
|
|
|
bl_region_type = "WINDOW"
|
2017-01-17 16:03:46 +01:00
|
|
|
bl_context = "render"
|
2021-02-16 11:21:06 +01:00
|
|
|
bl_options = {"DEFAULT_CLOSED"}
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-01-17 16:03:46 +01:00
|
|
|
from ..blender import preferences
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
prefs = preferences()
|
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Manager:")
|
2018-07-25 15:01:39 +02:00
|
|
|
prop_btn_row = labeled_row.row(align=True)
|
|
|
|
|
|
|
|
bcp = prefs.flamenco_manager
|
2021-02-16 11:21:06 +01:00
|
|
|
if bcp.status in {"NONE", "IDLE"}:
|
2018-07-25 15:01:39 +02:00
|
|
|
if not bcp.available_managers or not bcp.manager:
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_btn_row.operator(
|
|
|
|
"flamenco.managers",
|
|
|
|
text="Find Flamenco Managers",
|
|
|
|
icon="FILE_REFRESH",
|
|
|
|
)
|
2018-07-25 15:01:39 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_btn_row.prop(bcp, "manager", text="")
|
|
|
|
prop_btn_row.operator("flamenco.managers", text="", icon="FILE_REFRESH")
|
2018-07-25 15:01:39 +02:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_btn_row.label(text="Fetching available managers.")
|
2018-07-25 15:01:39 +02:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Job Type:")
|
|
|
|
labeled_row.prop(context.scene, "flamenco_render_job_type", text="")
|
2017-01-18 09:34:30 +01:00
|
|
|
|
2019-01-30 15:57:43 +01:00
|
|
|
# Job-type-specific options go directly below the job type selector.
|
2019-02-06 09:32:24 +01:00
|
|
|
box = layout.box()
|
2021-02-16 11:21:06 +01:00
|
|
|
if (
|
|
|
|
getattr(context.scene, "flamenco_render_job_type", None)
|
|
|
|
== "blender-render-progressive"
|
|
|
|
):
|
2019-01-30 16:03:58 +01:00
|
|
|
if bpy.app.version < (2, 80):
|
|
|
|
box.alert = True
|
2021-02-16 11:21:06 +01:00
|
|
|
box.label(
|
|
|
|
text="Progressive rendering requires Blender 2.80 or newer.",
|
|
|
|
icon="ERROR",
|
|
|
|
)
|
2019-01-30 16:03:58 +01:00
|
|
|
# This isn't entirely fair, as Blender 2.79 could hypothetically
|
|
|
|
# be used to submit a job to farm running Blender 2.80.
|
|
|
|
return
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
if context.scene.render.engine != "CYCLES":
|
2019-01-30 16:04:31 +01:00
|
|
|
box.alert = True
|
2021-02-16 11:21:06 +01:00
|
|
|
box.label(text="Progressive rendering requires Cycles", icon="ERROR")
|
2019-01-30 16:04:31 +01:00
|
|
|
return
|
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
box.prop(context.scene, "flamenco_render_chunk_sample_cap")
|
2019-01-30 16:01:02 +01:00
|
|
|
|
|
|
|
sample_count = scene_sample_count(context.scene)
|
|
|
|
recommended_cap = sample_count // 4
|
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
split = box.split(factor=0.4)
|
2021-02-16 11:21:06 +01:00
|
|
|
split.label(text="Total Sample Count: %d" % sample_count)
|
|
|
|
props = split.operator(
|
|
|
|
"flamenco.set_recommended_sample_cap",
|
|
|
|
text="Recommended Max Samples per Task: %d" % recommended_cap,
|
|
|
|
)
|
2019-01-30 16:01:02 +01:00
|
|
|
props.sample_cap = recommended_cap
|
|
|
|
|
2019-01-30 16:01:54 +01:00
|
|
|
if any(layer.cycles.use_denoising for layer in context.scene.view_layers):
|
2021-02-16 11:21:06 +01:00
|
|
|
box.label(
|
|
|
|
text="Progressive Rendering will disable Denoising.", icon="ERROR"
|
|
|
|
)
|
2019-01-30 16:01:54 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
box.prop(
|
|
|
|
context.scene,
|
|
|
|
"flamenco_render_fchunk_size",
|
|
|
|
text="Minimum Frames per Task",
|
|
|
|
)
|
2019-02-06 09:32:24 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
box.prop(context.scene, "flamenco_render_fchunk_size")
|
2019-02-06 09:32:24 +01:00
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Frame Range:")
|
2017-01-17 16:03:46 +01:00
|
|
|
prop_btn_row = labeled_row.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_btn_row.prop(context.scene, "flamenco_render_frame_range", text="")
|
|
|
|
prop_btn_row.operator(
|
|
|
|
"flamenco.scene_to_frame_range", text="", icon="ARROW_LEFTRIGHT"
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
layout.prop(context.scene, "flamenco_render_job_priority")
|
|
|
|
layout.prop(context.scene, "flamenco_start_paused")
|
2017-01-30 10:38:35 +01:00
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
paths_layout = layout.column(align=True)
|
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = paths_layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Storage:")
|
2017-01-17 16:03:46 +01:00
|
|
|
prop_btn_row = labeled_row.row(align=True)
|
2018-09-04 13:47:44 +02:00
|
|
|
prop_btn_row.label(text=prefs.flamenco_job_file_path)
|
2021-02-16 11:21:06 +01:00
|
|
|
props = prop_btn_row.operator(
|
|
|
|
FLAMENCO_OT_explore_file_path.bl_idname, text="", icon="DISK_DRIVE"
|
|
|
|
)
|
2017-01-18 14:31:25 +01:00
|
|
|
props.path = prefs.flamenco_job_file_path
|
|
|
|
|
2020-03-03 10:37:44 +01:00
|
|
|
if is_file_inside_job_storage(prefs, context.blend_data.filepath):
|
2019-10-25 13:34:34 +02:00
|
|
|
# File is contained in the job storage path, no need to copy anything.
|
2021-02-16 11:21:06 +01:00
|
|
|
paths_layout.label(
|
|
|
|
text="Current file already in job storage path; "
|
|
|
|
"not going to create BAT pack."
|
|
|
|
)
|
2019-10-25 13:34:34 +02:00
|
|
|
|
2017-01-18 14:31:25 +01:00
|
|
|
render_output = render_output_path(context)
|
2017-01-18 16:45:54 +01:00
|
|
|
if render_output is None:
|
2021-02-16 11:21:06 +01:00
|
|
|
paths_layout.label(
|
|
|
|
text="Unable to render with Flamenco, outside of project directory."
|
|
|
|
)
|
2018-03-16 12:40:05 +01:00
|
|
|
return
|
|
|
|
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = paths_layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Output:")
|
2018-03-16 12:40:05 +01:00
|
|
|
prop_btn_row = labeled_row.row(align=True)
|
|
|
|
|
|
|
|
if context.scene.flamenco_do_override_output_path:
|
2021-02-16 11:21:06 +01:00
|
|
|
prop_btn_row.prop(context.scene, "flamenco_override_output_path", text="")
|
2018-03-16 12:40:05 +01:00
|
|
|
op = FLAMENCO_OT_disable_output_path_override.bl_idname
|
2021-02-16 11:21:06 +01:00
|
|
|
icon = "X"
|
2017-01-18 16:45:54 +01:00
|
|
|
else:
|
2018-09-04 13:47:44 +02:00
|
|
|
prop_btn_row.label(text=str(render_output))
|
2018-03-16 12:40:05 +01:00
|
|
|
op = FLAMENCO_OT_enable_output_path_override.bl_idname
|
2021-02-16 11:21:06 +01:00
|
|
|
icon = "GREASEPENCIL"
|
|
|
|
prop_btn_row.operator(op, icon=icon, text="")
|
2017-10-06 12:39:18 +02:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
props = prop_btn_row.operator(
|
|
|
|
FLAMENCO_OT_explore_file_path.bl_idname, text="", icon="DISK_DRIVE"
|
|
|
|
)
|
2018-03-16 12:40:05 +01:00
|
|
|
props.path = str(render_output.parent)
|
|
|
|
|
|
|
|
if context.scene.flamenco_do_override_output_path:
|
2021-02-16 11:33:48 +01:00
|
|
|
labeled_row = paths_layout.split(factor=0.25, align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
labeled_row.label(text="Effective Output Path:")
|
2018-09-04 13:47:44 +02:00
|
|
|
labeled_row.label(text=str(render_output))
|
2018-03-16 12:40:05 +01:00
|
|
|
|
2019-02-04 11:39:14 +01:00
|
|
|
self.draw_odd_size_warning(layout, context.scene.render)
|
|
|
|
|
2018-03-16 12:40:05 +01:00
|
|
|
# Show current status of Flamenco.
|
|
|
|
flamenco_status = context.window_manager.flamenco_status
|
2021-02-16 11:21:06 +01:00
|
|
|
if flamenco_status in {"IDLE", "ABORTED", "DONE"}:
|
2019-01-31 14:42:50 +01:00
|
|
|
if prefs.flamenco_show_quit_after_submit_button:
|
2021-02-16 11:33:48 +01:00
|
|
|
ui = layout.split(factor=0.75, align=True)
|
2019-01-31 14:42:50 +01:00
|
|
|
else:
|
|
|
|
ui = layout
|
2021-02-16 11:21:06 +01:00
|
|
|
ui.operator(
|
|
|
|
FLAMENCO_OT_render.bl_idname,
|
|
|
|
text="Render on Flamenco",
|
|
|
|
icon="RENDER_ANIMATION",
|
|
|
|
).quit_after_submit = False
|
2019-01-31 14:42:50 +01:00
|
|
|
if prefs.flamenco_show_quit_after_submit_button:
|
2021-02-16 11:21:06 +01:00
|
|
|
ui.operator(
|
|
|
|
FLAMENCO_OT_render.bl_idname,
|
|
|
|
text="Submit & Quit",
|
|
|
|
icon="RENDER_ANIMATION",
|
|
|
|
).quit_after_submit = True
|
2018-03-20 16:52:50 +01:00
|
|
|
if bpy.app.debug:
|
|
|
|
layout.operator(FLAMENCO_OT_copy_files.bl_idname)
|
2021-02-16 11:21:06 +01:00
|
|
|
elif flamenco_status == "INVESTIGATING":
|
2018-03-16 12:40:05 +01:00
|
|
|
row = layout.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
row.label(text="Investigating your files")
|
|
|
|
row.operator(FLAMENCO_OT_abort.bl_idname, text="", icon="CANCEL")
|
|
|
|
elif flamenco_status == "COMMUNICATING":
|
|
|
|
layout.label(text="Communicating with Flamenco Server")
|
|
|
|
elif flamenco_status == "ABORTING":
|
2018-03-16 12:40:05 +01:00
|
|
|
row = layout.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
row.label(text="Aborting, please wait.")
|
|
|
|
row.operator(FLAMENCO_OT_abort.bl_idname, text="", icon="CANCEL")
|
|
|
|
if flamenco_status == "TRANSFERRING":
|
2018-03-16 12:40:05 +01:00
|
|
|
row = layout.row(align=True)
|
2021-02-16 11:21:06 +01:00
|
|
|
row.prop(
|
|
|
|
context.window_manager,
|
|
|
|
"flamenco_progress",
|
|
|
|
text=context.window_manager.flamenco_status_txt,
|
|
|
|
)
|
|
|
|
row.operator(FLAMENCO_OT_abort.bl_idname, text="", icon="CANCEL")
|
|
|
|
elif flamenco_status != "IDLE" and context.window_manager.flamenco_status_txt:
|
2018-09-04 13:47:44 +02:00
|
|
|
layout.label(text=context.window_manager.flamenco_status_txt)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2019-02-04 11:39:14 +01:00
|
|
|
def draw_odd_size_warning(self, layout, render):
|
|
|
|
render_width = render.resolution_x * render.resolution_percentage // 100
|
|
|
|
render_height = render.resolution_y * render.resolution_percentage // 100
|
|
|
|
|
|
|
|
odd_width = render_width % 2
|
|
|
|
odd_height = render_height % 2
|
|
|
|
|
|
|
|
if not odd_width and not odd_height:
|
|
|
|
return
|
|
|
|
|
|
|
|
box = layout.box()
|
|
|
|
box.alert = True
|
|
|
|
|
|
|
|
if odd_width and odd_height:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg = "Both X (%d) and Y (%d) resolution are" % (
|
|
|
|
render_width,
|
|
|
|
render_height,
|
|
|
|
)
|
2019-02-04 11:39:14 +01:00
|
|
|
elif odd_width:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg = "X resolution (%d) is" % render_width
|
2019-02-04 11:39:14 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
msg = "Y resolution (%d) is" % render_height
|
2019-02-04 11:39:14 +01:00
|
|
|
|
2021-02-16 11:21:06 +01:00
|
|
|
box.label(text=msg + " not divisible by 2.", icon="ERROR")
|
|
|
|
box.label(
|
|
|
|
text="Any video rendered from these frames will be padded with black pixels."
|
|
|
|
)
|
2019-02-04 11:39:14 +01:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2017-03-17 15:08:09 +01:00
|
|
|
def activate():
|
|
|
|
"""Activates draw callbacks, menu items etc. for Flamenco."""
|
|
|
|
|
|
|
|
global flamenco_is_active
|
2021-02-16 11:21:06 +01:00
|
|
|
log.info("Activating Flamenco")
|
2017-03-17 15:08:09 +01:00
|
|
|
flamenco_is_active = True
|
2017-05-03 15:32:32 +02:00
|
|
|
_render_output_path.cache_clear()
|
2017-03-17 15:08:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
def deactivate():
|
|
|
|
"""Deactivates draw callbacks, menu items etc. for Flamenco."""
|
|
|
|
|
|
|
|
global flamenco_is_active
|
2021-02-16 11:21:06 +01:00
|
|
|
log.info("Deactivating Flamenco")
|
2017-03-17 15:08:09 +01:00
|
|
|
flamenco_is_active = False
|
2017-05-03 15:32:32 +02:00
|
|
|
_render_output_path.cache_clear()
|
2017-03-17 15:08:09 +01:00
|
|
|
|
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
def flamenco_do_override_output_path_updated(scene, context):
|
|
|
|
"""Set the override paths to the default, if not yet set."""
|
|
|
|
|
|
|
|
# Only set a default when enabling the override.
|
|
|
|
if not scene.flamenco_do_override_output_path:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Don't overwrite existing setting.
|
|
|
|
if scene.flamenco_override_output_path:
|
|
|
|
return
|
|
|
|
|
|
|
|
from ..blender import preferences
|
2021-02-16 11:21:06 +01:00
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
scene.flamenco_override_output_path = preferences().flamenco_job_output_path
|
2021-02-16 11:21:06 +01:00
|
|
|
log.info("Setting Override Output Path to %s", scene.flamenco_override_output_path)
|
2017-10-06 12:39:18 +02:00
|
|
|
|
|
|
|
|
2018-09-04 14:56:10 +02:00
|
|
|
# FlamencoManagerGroup needs to be registered before classes that use it.
|
|
|
|
_rna_classes = [FlamencoManagerGroup]
|
|
|
|
_rna_classes.extend(
|
2021-02-16 11:21:06 +01:00
|
|
|
cls
|
|
|
|
for cls in locals().values()
|
|
|
|
if (
|
|
|
|
isinstance(cls, type)
|
|
|
|
and cls.__name__.startswith("FLAMENCO")
|
|
|
|
and cls not in _rna_classes
|
|
|
|
)
|
2018-09-04 14:56:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
def register():
|
2017-01-24 14:55:39 +01:00
|
|
|
from ..utils import redraw
|
|
|
|
|
2018-09-04 14:56:10 +02:00
|
|
|
for cls in _rna_classes:
|
|
|
|
bpy.utils.register_class(cls)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
|
|
|
scene = bpy.types.Scene
|
2017-01-30 10:38:35 +01:00
|
|
|
scene.flamenco_render_fchunk_size = IntProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Frames per Task",
|
|
|
|
description="Number of frames to render per task. For progressive renders this is used "
|
|
|
|
"when the sample limit is reached -- before that more frames are used",
|
2017-01-30 10:38:35 +01:00
|
|
|
min=1,
|
2017-02-14 10:22:06 +01:00
|
|
|
default=1,
|
2017-01-13 17:24:37 +01:00
|
|
|
)
|
2019-01-30 14:16:30 +01:00
|
|
|
scene.flamenco_render_chunk_sample_cap = IntProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Maximum Samples per Task",
|
|
|
|
description="Maximum number of samples per render task; a lower number creates more "
|
|
|
|
"shorter-running tasks. Values between 1/10 and 1/4 of the total sample count "
|
|
|
|
"seem sensible",
|
2019-01-30 14:16:30 +01:00
|
|
|
min=1,
|
|
|
|
soft_min=5,
|
|
|
|
default=100,
|
|
|
|
soft_max=1000,
|
2017-01-30 10:38:35 +01:00
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
scene.flamenco_render_frame_range = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Frame Range",
|
2019-01-30 14:16:30 +01:00
|
|
|
description='Frames to render, in "printer range" notation',
|
2017-01-13 17:24:37 +01:00
|
|
|
)
|
2017-01-18 09:34:30 +01:00
|
|
|
scene.flamenco_render_job_type = EnumProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Job Type",
|
2017-01-18 09:34:30 +01:00
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("blender-render", "Simple Render", "Simple frame-by-frame render"),
|
|
|
|
(
|
|
|
|
"blender-render-progressive",
|
|
|
|
"Progressive Render",
|
|
|
|
"Each frame is rendered multiple times with different Cycles sample chunks, then combined",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"blender-video-chunks",
|
|
|
|
"Video Chunks",
|
|
|
|
"Render each frame chunk to a video file, then concateate those video files",
|
|
|
|
),
|
|
|
|
],
|
2017-01-18 09:34:30 +01:00
|
|
|
)
|
2017-01-30 10:38:35 +01:00
|
|
|
|
2018-07-12 11:54:13 +02:00
|
|
|
scene.flamenco_start_paused = BoolProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Start Paused",
|
2018-07-12 11:54:13 +02:00
|
|
|
description="When enabled, the job will be created in 'paused' state, rather than"
|
2021-02-16 11:21:06 +01:00
|
|
|
" 'queued'. The job will need manual queueing before it will start",
|
2018-07-12 11:54:13 +02:00
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
|
2017-01-18 09:34:30 +01:00
|
|
|
scene.flamenco_render_job_priority = IntProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Job Priority",
|
2019-03-01 14:36:41 +01:00
|
|
|
min=1,
|
2017-01-18 09:34:30 +01:00
|
|
|
default=50,
|
|
|
|
max=100,
|
2021-02-16 11:21:06 +01:00
|
|
|
description="Higher numbers mean higher priority",
|
2017-01-18 09:34:30 +01:00
|
|
|
)
|
|
|
|
|
2017-10-06 12:39:18 +02:00
|
|
|
scene.flamenco_do_override_output_path = BoolProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Override Output Path for this Job",
|
|
|
|
description="When enabled, allows you to specify a non-default Output path "
|
|
|
|
"for this particular job",
|
2017-10-06 12:39:18 +02:00
|
|
|
default=False,
|
2021-02-16 11:21:06 +01:00
|
|
|
update=flamenco_do_override_output_path_updated,
|
2017-10-06 12:39:18 +02:00
|
|
|
)
|
|
|
|
scene.flamenco_override_output_path = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Override Output Path",
|
|
|
|
description="Path where to store output files, should be accessible for Workers",
|
|
|
|
subtype="DIR_PATH",
|
|
|
|
default="",
|
|
|
|
)
|
2017-10-06 12:39:18 +02:00
|
|
|
|
2017-01-24 14:55:39 +01:00
|
|
|
bpy.types.WindowManager.flamenco_status = EnumProperty(
|
|
|
|
items=[
|
2021-02-16 11:21:06 +01:00
|
|
|
("IDLE", "IDLE", "Not doing anything."),
|
|
|
|
("SAVING", "SAVING", "Saving your file."),
|
|
|
|
("INVESTIGATING", "INVESTIGATING", "Finding all dependencies."),
|
|
|
|
("TRANSFERRING", "TRANSFERRING", "Transferring all dependencies."),
|
|
|
|
("COMMUNICATING", "COMMUNICATING", "Communicating with Flamenco Server."),
|
|
|
|
("DONE", "DONE", "Not doing anything, but doing something earlier."),
|
|
|
|
("ABORTING", "ABORTING", "User requested we stop doing something."),
|
|
|
|
("ABORTED", "ABORTED", "We stopped doing something."),
|
2017-01-24 14:55:39 +01:00
|
|
|
],
|
2021-02-16 11:21:06 +01:00
|
|
|
name="flamenco_status",
|
|
|
|
default="IDLE",
|
|
|
|
description="Current status of the Flamenco add-on",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2017-01-13 17:24:37 +01:00
|
|
|
|
2018-03-15 18:01:04 +01:00
|
|
|
bpy.types.WindowManager.flamenco_status_txt = StringProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Flamenco Status",
|
|
|
|
default="",
|
|
|
|
description="Textual description of what Flamenco is doing",
|
|
|
|
update=redraw,
|
|
|
|
)
|
2018-03-15 18:01:04 +01:00
|
|
|
|
|
|
|
bpy.types.WindowManager.flamenco_progress = IntProperty(
|
2021-02-16 11:21:06 +01:00
|
|
|
name="Flamenco Progress",
|
2018-03-15 18:01:04 +01:00
|
|
|
default=0,
|
2021-02-16 11:21:06 +01:00
|
|
|
description="File transfer progress",
|
|
|
|
subtype="PERCENTAGE",
|
2018-03-15 18:01:04 +01:00
|
|
|
min=0,
|
|
|
|
max=100,
|
2021-02-16 11:21:06 +01:00
|
|
|
update=redraw,
|
|
|
|
)
|
2018-03-15 18:01:04 +01:00
|
|
|
|
2017-01-24 15:15:08 +01:00
|
|
|
|
2017-01-13 17:24:37 +01:00
|
|
|
def unregister():
|
2017-03-17 15:08:09 +01:00
|
|
|
deactivate()
|
2018-09-04 14:56:10 +02:00
|
|
|
for cls in _rna_classes:
|
|
|
|
try:
|
|
|
|
bpy.utils.unregister_class(cls)
|
|
|
|
except RuntimeError:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.warning(
|
|
|
|
"Unable to unregister class %r, probably already unregistered", cls
|
|
|
|
)
|
|
|
|
|
|
|
|
for name in (
|
|
|
|
"flamenco_render_fchunk_size",
|
|
|
|
"flamenco_render_chunk_sample_cap",
|
|
|
|
"flamenco_render_frame_range",
|
|
|
|
"flamenco_render_job_type",
|
|
|
|
"flamenco_start_paused",
|
|
|
|
"flamenco_render_job_priority",
|
|
|
|
"flamenco_do_override_output_path",
|
|
|
|
"flamenco_override_output_path",
|
|
|
|
):
|
2018-07-12 11:54:01 +02:00
|
|
|
try:
|
|
|
|
delattr(bpy.types.Scene, name)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2017-01-24 14:55:39 +01:00
|
|
|
try:
|
|
|
|
del bpy.types.WindowManager.flamenco_status
|
|
|
|
except AttributeError:
|
|
|
|
pass
|