Asset Pipeline: Add Support for Asset Catalogs #185
42
scripts-blender/addons/asset_pipeline/asset_catalog.py
Normal file
42
scripts-blender/addons/asset_pipeline/asset_catalog.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
asset_file_cache = None
|
||||||
|
cat_data_cache = None
|
||||||
|
|
||||||
|
|
||||||
|
# TODO add refresh operator
|
||||||
|
|
||||||
|
|
||||||
|
def find_asset_cat_file(directory):
|
||||||
|
global asset_file_cache
|
||||||
|
if asset_file_cache is not None:
|
||||||
|
return asset_file_cache
|
||||||
|
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_asset_cat_enum_items():
|
||||||
|
global cat_data_cache
|
||||||
|
if cat_data_cache is not None:
|
||||||
|
return cat_data_cache
|
||||||
|
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(':', 1)[1].strip('\n')
|
||||||
|
uuid = line.split(':', 1)[0]
|
||||||
|
|
||||||
|
items.append((uuid, name, uuid))
|
||||||
|
return items
|
@ -5,25 +5,13 @@ from . import constants
|
|||||||
from .config import get_task_layer_presets_path
|
from .config import get_task_layer_presets_path
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from .prefs import get_addon_prefs
|
from .prefs import get_addon_prefs
|
||||||
|
from .asset_catalog import get_asset_cat_enum_items
|
||||||
|
|
||||||
""" NOTE Items in these properties groups should be generated by a function that finds the
|
""" NOTE Items in these properties groups should be generated by a function that finds the
|
||||||
avaliable task layers from the task_layer.json file that needs to be created.
|
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):
|
def get_task_layer_presets(self, context):
|
||||||
prefs = get_addon_prefs()
|
prefs = get_addon_prefs()
|
||||||
user_tls = Path(prefs.custom_task_layers_dir)
|
user_tls = Path(prefs.custom_task_layers_dir)
|
||||||
@ -159,22 +147,9 @@ class AssetPipeline(bpy.types.PropertyGroup):
|
|||||||
file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False)
|
file_parent_ui_bool: bpy.props.BoolProperty(name="Show/Hide Parent", default=False)
|
||||||
|
|
||||||
def get_asset_catalogs(self, context):
|
def get_asset_catalogs(self, context):
|
||||||
items = []
|
return get_asset_cat_enum_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, ''))
|
asset_catalog_id: bpy.props.EnumProperty(name="Catalog", items=get_asset_catalogs)
|
||||||
return items
|
|
||||||
|
|
||||||
aval_asset_catalogs: bpy.props.EnumProperty(
|
|
||||||
name="Catalog", items=get_asset_catalogs
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
Loading…
Reference in New Issue
Block a user