Move Anim_Setup
module into Blender_Kitsu
#5
@ -1,6 +1,13 @@
|
|||||||
import bpy
|
import bpy
|
||||||
|
from bpy import context
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
from typing import Set
|
from typing import Set
|
||||||
from blender_kitsu import prefs
|
from blender_kitsu import prefs
|
||||||
|
from blender_kitsu import cache
|
||||||
|
from blender_kitsu import gazu
|
||||||
|
|
||||||
|
|
||||||
class ANIM_SETUP_OT_setup_workspaces(bpy.types.Operator):
|
class ANIM_SETUP_OT_setup_workspaces(bpy.types.Operator):
|
||||||
bl_idname = "anim_setup.setup_workspaces"
|
bl_idname = "anim_setup.setup_workspaces"
|
||||||
bl_label = "Setup Workspace"
|
bl_label = "Setup Workspace"
|
||||||
@ -13,3 +20,108 @@ class ANIM_SETUP_OT_setup_workspaces(bpy.types.Operator):
|
|||||||
bpy.ops.workspace.delete({"workspace": ws})
|
bpy.ops.workspace.delete({"workspace": ws})
|
||||||
self.report({"INFO"}, "Deleted non Animation workspaces")
|
self.report({"INFO"}, "Deleted non Animation workspaces")
|
||||||
return {"FINISHED"}
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context: bpy.types.Context) -> bool:
|
||||||
|
return cls.can_load_edit(context)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def description(cls, context, properties):
|
||||||
|
if cls.can_load_edit(context):
|
||||||
|
return "Load latest edit from shared folder"
|
||||||
|
else:
|
||||||
|
return "Shared folder not set, or VSE area not available in this workspace"
|
||||||
|
|
||||||
|
def execute(self, context: bpy.types.Context) -> Set[str]:
|
||||||
|
addon_prefs = prefs.addon_prefs_get(context)
|
||||||
|
edit_export_path = Path(addon_prefs.edit_export_dir)
|
||||||
|
strip_channel = 1
|
||||||
|
latest_file = self._get_latest_edit(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 = 101
|
||||||
|
|
||||||
|
# Needs to be run in sequence editor area.
|
||||||
|
# area_override = None
|
||||||
|
scene = context.scene
|
||||||
|
if not scene.sequence_editor:
|
||||||
|
scene.sequence_editor_create()
|
||||||
|
seq_editor = scene.sequence_editor
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
bpy.ops.kitsu.con_detect_context()
|
||||||
|
shot = cache.shot_active_get()
|
||||||
|
|
||||||
|
|
||||||
|
# Update shift frame range prop.
|
||||||
|
frame_in = shot.frame_in
|
||||||
|
frame_3d_offset = 101
|
||||||
|
|
||||||
|
# Set sequence strip start kitsu data.
|
||||||
|
for strip in scene.sequence_editor.sequences_all:
|
||||||
|
strip.frame_start = -(frame_in) + frame_3d_offset #TODO CONFIRM LOGIC HERE
|
||||||
|
|
||||||
|
self.report({"INFO"}, f"Loaded latest edit: {latest_file.name}")
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def _get_latest_edit(self, context: bpy.types.Context):
|
||||||
|
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 self._is_valid_edit_name(f.name)
|
||||||
|
]
|
||||||
|
files_list = sorted(files_list, reverse=True)
|
||||||
|
|
||||||
|
return files_list[0]
|
||||||
|
|
||||||
|
def _is_valid_edit_name(self, filename: str) -> bool:
|
||||||
|
pattern = r"petprojects_v\d\d\d.mp4"
|
||||||
|
|
||||||
|
match = re.search(pattern, filename)
|
||||||
|
if match:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
ANIM_SETUP_OT_setup_workspaces,
|
||||||
|
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)
|
@ -294,6 +294,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences):
|
|||||||
subtype='DIR_PATH',
|
subtype='DIR_PATH',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
edit_export_dir: bpy.props.StringProperty( # type: ignore
|
||||||
|
name="Edit Export Directory",
|
||||||
|
options={"HIDDEN", "SKIP_SAVE"},
|
||||||
|
subtype="DIR_PATH",
|
||||||
|
# TODO ADD DEFAULT
|
||||||
|
# TODO ADD TO KITSU PREFRENCES UI
|
||||||
|
)
|
||||||
session: Session = Session()
|
session: Session = Session()
|
||||||
|
|
||||||
tasks: bpy.props.CollectionProperty(type=KITSU_task)
|
tasks: bpy.props.CollectionProperty(type=KITSU_task)
|
||||||
|
@ -157,7 +157,8 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
|
|||||||
context=context, production=production, shot_name=self.shot_id, task_type=TaskType(self.task_type))
|
context=context, production=production, shot_name=self.shot_id, task_type=TaskType(self.task_type))
|
||||||
shot_builder.create_build_steps()
|
shot_builder.create_build_steps()
|
||||||
shot_builder.build()
|
shot_builder.build()
|
||||||
|
#Load EDIT
|
||||||
|
bpy.ops.asset_setup.load_latest_edit()
|
||||||
# Load Anim Workspace
|
# Load Anim Workspace
|
||||||
bpy.ops.anim_setup.setup_workspaces()
|
bpy.ops.anim_setup.setup_workspaces()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
Loading…
Reference in New Issue
Block a user