Asset Pipeline: Add Support for Asset Catalogs #185

Merged
Nick Alberelli merged 7 commits from TinyNick/blender-studio-pipeline:feature/asset-pipeline-set-catalog into main 2024-01-09 23:28:34 +01:00
4 changed files with 23 additions and 6 deletions
Showing only changes of commit 942b24ca0e - Show all commits

View File

@ -24,19 +24,20 @@ def find_asset_cat_file(directory):
return find_asset_cat_file(parent_dir) return find_asset_cat_file(parent_dir)
def get_asset_cat_enum_items(): def get_asset_cat_enum_items(reload: bool = False):
global cat_data_cache global cat_data_cache
if cat_data_cache is not None: if cat_data_cache is not None and not reload:
return cat_data_cache return cat_data_cache
items = [] items = []
items.append(('NONE', 'None', ''))
asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__()) asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__())
with (Path(asset_cat_file)).open() as file: with (Path(asset_cat_file)).open() as file:
for line in file.readlines(): for line in file.readlines():
if line.startswith(("#", "VERSION", "\n")): if line.startswith(("#", "VERSION", "\n")):
continue continue
# Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n') # Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n')
name = line.split(':', 1)[1].strip('\n') name = line.split(':', 1)[1].split(":")[-1].strip("\n")
uuid = line.split(':', 1)[0] uuid = line.split(':', 1)[0]
items.append((uuid, name, uuid)) items.append((uuid, name, ''))
return items return items

View File

@ -81,7 +81,7 @@ def create_next_published_file(
asset_col = bpy.context.scene.asset_pipeline.asset_collection asset_col = bpy.context.scene.asset_pipeline.asset_collection
if publish_type == constants.ACTIVE_PUBLISH_KEY: if publish_type == constants.ACTIVE_PUBLISH_KEY:
asset_col.asset_mark() asset_col.asset_mark()
if catalog_id != '': if catalog_id != '' or catalog_id != 'NONE':
asset_col.asset_data.catalog_id = catalog_id asset_col.asset_data.catalog_id = catalog_id
bpy.ops.wm.save_as_mainfile(filepath=new_file_path.__str__(), copy=True) bpy.ops.wm.save_as_mainfile(filepath=new_file_path.__str__(), copy=True)
asset_col.asset_clear() asset_col.asset_clear()

View File

@ -1,6 +1,8 @@
from typing import Set
import bpy import bpy
import os import os
from pathlib import Path from pathlib import Path
from . import constants from . import constants
from . import config from . import config
from .prefs import get_addon_prefs from .prefs import get_addon_prefs
@ -25,6 +27,8 @@ from .sync import (
sync_execute_push, sync_execute_push,
) )
from .asset_catalog import get_asset_cat_enum_items
class ASSETPIPE_OT_create_new_asset(bpy.types.Operator): class ASSETPIPE_OT_create_new_asset(bpy.types.Operator):
bl_idname = "assetpipe.create_new_asset" bl_idname = "assetpipe.create_new_asset"
@ -944,6 +948,17 @@ class ASSETPIPE_OT_batch_ownership_change(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
class ASSETPIPE_OT_refresh_asset_cat(bpy.types.Operator):
bl_idname = "assetpipe.refresh_asset_cat"
bl_label = "Refresh Asset Catalogs"
bl_description = """Refresh Asset Catalogs"""
def execute(self, context: bpy.types.Context):
get_asset_cat_enum_items()
self.report({'INFO'}, "Asset Catalogs Refreshed!")
return {'FINISHED'}
classes = ( classes = (
ASSETPIPE_OT_update_ownership, ASSETPIPE_OT_update_ownership,
ASSETPIPE_OT_sync_push, ASSETPIPE_OT_sync_push,
@ -958,6 +973,7 @@ classes = (
ASSETPIPE_OT_update_surrendered_object, ASSETPIPE_OT_update_surrendered_object,
ASSETPIPE_OT_update_surrendered_transfer_data, ASSETPIPE_OT_update_surrendered_transfer_data,
ASSETPIPE_OT_batch_ownership_change, ASSETPIPE_OT_batch_ownership_change,
ASSETPIPE_OT_refresh_asset_cat,
) )

View File

@ -179,7 +179,7 @@ def sync_execute_push(self, context):
asset_pipe = context.scene.asset_pipeline asset_pipe = context.scene.asset_pipeline
asset_col = asset_pipe.asset_collection asset_col = asset_pipe.asset_collection
if _catalog_id != '': if _catalog_id != '' or _catalog_id != 'NONE':
asset_col.asset_data.catalog_id = _catalog_id asset_col.asset_data.catalog_id = _catalog_id
bpy.ops.wm.save_as_mainfile(filepath=file_path) bpy.ops.wm.save_as_mainfile(filepath=file_path)