Refactor and Copy Paste Casting
This commit is contained in:
+167
-88
@@ -2,6 +2,7 @@
|
||||
|
||||
import bpy
|
||||
import importlib
|
||||
import json
|
||||
import re
|
||||
import vse_toolbox
|
||||
|
||||
@@ -18,8 +19,8 @@ from bpy.types import (
|
||||
)
|
||||
from pathlib import Path
|
||||
from vse_toolbox.constants import (
|
||||
ASSETS,
|
||||
ASSET_PREVIEWS,
|
||||
CASTING_BUFFER,
|
||||
CONFIG_DIR,
|
||||
EDITS,
|
||||
EDIT_SUFFIXES,
|
||||
@@ -41,7 +42,7 @@ from vse_toolbox.sequencer_utils import (
|
||||
render_strips,
|
||||
set_channels,
|
||||
)
|
||||
from vse_toolbox.bl_utils import get_addon_prefs, get_settings
|
||||
from vse_toolbox.bl_utils import get_addon_prefs, get_scene_settings, get_strip_settings
|
||||
from vse_toolbox.file_utils import install_module, norm_name, norm_str
|
||||
|
||||
class VSETB_OT_export_csv(Operator):
|
||||
@@ -166,7 +167,7 @@ class VSETB_OT_import_files(Operator):
|
||||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
@@ -257,57 +258,45 @@ class VSETB_OT_load_assets(Operator):
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
if settings.active_project:
|
||||
return True
|
||||
|
||||
def get_items(self, items=[]):
|
||||
if not items:
|
||||
return [('NONE', 'None', '', 0)]
|
||||
|
||||
icons = {
|
||||
'camera':'CAMERA_DATA',
|
||||
'chars':'COMMUNITY',
|
||||
'props':'OBJECT_DATAMODE',
|
||||
'sets':'SMOOTHCURVE',
|
||||
}
|
||||
#TODO Mettre la preview dans le popup search
|
||||
return [(e.norm_name, e.norm_name.title(), '', icons[e.asset_type], i) for i, e in enumerate(items)]
|
||||
# return [(e.norm_name, e.norm_name.title(), '', ASSET_PREVIEWS[e.preview].icon_id, i) for i, e in enumerate(items)]
|
||||
|
||||
def execute(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
ASSETS.clear()
|
||||
settings.active_project.assets.clear()
|
||||
|
||||
tracker.connect()
|
||||
project = settings.active_project
|
||||
project.assets.clear()
|
||||
|
||||
assets = tracker.get_assets(project['id'])
|
||||
if not assets:
|
||||
self.report({'ERROR'}, f'No Assets found for {project.name}.')
|
||||
|
||||
for asset_data in assets:
|
||||
for asset_data in assets:
|
||||
asset = project.assets.add()
|
||||
|
||||
asset.name = asset_data['id']
|
||||
asset.norm_name = norm_name(asset_data['name'], separator=' ', format=str.lower)
|
||||
asset.name = asset.norm_name
|
||||
|
||||
asset.tracker_name = asset_data['name']
|
||||
|
||||
asset.id = asset_data['id']
|
||||
asset.asset_type = asset_data['asset_type']
|
||||
|
||||
asset.nombss = asset_data['data'].get('nombss', '')
|
||||
|
||||
datas = asset_data.get('data', {})
|
||||
for key, values in datas.items():
|
||||
asset[key] = values
|
||||
|
||||
preview_id = asset_data.get('preview_file_id')
|
||||
if preview_id:
|
||||
asset.preview = preview_id
|
||||
preview_path = Path(PREVIEWS_DIR / project.name.lower() / preview_id).with_suffix('.png')
|
||||
preview_path = Path(PREVIEWS_DIR / project.id / preview_id).with_suffix('.png')
|
||||
tracker.download_preview(preview_id, preview_path)
|
||||
|
||||
ASSET_PREVIEWS.load(preview_id, preview_path.as_posix(), 'IMAGE')
|
||||
|
||||
ASSETS.extend(self.get_items(items=project.assets))
|
||||
|
||||
self.report({'INFO'}, f'Assets for {project.name} successfully loaded')
|
||||
return {"FINISHED"}
|
||||
@@ -324,7 +313,7 @@ class VSETB_OT_load_projects(Operator):
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
@@ -340,12 +329,6 @@ class VSETB_OT_load_projects(Operator):
|
||||
episode = project.episodes.add()
|
||||
episode.name = episode_data['name']
|
||||
episode.id = episode_data['id']
|
||||
|
||||
# for asset_data in tracker.get_assets(project_data):
|
||||
# asset = project.assets.add()
|
||||
# asset.name = asset_data['name']
|
||||
# asset.id = asset_data['id']
|
||||
# asset.asset_type = asset_data['asset_type']
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
@@ -364,12 +347,12 @@ class VSETB_OT_new_episode(Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
prefs = get_addon_prefs()
|
||||
tracker = prefs.tracker
|
||||
|
||||
@@ -430,13 +413,13 @@ class VSETB_OT_rename(Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
@@ -474,13 +457,13 @@ class VSETB_OT_render(Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
@@ -491,7 +474,7 @@ class VSETB_OT_render(Operator):
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
settings = get_scene_settings()
|
||||
strips = get_strips(channel=settings.channel, selected_only=self.selected_only)
|
||||
|
||||
render_strips(strips)
|
||||
@@ -526,6 +509,12 @@ class VSETB_OT_set_scene(Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
def get_asset_items(self, context):
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
|
||||
return [(a.id, a.label, '', i) for i, a in enumerate(project.assets)]
|
||||
|
||||
class VSETB_OT_casting_add(Operator):
|
||||
bl_idname = "vse_toolbox.casting_add"
|
||||
bl_label = "Casting Add"
|
||||
@@ -533,40 +522,81 @@ class VSETB_OT_casting_add(Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_property = "asset_name"
|
||||
|
||||
asset_name : EnumProperty(name='', items=lambda s, c: ASSETS)
|
||||
|
||||
asset_name : EnumProperty(name='', items=get_asset_items)
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
if active_strip:
|
||||
return True
|
||||
|
||||
|
||||
def invoke(self, context, event):
|
||||
context.window_manager.invoke_search_popup(self)
|
||||
return {"FINISHED"}
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
settings = get_settings()
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
|
||||
settings = get_scene_settings()
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
project = settings.active_project
|
||||
|
||||
if active_strip.casting.get(self.asset_name):
|
||||
self.report({'WARNING'}, f"Asset {self.asset_name} already casted.")
|
||||
if strip_settings.casting.get(self.asset_name):
|
||||
asset = project.assets[self.asset_name]
|
||||
self.report({'WARNING'}, f"Asset {asset.label} already casted.")
|
||||
return {"CANCELLED"}
|
||||
|
||||
item = active_strip.casting.add()
|
||||
item.name = self.asset_name
|
||||
for k, v in project.assets[self.asset_name].items():
|
||||
setattr(item, k, v)
|
||||
item = strip_settings.casting.add()
|
||||
asset = project.assets[self.asset_name]
|
||||
|
||||
active_strip.casting.update()
|
||||
item.name = asset.name
|
||||
item.id = project.assets[self.asset_name].id
|
||||
|
||||
strip_settings.casting.update()
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_casting_actions(Operator):
|
||||
bl_idname = "vse_toolbox.casting_actions"
|
||||
class VSETB_OT_casting_remove(Operator):
|
||||
bl_idname = "vse_toolbox.casting_remove"
|
||||
bl_label = "Remove Item from Casting"
|
||||
bl_description = "Remove Item from Casting"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
if active_strip:
|
||||
return True
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
|
||||
strip_settings = get_strip_settings()
|
||||
idx = strip_settings.casting_index
|
||||
|
||||
try:
|
||||
item = strip_settings.casting[idx]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
item = strip_settings.casting[strip_settings.casting_index]
|
||||
info = f"Item {item.asset.label} removed from casting"
|
||||
strip_settings.casting.remove(idx)
|
||||
|
||||
if strip_settings.casting_index == 0:
|
||||
strip_settings.casting_index = 0
|
||||
else:
|
||||
strip_settings.casting_index -= 1
|
||||
|
||||
self.report({'INFO'}, info)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_casting_move(Operator):
|
||||
bl_idname = "vse_toolbox.casting_move"
|
||||
bl_label = "Casting Actions"
|
||||
bl_description = "Actions to Add, Remove, Move casting items"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
@@ -575,7 +605,6 @@ class VSETB_OT_casting_actions(Operator):
|
||||
items=(
|
||||
('UP', "Up", ""),
|
||||
('DOWN', "Down", ""),
|
||||
('REMOVE', "Remove", ""),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -589,50 +618,100 @@ class VSETB_OT_casting_actions(Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
scn = context.scene
|
||||
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
idx = active_strip.casting_index
|
||||
|
||||
strip_settings = get_strip_settings()
|
||||
idx = strip_settings.casting_index
|
||||
|
||||
try:
|
||||
item = active_strip.casting[idx]
|
||||
item = strip_settings.casting[idx]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
if self.action == 'DOWN' and idx < len(active_strip.casting) - 1:
|
||||
item_next = active_strip.casting[idx+1].name
|
||||
active_strip.casting.move(idx, idx+1)
|
||||
active_strip.casting_index += 1
|
||||
|
||||
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
|
||||
self.report({'INFO'}, info)
|
||||
if self.action == 'DOWN' and idx < len(strip_settings.casting) - 1:
|
||||
item_next = strip_settings.casting[idx+1].name
|
||||
strip_settings.casting.move(idx, idx+1)
|
||||
strip_settings.casting_index += 1
|
||||
|
||||
elif self.action == 'UP' and idx >= 1:
|
||||
item_prev = active_strip.casting[idx-1].name
|
||||
active_strip.casting.move(idx, idx-1)
|
||||
active_strip.casting_index -= 1
|
||||
item_prev = strip_settings.casting[idx-1].name
|
||||
strip_settings.casting.move(idx, idx-1)
|
||||
strip_settings.casting_index -= 1
|
||||
|
||||
info = f"Item {item.name} moved to position {(item.name, active_strip.casting_index + 1)}"
|
||||
self.report({'INFO'}, info)
|
||||
|
||||
elif self.action == 'REMOVE':
|
||||
item = active_strip.casting[active_strip.casting_index]
|
||||
active_strip.casting.remove(idx)
|
||||
|
||||
if active_strip.casting_index == 0:
|
||||
active_strip.casting_index = 0
|
||||
else:
|
||||
active_strip.casting_index -= 1
|
||||
|
||||
info = f"Item {item.name} removed from casting"
|
||||
self.report({'INFO'}, info)
|
||||
info = f"Item {item.asset.label} moved to position {(item.asset.label, strip_settings.casting_index + 1)}"
|
||||
self.report({'INFO'}, info)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_copy_casting(Operator):
|
||||
bl_idname = "sequencer.copy_casting"
|
||||
bl_label = "Casting Actions"
|
||||
bl_description = "Copy Casting from active strip"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
if active_strip and strip_settings.casting:
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
|
||||
active_strip = scn.sequence_editor.active_strip
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
datas = [c.to_dict() for c in strip_settings.casting]
|
||||
CASTING_BUFFER.write_text(json.dumps(datas), encoding='utf-8')
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class VSETB_OT_paste_casting(Operator):
|
||||
bl_idname = "sequencer.paste_casting"
|
||||
bl_label = "Casting Actions"
|
||||
bl_description = "Copy Casting from active strip"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
active_strip = context.scene.sequence_editor.active_strip
|
||||
if active_strip:
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
scn = context.scene
|
||||
strip_settings = get_strip_settings()
|
||||
|
||||
if not CASTING_BUFFER.exists():
|
||||
self.report({'ERROR'}, f'No Casting to copy.')
|
||||
return {"CANCELLED"}
|
||||
|
||||
casting_datas = json.loads(CASTING_BUFFER.read_text())
|
||||
for casting_item in casting_datas:
|
||||
for strip in context.selected_sequences:
|
||||
strip_settings = strip.vsetb_strip_settings
|
||||
|
||||
if strip_settings.casting.get(casting_item['name']):
|
||||
continue
|
||||
|
||||
item = strip.vsetb_strip_settings.casting.add()
|
||||
for k, v in casting_item.items():
|
||||
setattr(item, k, v)
|
||||
|
||||
strip_settings.casting.update()
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
classes=(
|
||||
VSETB_OT_auto_select_files,
|
||||
VSETB_OT_casting_add,
|
||||
VSETB_OT_casting_actions,
|
||||
VSETB_OT_casting_remove,
|
||||
VSETB_OT_casting_move,
|
||||
VSETB_OT_copy_casting,
|
||||
VSETB_OT_paste_casting,
|
||||
VSETB_OT_export_csv,
|
||||
VSETB_OT_import_files,
|
||||
VSETB_OT_load_assets,
|
||||
|
||||
Reference in New Issue
Block a user