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
8 changed files with 148 additions and 89 deletions
Showing only changes of commit f1f815a648 - Show all commits

View File

@ -40,7 +40,7 @@ from blender_kitsu.auth.ops import (
)
from blender_kitsu.context.ops import KITSU_OT_con_productions_load
from blender_kitsu.lookdev.prefs import LOOKDEV_preferences
from blender_kitsu.shot_builder.anim_setup.core import editorial_export_check_latest
from blender_kitsu.shot_builder.editorial.core import editorial_export_check_latest
logger = LoggerFactory.getLogger()

View File

@ -22,7 +22,8 @@ from blender_kitsu.shot_builder.ui import *
from blender_kitsu.shot_builder.connectors.kitsu import *
from blender_kitsu.shot_builder.operators import *
import bpy
from blender_kitsu.shot_builder.anim_setup import ops #TODO Fix Registraion
from blender_kitsu.shot_builder.anim_setup import ops as anim_setup_ops #TODO Fix Registraion
from blender_kitsu.shot_builder.editorial import ops as editorial_ops #TODO Fix Registraion
# import logging
# logging.basicConfig(level=logging.DEBUG)
@ -46,14 +47,18 @@ classes = (
def register():
anim_setup_ops.register()
editorial_ops.register()
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_new.append(topbar_file_new_draw_handler)
ops.register()
def unregister():
anim_setup_ops.unregister()
editorial_ops.unregister()
bpy.types.TOPBAR_MT_file_new.remove(topbar_file_new_draw_handler)
for cls in classes:
bpy.utils.unregister_class(cls)
ops.unregister()

View File

@ -18,7 +18,6 @@ def animation_workspace_vse_area_add(self, context:bpy.types.Context):
bpy.ops.screen.area_split(direction='HORIZONTAL', factor=0.5)
small_view_3d.ui_type = "SEQUENCE_EDITOR"
small_view_3d.spaces[0].view_type = "PREVIEW"
print(f"splitting viewpoert in workspace {context.workspace.name}") #USING THIS TO DEBUG
def animation_workspace_delete_others(self, context:bpy.types.Context):
"""Delete any workspace that is not an animation workspace"""
@ -27,72 +26,4 @@ def animation_workspace_delete_others(self, context:bpy.types.Context):
bpy.ops.workspace.delete({"workspace": ws})
self.report({"INFO"}, "Deleted non Animation workspaces")
def editorial_export_get_latest(self, context:bpy.types.Context):
"""Loads latest export from editorial department"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
strip_channel = 1
latest_file = editorial_export_check_latest(context)
if not latest_file:
self.report(
{"ERROR"}, f"Found no edit file in: {edit_export_path.as_posix()}"
)
strip_filepath = latest_file.as_posix()
strip_frame_start = addon_prefs.shot_builder_frame_offset
scene = context.scene
if not scene.sequence_editor:
scene.sequence_editor_create()
seq_editor = scene.sequence_editor
movie_strip = seq_editor.sequences.new_movie(
strip_filepath,
strip_filepath,
strip_channel + 1,
strip_frame_start,
fit_method="FIT",
)
sound_strip = seq_editor.sequences.new_sound(
strip_filepath,
strip_filepath,
strip_channel,
strip_frame_start,
)
shot = cache.shot_active_get()
# Update shift frame range prop.
frame_in = shot.frame_in
frame_3d_in = shot.data["3d_in"]
frame_3d_offset = frame_3d_in - addon_prefs.shot_builder_frame_offset
# Set sequence strip start kitsu data.
for strip in scene.sequence_editor.sequences_all:
strip.frame_start = -frame_in + (strip_frame_start * 2) + frame_3d_offset
self.report({"INFO"}, f"Loaded latest edit: {latest_file.name}")
def editorial_export_check_latest(context: bpy.types.Context):
"""Find latest export in editorial export directory"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
files_list = [
f
for f in edit_export_path.iterdir()
if f.is_file() and editorial_export_is_valid_edit_name(addon_prefs.edit_export_file_pattern, f.name)
]
if len(files_list) >= 1:
files_list = sorted(files_list, reverse=True)
return files_list[0]
return None
def editorial_export_is_valid_edit_name(file_pattern:str, filename: str) -> bool:
"""Verify file name matches file pattern set in preferences"""
match = re.search(file_pattern, filename)
if match:
return True
return False

View File

@ -1,8 +1,7 @@
import bpy
from typing import Set
from blender_kitsu.shot_builder.anim_setup.core import editorial_export_get_latest, animation_workspace_delete_others, animation_workspace_vse_area_add
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
class ANIM_SETUP_OT_setup_workspaces(bpy.types.Operator):
bl_idname = "anim_setup.setup_workspaces"
bl_label = "Setup Workspace"
@ -21,21 +20,10 @@ class ANIM_SETUP_OT_animation_workspace_vse_area_add(bpy.types.Operator):
animation_workspace_vse_area_add(self, context)
return {"FINISHED"}
class ANIM_SETUP_OT_load_latest_edit(bpy.types.Operator):
bl_idname = "asset_setup.load_latest_edit"
bl_label = "Load edit"
bl_description = (
"Loads latest edit from shot_preview_folder "
"Shifts edit so current shot starts at 3d_in metadata shot key from Kitsu"
)
def execute(self, context: bpy.types.Context) -> Set[str]:
editorial_export_get_latest(self, context)
return {"FINISHED"}
#
classes = [
ANIM_SETUP_OT_setup_workspaces,
ANIM_SETUP_OT_load_latest_edit,
ANIM_SETUP_OT_animation_workspace_vse_area_add
]

View File

@ -0,0 +1,30 @@
# ##### 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 #####
# <pep8 compliant>
import bpy
from blender_kitsu.shot_builder.editorial import ops
def register():
ops.register()
def unregister():
ops.unregister()

View File

@ -0,0 +1,75 @@
import bpy
import re
from pathlib import Path
from typing import Set
from blender_kitsu import prefs
from blender_kitsu import cache
def editorial_export_get_latest(self, context:bpy.types.Context):
"""Loads latest export from editorial department"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
strip_channel = 1
latest_file = editorial_export_check_latest(context)
if not latest_file:
self.report(
{"ERROR"}, f"Found no edit file in: {edit_export_path.as_posix()}"
)
strip_filepath = latest_file.as_posix()
strip_frame_start = addon_prefs.shot_builder_frame_offset
scene = context.scene
if not scene.sequence_editor:
scene.sequence_editor_create()
seq_editor = scene.sequence_editor
movie_strip = seq_editor.sequences.new_movie(
strip_filepath,
strip_filepath,
strip_channel + 1,
strip_frame_start,
fit_method="FIT",
)
sound_strip = seq_editor.sequences.new_sound(
strip_filepath,
strip_filepath,
strip_channel,
strip_frame_start,
)
shot = cache.shot_active_get()
# Update shift frame range prop.
frame_in = shot.frame_in
frame_3d_in = shot.data["3d_in"]
frame_3d_offset = frame_3d_in - addon_prefs.shot_builder_frame_offset
# Set sequence strip start kitsu data.
for strip in scene.sequence_editor.sequences_all:
strip.frame_start = -frame_in + (strip_frame_start * 2) + frame_3d_offset
self.report({"INFO"}, f"Loaded latest edit: {latest_file.name}")
def editorial_export_check_latest(context: bpy.types.Context):
"""Find latest export in editorial export directory"""
addon_prefs = prefs.addon_prefs_get(context)
edit_export_path = Path(addon_prefs.edit_export_dir)
files_list = [
f
for f in edit_export_path.iterdir()
if f.is_file() and editorial_export_is_valid_edit_name(addon_prefs.edit_export_file_pattern, f.name)
]
if len(files_list) >= 1:
files_list = sorted(files_list, reverse=True)
return files_list[0]
return None
def editorial_export_is_valid_edit_name(file_pattern:str, filename: str) -> bool:
"""Verify file name matches file pattern set in preferences"""
match = re.search(file_pattern, filename)
if match:
return True
return False

View File

@ -0,0 +1,28 @@
import bpy
from typing import Set
from blender_kitsu.shot_builder.editorial.core import editorial_export_get_latest
class ANIM_SETUP_OT_load_latest_edit(bpy.types.Operator):
bl_idname = "asset_setup.load_latest_edit"
bl_label = "Load edit"
bl_description = (
"Loads latest edit from shot_preview_folder "
"Shifts edit so current shot starts at 3d_in metadata shot key from Kitsu"
)
def execute(self, context: bpy.types.Context) -> Set[str]:
editorial_export_get_latest(self, context)
return {"FINISHED"}
classes = [
ANIM_SETUP_OT_load_latest_edit,
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)

View File

@ -24,7 +24,9 @@ from blender_kitsu.shot_builder.project import ensure_loaded_production, get_act
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.shot_builder.anim_setup.core import editorial_export_get_latest, animation_workspace_delete_others, animation_workspace_vse_area_add
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
_production_task_type_items: List[Tuple[str, str, str]] = []