Blender Kitsu: Add Operator to Push Frame Start #98

Merged
Nick Alberelli merged 6 commits from feature/3d-offset-kitsu into main 2023-06-27 15:35:00 +02:00
2 changed files with 40 additions and 6 deletions
Showing only changes of commit 3dd57246d0 - Show all commits

View File

@ -65,6 +65,7 @@ class KITSU_PT_vi3d_anim_tools(bpy.types.Panel):
"kitsu.pull_frame_range",
icon="FILE_REFRESH",
)
row.operator("kitsu.push_frame_range", icon="EMPTY_SINGLE_ARROW", text="")
# Update output collection.
row = box.row(align=True)

View File

@ -25,6 +25,9 @@ from typing import Dict, List, Set, Optional, Tuple, Any
import bpy
from bpy.app.handlers import persistent
from blender_kitsu import bkglobals
from blender_kitsu.types import Shot
from blender_kitsu import (
cache,
util,
@ -340,6 +343,37 @@ class KITSU_OT_playblast_set_version(bpy.types.Operator):
return {"FINISHED"}
class KITSU_OT_push_frame_range(bpy.types.Operator):
bl_idname = "kitsu.push_frame_range"
bl_label = "Push Frame Range Offset"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Adjusts the start frame to set it outside of the global value set for productionPush metadata via 3d_offset."
_shot = None
kitsu_offset: bpy.props.IntProperty(name="Frame Range Offset", default=0)
def draw(self, context: bpy.types.Context) -> None:
layout = self.layout
col = layout.column(align=True)
col.label(text="Choose an offset value for this animation file's frame range.")
col.label(
text="This will affect the results of 'Update Frame Range'", icon="ERROR"
)
col.prop(self, "kitsu_offset")
def execute(self, context: bpy.types.Context) -> Set[str]:
shot = cache.shot_active_pull_update()
shot.data["3d_offset"] = self.kitsu_offset
shot.update()
self.report({"INFO"}, f"Updated frame range offset {shot.data['3d_offset']}")
return {"FINISHED"}
def invoke(self, context: bpy.types.Context, event: bpy.types.Event) -> Set[str]:
self.kitsu_offset = context.scene.frame_start - bkglobals.FRAME_START
return context.window_manager.invoke_props_dialog(self, width=500)
class KITSU_OT_pull_frame_range(bpy.types.Operator):
bl_idname = "kitsu.pull_frame_range"
bl_label = "Update Frame Range"
@ -363,8 +397,8 @@ class KITSU_OT_pull_frame_range(bpy.types.Operator):
)
return {"CANCELLED"}
frame_in = int(active_shot.data["3d_in"])
frame_out = int(active_shot.data["3d_out"])
frame_in = int(active_shot.data["3d_in"]) + int(active_shot.data["3d_offset"])
frame_out = int(active_shot.data["3d_out"]) + int(active_shot.data["3d_offset"])
# Check if current frame range matches the one for active shot.
if (
@ -434,10 +468,8 @@ def load_post_handler_check_frame_range(dummy: Any) -> None:
active_shot.name,
)
return
frame_in = int(active_shot.data["3d_in"])
frame_out = int(active_shot.data["3d_out"])
frame_in = int(active_shot.data["3d_in"]) + int(active_shot.data["3d_offset"])
frame_out = int(active_shot.data["3d_out"]) + int(active_shot.data["3d_offset"])
if (
frame_in == bpy.context.scene.frame_start
and frame_out == bpy.context.scene.frame_end
@ -478,6 +510,7 @@ classes = [
KITSU_OT_playblast_set_version,
KITSU_OT_playblast_increment_playblast_version,
KITSU_OT_pull_frame_range,
KITSU_OT_push_frame_range,
]