Brushstroke Tools: Initial Version #328

Merged
Simon Thommes merged 229 commits from SimonThommes/blender-studio-tools:brushstroke_tools-initial-version into main 2024-11-06 15:03:47 +01:00
2 changed files with 30 additions and 2 deletions
Showing only changes of commit e2fa4b0c2a - Show all commits

View File

@ -1,14 +1,25 @@
from . import utils, icons, settings, ui, draw_tool, ops from . import utils, icons, settings, ui, draw_tool, ops
import toml import toml
import bpy
modules = [utils, icons, settings, ui, draw_tool, ops] modules = [utils, icons, settings, ui, draw_tool, ops]
def register(): def register():
# register modules
for m in modules: for m in modules:
m.register() m.register()
SimonThommes marked this conversation as resolved Outdated

Generally it's recommended to unregister in reverse registration order: for m in reversed(modules):

Generally it's recommended to unregister in reverse registration order: `for m in reversed(modules):`
# read addon meta-data
manifest = toml.load(f"{utils.get_addon_directory()}/blender_manifest.toml") manifest = toml.load(f"{utils.get_addon_directory()}/blender_manifest.toml")
utils.addon_version = tuple([int(i) for i in manifest['version'].split('.')]) utils.addon_version = tuple([int(i) for i in manifest['version'].split('.')])
# Add addon asset library
utils.register_asset_lib()
def unregister(): def unregister():
# un-register modules
for m in reversed(modules): for m in reversed(modules):
m.unregister() m.unregister()
# Remove addon asset library
utils.unregister_asset_lib()

View File

@ -18,6 +18,8 @@ linkable_sockets = [
bpy.types.NodeTreeInterfaceSocketInt, bpy.types.NodeTreeInterfaceSocketInt,
] ]
asset_lib_name = 'Brushstroke Tools Library'
@persistent @persistent
def refresh_preset(dummy): def refresh_preset(dummy):
settings = bpy.context.scene.BSBST_settings settings = bpy.context.scene.BSBST_settings
@ -118,6 +120,21 @@ def ensure_resources():
if ng_missing: if ng_missing:
import_resources(list(ng_missing)) import_resources(list(ng_missing))
def register_asset_lib():
asset_libs = bpy.context.preferences.filepaths.asset_libraries
if asset_lib_name in [a.name for a in asset_libs]:
return
lib = asset_libs.new()
SimonThommes marked this conversation as resolved Outdated

Would recommend using x not in y instead of not x in y for improved readability.

https://stackoverflow.com/a/3481700

Would recommend using `x not in y` instead of `not x in y` for improved readability. https://stackoverflow.com/a/3481700
lib.name = asset_lib_name
lib.path = get_addon_directory()
def unregister_asset_lib():
asset_libs = bpy.context.preferences.filepaths.asset_libraries
lib = asset_libs.get(asset_lib_name)
if not lib:
return
asset_libs.remove(lib)
def transfer_modifier(modifier_name, target_obj, source_obj): def transfer_modifier(modifier_name, target_obj, source_obj):
""" """
Core taken from https://projects.blender.org/studio/blender-studio-pipeline Core taken from https://projects.blender.org/studio/blender-studio-pipeline