Blender Kitsu: Add option to Exclude Collections from Output Collection #120

Merged
Nick Alberelli merged 9 commits from :feature/exclude-output-collections into main 2023-07-13 19:54:03 +02:00
Showing only changes of commit 31f3ccb288 - Show all commits

View File

@ -413,6 +413,15 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator):
bl_description = ( bl_description = (
"Scans scene for any collections that are not yet in the output collection" "Scans scene for any collections that are not yet in the output collection"
) )
active_shot = None
output_coll_name = None
output_coll = None
asset_colls = NotImplementedError
exclude_collections: bpy.props.BoolProperty(
name="Exclude Collections",
description="Exclude selectied collections from the 'anim.output' collection",
)
@classmethod @classmethod
def poll(cls, context: bpy.types.Context) -> bool: def poll(cls, context: bpy.types.Context) -> bool:
@ -425,24 +434,18 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator):
return bool(active_shot and output_coll) return bool(active_shot and output_coll)
def execute(self, context: bpy.types.Context) -> Set[str]: def invoke(self, context, event):
active_shot = cache.shot_active_get() self.active_shot = cache.shot_active_get()
output_coll_name = opsdata.get_output_coll_name(active_shot) self.output_coll_name = opsdata.get_output_coll_name(self.active_shot)
output_coll = bpy.data.collections[output_coll_name] self.output_coll = bpy.data.collections[self.output_coll_name]
return context.window_manager.invoke_props_dialog(self, width=500)
# Clear Out Output Collection before Starting def get_collections(self, context):
for collection in output_coll.children: self.asset_colls = opsdata.find_asset_collections_in_scene(context.scene)
output_coll.children.unlink(collection)
bpy.context.view_layer.update()
asset_colls = opsdata.find_asset_collections_in_scene(context.scene)
missing: List[bpy.types.Collection] = [] missing: List[bpy.types.Collection] = []
output_coll_childs = list(opsdata.traverse_collection_tree(output_coll))
# Check if all found asset colls are in output coll. # Check if all found asset colls are in output coll.
for coll in asset_colls: for coll in self.asset_colls:
if coll in output_coll_childs:
continue
missing.append(coll) missing.append(coll)
# Only take parent colls. # Only take parent colls.
@ -455,10 +458,26 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator):
if coll_comp in coll_childs: if coll_comp in coll_childs:
childs.append(coll_comp) childs.append(coll_comp)
parents = [coll for coll in missing if coll not in childs] return [coll for coll in missing if coll not in childs]
def draw(self, context):
layout = self.layout
layout.prop(self, "exclude_collections")
if not self.exclude_collections:
return
parents = self.get_collections(context)
for col in parents:
layout.prop(col.blender_kitsu_exclusions, "exclude", text=col.name)
def execute(self, context: bpy.types.Context) -> Set[str]:
# Clear Out Output Collection before Starting
for collection in self.output_coll.children:
self.output_coll.children.unlink(collection)
bpy.context.view_layer.update()
parents = self.get_collections(context)
for coll in parents: for coll in parents:
output_coll.children.link(coll) self.output_coll.children.link(coll)
logger.info("%s linked in %s", coll.name, output_coll.name) logger.info("%s linked in %s", coll.name, self.output_coll.name)
# Ensure Camera Rig is Linked # Ensure Camera Rig is Linked
for coll in [col for col in bpy.data.collections]: for coll in [col for col in bpy.data.collections]:
@ -466,11 +485,11 @@ class KITSU_OT_anim_update_output_coll(bpy.types.Operator):
if ( if (
coll.override_library.hierarchy_root.name == "CA-camera_rig" coll.override_library.hierarchy_root.name == "CA-camera_rig"
): # TODO Fix this hack to be generic ): # TODO Fix this hack to be generic
output_coll.children.link(coll) self.output_coll.children.link(coll)
self.report( self.report(
{"INFO"}, {"INFO"},
f"Found Asset Collections: {len(asset_colls)} | Added to output collection: {len(parents)}", f"Found Asset Collections: {len(self.asset_colls)} | Added to output collection: {len(parents)}",
) )
return {"FINISHED"} return {"FINISHED"}