Blender Kitsu: Refactor Shot Builder #183

Merged
Nick Alberelli merged 55 commits from TinyNick/blender-studio-pipeline:feature/shot-builder-2 into main 2023-12-21 23:58:21 +01:00
2 changed files with 60 additions and 1 deletions
Showing only changes of commit cae0541f77 - Show all commits

View File

@ -6,8 +6,15 @@ from ..types import (
Shot,
TaskType,
)
from blender_kitsu import prefs
#################
# Constants
#################
CAMERA_NAME = 'CAM-camera'
def get_project_root_path() -> Path:
addon_prefs = prefs.addon_prefs_get(bpy.context)
return Path(addon_prefs.project_root_dir).resolve()
@ -39,6 +46,51 @@ def set_render_engine(scene: bpy.types.Scene, engine='CYCLES'):
"""
scene.render.engine = engine
def link_camera_rig(
scene: bpy.types.Scene,
output_collection: bpy.types.Collection,
):
"""
Function to load the camera rig. The rig will be added to the output collection
of the shot and the camera will be set as active camera.
"""
# Load camera rig.
project_path = get_project_root_path()
path = f"{project_path}/pro/assets/cam/camera_rig.blend"
if not Path(path).exists():
camera_data = bpy.data.cameras.new(name=CAMERA_NAME)
camera_object = bpy.data.objects.new(name=CAMERA_NAME, object_data=camera_data)
scene.collection.objects.link(camera_object)
output_collection.objects.link(camera_object)
return
collection_name = (
"CA-camera_rig" # TODO Rename the asset itself, this breaks convention
)
bpy.ops.wm.link(
filepath=path,
directory=path + "/Collection",
filename=collection_name,
)
# bpy.ops.object.make_override_library()
camera_col = bpy.data.collections.get(collection_name)
override_camera_col = camera_col.override_hierarchy_create(
bpy.context.scene, bpy.context.view_layer, do_fully_editable=True
)
# Make library override.
output_collection.children.link(override_camera_col)
# scene.collection.children.link(override_camera_col)
# Set the camera of the camera rig as active scene camera.
camera = override_camera_col.objects.get(CAMERA_NAME)
scene.camera = camera
def task_type_anim_output_collection(
scene: bpy.types.Scene, shot: Shot, task_type: TaskType
) -> bpy.types.Collection:

View File

@ -2,7 +2,12 @@ import bpy
from pathlib import Path
from typing import List, Any, Tuple, Set, cast
from .. import prefs, cache
from .core import get_shot_task_name, get_file_dir
from .core import (
get_file_dir,
set_render_engine,
link_camera_rig,
task_type_anim_output_collection,
)
active_project = None
@ -143,6 +148,8 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
set_render_engine(context.scene)
output_col = task_type_anim_output_collection(context.scene, shot, task_type)
link_camera_rig(context.scene, output_col)
print("Create shot with the following details") # TODO Remove
print(f"Seq Name: '{seq.name}' Seq ID: '{self.seq_id}'")
print(f"Shot Name: '{shot.name}' Shot ID: '{self.shot_id}'")