Move Anim_Setup module into Blender_Kitsu #5

Merged
Nick Alberelli merged 27 commits from :feature/merge_anim_setup_into_blender_kitsu into master 2023-04-05 17:38:41 +02:00
4 changed files with 51 additions and 40 deletions
Showing only changes of commit 2e58de49c2 - Show all commits

View File

@ -7,7 +7,6 @@ from blender_kitsu.shot_builder.builder.init_shot import InitShotStep
from blender_kitsu.shot_builder.builder.set_render_settings import SetRenderSettingsStep
from blender_kitsu.shot_builder.builder.new_scene import NewSceneStep
from blender_kitsu.shot_builder.builder.invoke_hook import InvokeHookStep
from blender_kitsu.shot_builder.builder.save_file import SaveFileStep
import bpy
@ -76,8 +75,6 @@ class ShotBuilder:
for hook in production.hooks.filter(match_task_type=task_type.name, match_asset_type=asset.asset_type):
self._steps.append(InvokeHookStep(hook))
self._steps.append(SaveFileStep())
def build(self) -> None:
num_steps = len(self._steps)
step_number = 1

View File

@ -5,7 +5,7 @@ from typing import Set
from blender_kitsu import prefs
from blender_kitsu import cache
def editorial_export_get_latest(context:bpy.types.Context) -> list[bpy.types.Sequence]:
def editorial_export_get_latest(context:bpy.types.Context, shot) -> list[bpy.types.Sequence]: #TODO add info to shot
"""Loads latest export from editorial department"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
@ -13,9 +13,8 @@ def editorial_export_get_latest(context:bpy.types.Context) -> list[bpy.types.Seq
latest_file = editorial_export_check_latest(context)
if not latest_file:
return None
shot = cache.shot_active_get()
# Check if Kitsu server returned empty shot
if shot.id == '':
if shot.get("id") == '':
return None
strip_filepath = latest_file.as_posix()
strip_frame_start = addon_prefs.shot_builder_frame_offset
@ -40,8 +39,8 @@ def editorial_export_get_latest(context:bpy.types.Context) -> list[bpy.types.Seq
new_strips = [movie_strip, sound_strip]
# Update shift frame range prop.
frame_in = shot.frame_in
frame_3d_in = shot.data["3d_in"]
frame_in = shot["data"].get("frame_in")
frame_3d_in = shot["data"].get("3d_in")
frame_3d_offset = frame_3d_in - addon_prefs.shot_builder_frame_offset
# Set sequence strip start kitsu data.

View File

@ -1,6 +1,7 @@
import bpy
from typing import Set
from blender_kitsu.shot_builder.editorial.core import editorial_export_get_latest
from blender_kitsu import cache, gazu
class ANIM_SETUP_OT_load_latest_editorial(bpy.types.Operator):
bl_idname = "asset_setup.load_latest_editorial"
@ -11,7 +12,9 @@ class ANIM_SETUP_OT_load_latest_editorial(bpy.types.Operator):
)
def execute(self, context: bpy.types.Context) -> Set[str]:
strips = editorial_export_get_latest(self, context)
cache_shot = cache.shot_active_get()
shot = gazu.shot.get_shot(cache_shot.id)
strips = editorial_export_get_latest(context, shot)
if strips is None:
self.report(
{"ERROR"}, f"No valid editorial export in editorial export path."

View File

@ -17,13 +17,14 @@
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import pathlib
from typing import *
import bpy
from blender_kitsu.shot_builder.shot import ShotRef
from blender_kitsu.shot_builder.project import ensure_loaded_production, get_active_production
from blender_kitsu.shot_builder.builder import ShotBuilder
from blender_kitsu.shot_builder.task_type import TaskType
from blender_kitsu import prefs, cache
from blender_kitsu import prefs, cache, gazu
from blender_kitsu.shot_builder.anim_setup.core import animation_workspace_delete_others, animation_workspace_vse_area_add
from blender_kitsu.shot_builder.editorial.core import editorial_export_get_latest
@ -79,6 +80,7 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
_timer = None
_built_shot = False
_add_vse_area = False
_file_path = ''
production_root: bpy.props.StringProperty( # type: ignore
name="Production Root",
@ -121,6 +123,9 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
self._add_vse_area = True
if self._built_shot and self._add_vse_area:
file_path = pathlib.Path(self._file_path)
file_path.mkdir(parents=True, exist_ok=True)
bpy.ops.wm.save_mainfile(filepath=self._file_path, relative_remap=True)
self.report({"INFO"}, f"Created Shot {self.shot_id}")
return {'FINISHED'}
@ -177,11 +182,12 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
wm = context.window_manager
self._timer = wm.event_timer_add(0.1, window=context.window)
wm.modal_handler_add(self)
if not self._built_shot:
if not self.production_root:
self.report(
{'ERROR'}, "Shot builder can only be started from the File menu. Shortcuts like CTRL-N don't work")
return {'CANCELLED'}
if self._built_shot:
return {'RUNNING_MODAL'}
addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences
ensure_loaded_production(context)
production = get_active_production()
@ -189,23 +195,29 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
context=context, production=production, shot_name=self.shot_id, task_type=TaskType(self.task_type))
shot_builder.create_build_steps()
shot_builder.build()
# Build Kitsu Context
sequence = gazu.shot.get_sequence_by_name(production.config['KITSU_PROJECT_ID'], self.seq_id)
shot = gazu.shot.get_shot_by_name(sequence, self.shot_id)
#Load EDIT
bpy.ops.kitsu.con_detect_context() #TODO CONFIRM AND CHECK IF OVERRIDE IS NEEDED
editorial_export_get_latest(context)
editorial_export_get_latest(context, shot)
# Load Anim Workspace
animation_workspace_delete_others()
shot = cache.shot_active_get()
# Initilize armatures
for obj in [obj for obj in bpy.data.objects if obj.type == "ARMATURE"]:
base_name = obj.name.split(addon_prefs.shot_builder_armature_prefix)[-1]
new_action = bpy.data.actions.new(f"{addon_prefs.shot_builder_action_prefix}{base_name}.{shot.name}.v001")
new_action = bpy.data.actions.new(f"{addon_prefs.shot_builder_action_prefix}{base_name}.{self.shot_id}.v001")
new_action.use_fake_user = True
obj.animation_data.action = new_action
# Set Shot Frame Range
frame_length = shot.get('nb_frames')
context.scene.frame_start = addon_prefs.shot_builder_frame_offset
context.scene.frame_end = shot.nb_frames + addon_prefs.shot_builder_frame_offset
context.scene.frame_end = frame_length + addon_prefs.shot_builder_frame_offset
self._file_path = shot_builder.build_context.shot.file_path
self._built_shot = True
return {'RUNNING_MODAL'}