Blender Kitsu: Refactor Shot Builder #183

Merged
Nick Alberelli merged 55 commits from TinyNick/blender-studio-pipeline:feature/shot-builder-2 into main 2023-12-21 23:58:21 +01:00
4 changed files with 37 additions and 34 deletions
Showing only changes of commit 2242b9a251 - Show all commits

View File

@ -169,7 +169,7 @@ def create_task_type_output_collection(
scene: bpy.types.Scene, shot: Shot, task_type: TaskType
) -> bpy.types.Collection:
collections = bpy.data.collections
output_col_name = shot.get_output_collection_name(task_type)
output_col_name = shot.get_output_collection_name(task_type.get_short_name())
if not collections.get(output_col_name):
bpy.data.collections.new(name=output_col_name)
@ -187,14 +187,16 @@ def create_task_type_output_collection(
return output_collection
def link_task_type_output_collections(shot: Shot, task_short_name: str):
# TODO TEST IF THIS WORKS
if bkglobals.OUTPUT_COL_LINK_MAPPING.get(task_short_name) == None:
def link_task_type_output_collections(shot: Shot, task_type: TaskType):
task_type_short_name = task_type.get_short_name()
if bkglobals.OUTPUT_COL_LINK_MAPPING.get(task_type_short_name) == None:
return
for short_name in bkglobals.OUTPUT_COL_LINK_MAPPING.get(task_short_name):
for short_name in bkglobals.OUTPUT_COL_LINK_MAPPING.get(task_type_short_name):
external_filepath = shot.get_shot_filepath(bpy.context, short_name)
if not external_filepath.exists():
print(f"Unable to link output collection for {external_filepath.name}")
if not Path(external_filepath).exists():
print(
f"Unable to link output collection for {Path(external_filepath).name}"
)
file_path = external_filepath.__str__()
colection_name = shot.get_shot_task_name(short_name)
link_data_block(file_path, colection_name)
colection_name = shot.get_output_collection_name(short_name)
link_data_block(file_path, colection_name, 'Collection')

View File

@ -201,14 +201,14 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
seq = active_project.get_sequence(self.seq_id)
shot = active_project.get_shot(self.shot_id)
task_type = self._get_task_type_for_shot(context, shot)
task_short_name = task_type.get_short_name()
shot_file_path_str = shot.get_shot_filepath(context, task_type)
task_type_short_name = task_type.get_short_name()
shot_file_path_str = shot.get_shot_filepath(context, task_type_short_name)
# Open Template File
replace_workspace_with_template(context, task_short_name)
replace_workspace_with_template(context, task_type_short_name)
# Set Up Scene + Naming
shot_task_name = shot.get_shot_task_name(task_type)
shot_task_name = shot.get_shot_task_name(task_type.get_short_name())
scene = set_shot_scene(context, shot_task_name)
remove_all_data()
set_resolution_and_fps(active_project, scene)
@ -218,33 +218,33 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
# TODO Only run if saving file
# Set Render Settings
if task_short_name == 'anim': # TODO get anim from a constant instead
if task_type_short_name == 'anim': # TODO get anim from a constant instead
set_render_engine(context.scene, 'BLENDER_WORKBENCH')
else:
set_render_engine(context.scene)
# Create Output Collection & Link Camera
if bkglobals.OUTPUT_COL_CREATE.get(task_short_name):
if bkglobals.OUTPUT_COL_CREATE.get(task_type_short_name):
output_col = create_task_type_output_collection( # TODO imporve
context.scene, shot, task_type
)
if task_short_name == 'anim':
if task_type_short_name == 'anim':
link_camera_rig(context.scene, output_col)
# Load Assets
get_shot_assets(scene=scene, output_collection=output_col, shot=shot)
# Link External Output Collections
link_task_type_output_collections(shot, task_short_name)
link_task_type_output_collections(shot, task_type)
if bkglobals.LOAD_EDITORIAL_REF.get(task_short_name):
if bkglobals.LOAD_EDITORIAL_REF.get(task_type_short_name):
editorial_export_get_latest(context, shot)
# Run Hooks
hooks_instance = Hooks()
hooks_instance.load_hooks(context)
hooks_instance.execute_hooks(
match_task_type=task_short_name,
match_task_type=task_type_short_name,
scene=context.scene,
shot=shot,
prod_path=prefs.project_root_dir_get(context),

View File

@ -13,23 +13,25 @@ def get_template_files() -> list[Path]:
return list(dir.glob('*.blend'))
def get_template_for_task_type(task_short_name: str) -> Path:
def get_template_for_task_type(task_type_short_name: str) -> Path:
for file in get_template_files():
if file.stem == task_short_name:
if file.stem == task_type_short_name:
return file
def open_template_for_task_type(task_short_name: str) -> bool:
def open_template_for_task_type(task_type_short_name: str) -> bool:
# TODO THIS DOESN'T WORK BECAUSE CHANGE THE OPEN FILE MESSES UP THE CONTEXT SOMEHOW
file_path = get_template_for_task_type(task_short_name)
file_path = get_template_for_task_type(task_type_short_name)
if file_path.exists() and file_path is not None:
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=file_path.__str__())
return True
return False
def replace_workspace_with_template(context: bpy.types.Context, task_short_name: str):
file_path = get_template_for_task_type(task_short_name).resolve().absolute()
def replace_workspace_with_template(
context: bpy.types.Context, task_type_short_name: str
):
file_path = get_template_for_task_type(task_type_short_name).resolve().absolute()
remove_prefix = "REMOVE-"
if not file_path.exists():
return

View File

@ -572,11 +572,11 @@ class Shot(Entity):
gazu.shot.update_shot(asdict(self))
return self
def get_shot_task_name(self, task_type: TaskType) -> str: #
return f"{self.name}{bkglobals.FILE_DELIMITER}{task_type.get_short_name()}"
def get_shot_task_name(self, task_type_short_name: str) -> str: #
return f"{self.name}{bkglobals.FILE_DELIMITER}{task_type_short_name}"
def get_output_collection_name(self, task_type: TaskType) -> str:
return f"{self.get_shot_task_name(task_type)}{bkglobals.FILE_DELIMITER}output"
def get_output_collection_name(self, task_type_short_name: str) -> str:
return f"{self.get_shot_task_name(task_type_short_name)}{bkglobals.FILE_DELIMITER}output"
def get_shot_dir(self, context) -> str:
project_root_dir = prefs.project_root_dir_get(context)
@ -585,9 +585,8 @@ class Shot(Entity):
shot_dir = all_shots_dir.joinpath(seq.name).joinpath(self.name)
return shot_dir.__str__()
def get_shot_filepath(self, context, task_type: TaskType) -> str:
shot_task_name = self.get_shot_task_name(task_type)
file_name = shot_task_name + '.blend'
def get_shot_filepath(self, context, task_type_short_name: str) -> str:
file_name = self.get_shot_task_name(task_type_short_name) + '.blend'
return Path(self.get_shot_dir(context)).joinpath(file_name).__str__()
def update_data(self, data: Dict[str, Any]) -> Shot: