feat: Refactor asset library management and update manifest for improved organization

This commit is contained in:
2026-05-25 16:18:52 +08:00
parent 564a47da69
commit 3a18d01d17
7 changed files with 47 additions and 37 deletions

View File

@@ -10,54 +10,36 @@ from . import menus
auto_load.init() auto_load.init()
def add_asset_library_if_missing(): def add_asset_library():
"""检查并添加Asset Library(如果不存在),使用link导入方式""" """Add Bioxel asset library, ensuring only one exists by removing duplicates first."""
# 检查路径是否存在
if not NODE_LIB_DIRPATH.exists(): if not NODE_LIB_DIRPATH.exists():
print(f"警告: 节点库路径不存在 - {NODE_LIB_DIRPATH}") print(f"Node library path does not exist - {NODE_LIB_DIRPATH}")
return return
# 转换为字符串路径用于Blender设置
lib_path_str = str(NODE_LIB_DIRPATH) lib_path_str = str(NODE_LIB_DIRPATH)
# 检查是否已存在该资产库
prefs = bpy.context.preferences.filepaths.asset_libraries prefs = bpy.context.preferences.filepaths.asset_libraries
for lib in prefs:
if lib.path == lib_path_str:
return # 已存在,无需添加
# 添加新的资产库,使用link导入方式 # Add new library
new_lib = prefs.new() new_lib = prefs.new()
new_lib.name = "O Bioxel" # 资产库名称 new_lib.name = "O Bioxel"
new_lib.path = lib_path_str # 资产库路径(字符串形式) new_lib.path = lib_path_str
new_lib.import_method = "PACK" # 设置导入方式为link new_lib.import_method = "PACK"
print(f"Add Bioxel Nodes library: {lib_path_str}") print(f"Add Bioxel Nodes library: {lib_path_str}")
def remove_asset_library_if_exists(): def remove_asset_library_if_exists():
"""Remove the Bioxel asset library entry if it was added (by path or name).""" """Remove the Bioxel asset library entry if it was added (by path or name)."""
# if path missing, nothing to remove
lib_path_str = str(NODE_LIB_DIRPATH) lib_path_str = str(NODE_LIB_DIRPATH)
prefs = bpy.context.preferences.filepaths.asset_libraries prefs = bpy.context.preferences.filepaths.asset_libraries
# iterate over a snapshot of prefs to safely find index for lib in list(prefs):
lib_to_remove = None
for i, lib in enumerate(list(prefs)):
try: try:
if lib.path == lib_path_str: if "Bioxel" in lib.name or lib.path == lib_path_str:
lib_to_remove = lib prefs.remove(lib)
break
except Exception: except Exception:
continue continue
if lib_to_remove is not None:
try:
prefs.remove(lib_to_remove)
print(f"Removed Bioxel Nodes library: {lib_path_str}")
except Exception as e:
print(f"Warning: failed to remove Bioxel node library: {e}")
def register(): def register():
pcoll = previews.new() pcoll = previews.new()
@@ -90,7 +72,8 @@ def register():
auto_load.register() auto_load.register()
menus.add() menus.add()
add_asset_library_if_missing() remove_asset_library_if_exists()
add_asset_library()
def unregister(): def unregister():

Binary file not shown.

View File

