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
3 changed files with 50 additions and 0 deletions
Showing only changes of commit f74113a899 - Show all commits

View File

@ -49,6 +49,22 @@ def get_next_published_file(
)
def get_asset_catalogues():
folder = Path(bpy.data.filepath).parent
target_catalog = "Catalog"
with (folder / "blender_assets.cats.txt").open() as f:
for line in f.readlines():
if line.startswith(("#", "VERSION", "\n")):
continue
# Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n')
name = line.split(":")[2].split("\n")[0]
if name == target_catalog:
uuid = line.split(":")[0]
obj = bpy.data.objects["Suzanne"] # Object name, case-sensitive !
asset_data = obj.asset_data
asset_data.catalog_id = uuid
def create_next_published_file(
current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY
) -> None:
@ -58,6 +74,7 @@ def create_next_published_file(
current_file (Path): Current file, which must be a task file at root of asset directory
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
"""
# TODO Set Catalogue here
new_file_path = get_next_published_file(current_file, publish_type)
if publish_type == constants.ACTIVE_PUBLISH_KEY:
bpy.context.scene.asset_pipeline.asset_collection.asset_mark()

View File

@ -1,4 +1,5 @@
import bpy
import os
from typing import List
from . import constants
from .config import get_task_layer_presets_path
@ -10,6 +11,19 @@ avaliable task layers from the task_layer.json file that needs to be created.
"""
# TODO find better place for this function
def find_asset_cat_file(directory):
asset_file = os.path.join(directory, "blender_assets.cats.txt")
if os.path.exists(asset_file):
return asset_file
parent_dir = os.path.dirname(directory)
if parent_dir == directory:
raise FileNotFoundError("blender_assets.cats.txt not found")
return find_asset_cat_file(parent_dir)
def get_task_layer_presets(self, context):
prefs = get_addon_prefs()
user_tls = Path(prefs.custom_task_layers_dir)
@ -144,6 +158,24 @@ class AssetPipeline(bpy.types.PropertyGroup):
)
file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False)
def get_asset_catalogs(self, context):
items = []
asset_cat_file = find_asset_cat_file(Path(bpy.data.filepath).parent.__str__())
with (Path(asset_cat_file)).open() as file:
for line in file.readlines():
if line.startswith(("#", "VERSION", "\n")):
continue
# Each line contains : 'uuid:catalog_tree:catalog_name' + eol ('\n')
name = line.split(":")[2].split("\n")[0]
uuid = line.split(":")[0]
items.append((uuid, name, ''))
return items
aval_asset_catalogs: bpy.props.EnumProperty(
name="Catalog", items=get_asset_catalogs
)
classes = (
AssetTransferData,

View File

@ -54,6 +54,7 @@ class ASSETPIPE_PT_sync(bpy.types.Panel):
for task_layer in asset_pipe.local_task_layers:
row.label(text=task_layer.name)
layout.prop(asset_pipe, 'aval_asset_catalogs')
layout.prop(asset_pipe, "asset_collection")
staged = is_staged_publish(Path(bpy.data.filepath))