Blender Kitsu: Refactor Shot Builder #183
@ -95,6 +95,8 @@ PLAYBLAST_DEFAULT_STATUS = "Todo"
|
||||
# Shot Builder Properties
|
||||
###########################
|
||||
|
||||
# TODO add documentation and move other shot builder props here
|
||||
|
||||
OUTPUT_COL_CREATE = {
|
||||
"anim": True,
|
||||
"comp": False,
|
||||
@ -130,3 +132,12 @@ LOAD_EDITORIAL_REF = {
|
||||
"smear_to_mesh": False,
|
||||
"storyboard": False,
|
||||
}
|
||||
|
||||
ASSET_TYPE_TO_OVERRIDE = {
|
||||
"CH": True, # Character
|
||||
"PR": True, # Rigged Prop
|
||||
"LI": True, # Library/Environment Asset
|
||||
"SE": False, # Set
|
||||
"LG": True, # Lighting Rig
|
||||
"CA": True, # Camera Rig
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
import bpy
|
||||
from .. import prefs
|
||||
from pathlib import Path
|
||||
import json
|
||||
from ..types import Shot
|
||||
from .core import link_and_override_collection, link_data_block
|
||||
from .. import bkglobals
|
||||
|
||||
|
||||
def get_asset_index_file() -> str:
|
||||
svn_project_root_dir = prefs.project_root_dir_get(bpy.context)
|
||||
asset_index_file = (
|
||||
Path(svn_project_root_dir)
|
||||
.joinpath("pro")
|
||||
.joinpath("assets")
|
||||
.joinpath("asset_index.json")
|
||||
)
|
||||
if asset_index_file.exists():
|
||||
return asset_index_file.__str__()
|
||||
|
||||
|
||||
def get_assset_index() -> dict:
|
||||
asset_index_file = get_asset_index_file()
|
||||
if asset_index_file is None:
|
||||
return
|
||||
return json.load(open(asset_index_file))
|
||||
|
||||
|
||||
def get_shot_assets(
|
||||
scene: bpy.types.Scene,
|
||||
output_collection: bpy.types.Collection,
|
||||
shot: Shot,
|
||||
):
|
||||
asset_index = get_assset_index()
|
||||
if asset_index is None:
|
||||
return
|
||||
assets = shot.get_all_assets()
|
||||
asset_slugs = [
|
||||
asset.data.get("slug") for asset in assets if asset.data.get("slug") is not None
|
||||
]
|
||||
if asset_slugs == []:
|
||||
print("No asset slugs found on Kitsu Server. Assets will not be loaded")
|
||||
for key, value in asset_index.items():
|
||||
if key in asset_slugs:
|
||||
filepath = value.get('filepath')
|
||||
data_type = value.get('type')
|
||||
if bkglobals.ASSET_TYPE_TO_OVERRIDE.get(key.split('-')[0]):
|
||||
if data_type != "Collection":
|
||||
print(f"Cannot load {key} because it is not a collection")
|
||||
continue
|
||||
linked_collection = link_and_override_collection(
|
||||
collection_name=key, file_path=filepath, scene=scene
|
||||
)
|
||||
print(f"'{key}': Succesfully Linked & Overriden")
|
||||
else:
|
||||
linked_collection = link_data_block(
|
||||
file_path=filepath, collection_name=key, data_block_type=data_type
|
||||
)
|
||||
print(f"'{key}': Succesfully Linked")
|
||||
output_collection.children.link(linked_collection)
|
@ -76,10 +76,10 @@ def set_frame_range(shot: Shot, scene: bpy.types.Scene):
|
||||
scene.frame_end = start_3d + shot.nb_frames - 1
|
||||
|
||||
|
||||
def link_collection(file_path: str, collection_name: str):
|
||||
def link_data_block(file_path: str, collection_name: str, data_block_type: str):
|
||||
bpy.ops.wm.link(
|
||||
filepath=file_path,
|
||||
directory=file_path + "/Collection",
|
||||
directory=file_path + "/" + data_block_type,
|
||||
filename=collection_name,
|
||||
instance_collections=False,
|
||||
)
|
||||
@ -99,7 +99,7 @@ def link_and_override_collection(
|
||||
Returns:
|
||||
bpy.types.Collection: Overriden Collection linked to Scene Collection
|
||||
"""
|
||||
camera_col = link_collection(file_path, collection_name)
|
||||
camera_col = link_data_block(file_path, collection_name, "Collection")
|
||||
override_camera_col = camera_col.override_hierarchy_create(
|
||||
scene, bpy.context.view_layer, do_fully_editable=True
|
||||
)
|
||||
@ -173,4 +173,4 @@ def link_task_type_output_collections(shot: Shot, task_short_name: str):
|
||||
print(f"Unable to link output collection for {external_filepath.name}")
|
||||
file_path = external_filepath.__str__()
|
||||
colection_name = shot.get_shot_task_name(short_name)
|
||||
link_collection(file_path, colection_name)
|
||||
link_data_block(file_path, colection_name)
|
||||
|
@ -16,6 +16,7 @@ from .core import (
|
||||
from .editorial import editorial_export_get_latest
|
||||
from .file_save import save_shot_builder_file
|
||||
from .template import open_template_for_task_type
|
||||
from .assets import get_shot_assets
|
||||
|
||||
active_project = None
|
||||
|
||||
@ -167,6 +168,9 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
|
||||
if task_short_name == 'anim':
|
||||
link_camera_rig(context.scene, output_col)
|
||||
|
||||
# Load Assets
|
||||
get_shot_assets(scene=scene, output_collection=output_col, shot=shot)
|
||||
|
||||
# Link External Output Collections
|
||||
link_task_type_output_collections(shot, task_short_name)
|
||||
|
||||
|
@ -560,6 +560,11 @@ class Shot(Entity):
|
||||
def get_all_tasks(self) -> List[Task]:
|
||||
return [Task.from_dict(t) for t in gazu.task.all_tasks_for_shot(asdict(self))]
|
||||
|
||||
def get_all_assets(self) -> List[Asset]:
|
||||
return [
|
||||
Asset.from_dict(t) for t in gazu.asset.all_assets_for_shot(asdict(self))
|
||||
]
|
||||
|
||||
def get_sequence(self) -> Sequence:
|
||||
return Sequence.from_dict(gazu.shot.get_sequence_from_shot(asdict(self)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user