@@ -4,7 +4,7 @@ id = "bioxelnodes"
version = "2.0.0" version = "2.0.0"
name = "Bioxel Nodes" name = "Bioxel Nodes"
tagline = "For scientific volumetric data visualization in Blender" tagline = "For scientific volumetric data visualization in Blender"
maintainer = "Ma Nan <icrdr2010@outlook.com>" maintainer = "Nan <icrdr2010@outlook.com>"
type = "add-on" type = "add-on"
website = "https://omoolab.github.io/BioxelNodes/latest" website = "https://omoolab.github.io/BioxelNodes/latest"
@@ -14,7 +14,32 @@ license = ['SPDX:GPL-3.0-or-later']
copyright = ["2024 OmooLab"] copyright = ["2024 OmooLab"]
platforms = ["windows-x64"] platforms = ["windows-x64"]
wheels = ["./wheels/contourpy-1.3.3-cp311-cp311-win_amd64.whl", "./wheels/contourpy-1.3.3-cp313-cp313-win_amd64.whl", "./wheels/cycler-0.12.1-py3-none-any.whl", "./wheels/fonttools-4.63.0-cp311-cp311-win_amd64.whl", "./wheels/fonttools-4.63.0-cp313-cp313-win_amd64.whl", "./wheels/h5py-3.16.0-cp311-cp311-win_amd64.whl", "./wheels/h5py-3.16.0-cp313-cp313-win_amd64.whl", "./wheels/kiwisolver-1.5.0-cp311-cp311-win_amd64.whl", "./wheels/kiwisolver-1.5.0-cp313-cp313-win_amd64.whl", "./wheels/lxml-6.1.1-cp311-cp311-win_amd64.whl", "./wheels/lxml-6.1.1-cp313-cp313-win_amd64.whl", "./wheels/matplotlib-3.10.7-cp311-cp311-win_amd64.whl", "./wheels/matplotlib-3.10.7-cp313-cp313-win_amd64.whl", "./wheels/mrcfile-1.5.1-py2.py3-none-any.whl", "./wheels/packaging-26.2-py3-none-any.whl", "./wheels/pillow-11.2.1-cp311-cp311-win_amd64.whl", "./wheels/pillow-11.2.1-cp313-cp313-win_amd64.whl", "./wheels/pyometiff-1.0.0-py3-none-any.whl", "./wheels/pyparsing-3.3.2-py3-none-any.whl", "./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", "./wheels/simpleitk-2.5.5-cp311-abi3-win_amd64.whl", "./wheels/six-1.17.0-py2.py3-none-any.whl", "./wheels/tifffile-2024.7.24-py3-none-any.whl", "./wheels/transforms3d-0.4.2-py3-none-any.whl"] wheels = [
"./wheels/contourpy-1.3.3-cp311-cp311-win_amd64.whl",
"./wheels/contourpy-1.3.3-cp313-cp313-win_amd64.whl",
"./wheels/cycler-0.12.1-py3-none-any.whl",
"./wheels/fonttools-4.63.0-cp311-cp311-win_amd64.whl",
"./wheels/fonttools-4.63.0-cp313-cp313-win_amd64.whl",
"./wheels/h5py-3.16.0-cp311-cp311-win_amd64.whl",
"./wheels/h5py-3.16.0-cp313-cp313-win_amd64.whl",
"./wheels/kiwisolver-1.5.0-cp311-cp311-win_amd64.whl",
"./wheels/kiwisolver-1.5.0-cp313-cp313-win_amd64.whl",
"./wheels/lxml-6.1.1-cp311-cp311-win_amd64.whl",
"./wheels/lxml-6.1.1-cp313-cp313-win_amd64.whl",
"./wheels/matplotlib-3.10.7-cp311-cp311-win_amd64.whl",
"./wheels/matplotlib-3.10.7-cp313-cp313-win_amd64.whl",
"./wheels/mrcfile-1.5.1-py2.py3-none-any.whl",
"./wheels/packaging-26.2-py3-none-any.whl",
"./wheels/pillow-11.2.1-cp311-cp311-win_amd64.whl",
"./wheels/pillow-11.2.1-cp313-cp313-win_amd64.whl",
"./wheels/pyometiff-1.0.0-py3-none-any.whl",
"./wheels/pyparsing-3.3.2-py3-none-any.whl",
"./wheels/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
"./wheels/simpleitk-2.5.5-cp311-abi3-win_amd64.whl",
"./wheels/six-1.17.0-py2.py3-none-any.whl",
"./wheels/tifffile-2024.7.24-py3-none-any.whl",
"./wheels/transforms3d-0.4.2-py3-none-any.whl",
]
[permissions] [permissions]
files = "Import/export volume data from/to disk" files = "Import/export volume data from/to disk"

View File

@@ -1,9 +1,11 @@
from pathlib import Path from pathlib import Path
NODE_LIB_FILENAME = "O_Bioxel_Nodes.blend"
NODE_LIB_DIRPATH = Path(Path(__file__).parent, NODE_LIB_DIRPATH = Path(Path(__file__).parent,
"assets/O_Bioxel").resolve() "assets/O_Bioxel").resolve()
LATEST_NODE_LIB_PATH = Path(NODE_LIB_DIRPATH, LATEST_NODE_LIB_PATH = Path(NODE_LIB_DIRPATH,
"BioxelNodes.blend").resolve() NODE_LIB_FILENAME).resolve()
PREVIEW_COLLECTIONS = {} PREVIEW_COLLECTIONS = {}

View File

@@ -2,7 +2,7 @@ from pathlib import Path
import bpy import bpy
# LookupError replaced with built-in LookupError # LookupError replaced with built-in LookupError
from .constants import LATEST_NODE_LIB_PATH from .constants import LATEST_NODE_LIB_PATH, NODE_LIB_FILENAME
def move_node_to_node(node, target_node, offset=(0, 0)): def move_node_to_node(node, target_node, offset=(0, 0)):
@@ -105,7 +105,7 @@ def add_bioxel_node(name: str):
bpy.ops.object.modifier_add_node_group( bpy.ops.object.modifier_add_node_group(
asset_library_type="CUSTOM", asset_library_type="CUSTOM",
asset_library_identifier="O Bioxel", asset_library_identifier="O Bioxel",
relative_asset_identifier=f"BioxelNodes.blend\\NodeTree\\{name}", relative_asset_identifier=f"{NODE_LIB_FILENAME}\\NodeTree\\{name}",
) )
bpy.ops.object.modifier_remove(modifier=name) bpy.ops.object.modifier_remove(modifier=name)
try: try: