2026-03-16

This commit is contained in:
2026-03-17 15:39:39 -06:00
parent 67782275d5
commit 330fed4231
29 changed files with 532 additions and 199 deletions
@@ -37,9 +37,8 @@ linkable_sockets = [
asset_lib_name = 'Brushstroke Tools Library'
@persistent
def find_context_brushstrokes(dummy):
context = bpy.context
settings = context.scene.BSBST_settings
def find_context_brushstrokes(scene, depsgraph):
settings = scene.BSBST_settings
edit_toggle = settings.edit_toggle
settings.edit_toggle = False
@@ -49,7 +48,7 @@ def find_context_brushstrokes(dummy):
# identify context brushstrokes
for el in range(len(settings.context_brushstrokes)):
settings.context_brushstrokes.remove(0)
context_object = context.object
context_object = depsgraph.view_layer.objects.active
if not is_brushstrokes_object(context_object):
bs_ob = is_flow_object(context_object)
if bs_ob:
@@ -97,12 +96,11 @@ def find_context_brushstrokes(dummy):
settings.edit_toggle = edit_toggle
@persistent
def refresh_preset(dummy):
context = bpy.context
settings = context.scene.BSBST_settings
def refresh_preset(scene, depsgraph):
settings = scene.BSBST_settings
if not settings:
return
for ob in [settings.preset_object, get_active_context_brushstrokes_object(context)]:
for ob in [settings.preset_object, get_active_context_brushstrokes_object(scene)]:
if not ob:
continue
for mod in ob.modifiers:
@@ -313,6 +311,25 @@ def write_lib_version(dir: Path = None):
with open(dir.joinpath(".version"), "w") as file:
file.write(str(addon_version))
def get_file_blend_version(path: Path):
with open(path, "rb") as f:
prefix = f.read(4)
f.seek(0)
if prefix.startswith(b"BLENDER"):
header = f.read(12)
elif prefix == b"\x28\xb5\x2f\xfd": # zstd
dctx = zstd.ZstdDecompressor()
with dctx.stream_reader(f) as reader:
header = reader.read(12)
else:
raise ValueError("Unknown blend format")
version = header[9:12].decode()
return int(version[0]), int(version[1:])
def copy_resources_to_dir(tgt_dir = ''):
source_dir = get_addon_directory().joinpath('assets')
if not tgt_dir:
@@ -545,8 +562,21 @@ def find_brush_style_by_name(name: str):
return brush_style
return None
def link_to_collections_by_ref(obj, ref_obj):
def link_to_collections_by_ref(obj, ref_obj, unlink=True):
col_list = []
if unlink:
for col in obj.users_collection:
if col.library:
continue
col_list += [col]
if col_list:
for col in col_list:
col.objects.unlink(obj)
col_list = []
for col in ref_obj.users_collection:
if col.library:
continue
@@ -754,8 +784,8 @@ def context_brushstrokes(context):
settings = context.scene.BSBST_settings
return settings.context_brushstrokes
def get_active_context_brushstrokes_object(context):
settings = context.scene.BSBST_settings
def get_active_context_brushstrokes_object(scene):
settings = scene.BSBST_settings
if not settings.context_brushstrokes:
return None
bs = settings.context_brushstrokes[settings.active_context_brushstrokes_index]
@@ -765,19 +795,22 @@ def get_active_context_brushstrokes_object(context):
def get_active_context_surface_object(context):
if not context.object:
return None
bs_ob = get_active_context_brushstrokes_object(context)
bs_ob = get_active_context_brushstrokes_object(context.scene)
if bs_ob:
return get_surface_object(bs_ob)
if context.object.type == 'MESH':
return context.object
def flow_name(name):
return f'{name}-FLOW'
def bs_name(surf_name: str) -> str:
return f'{surf_name} - Brushstrokes'
def flow_name(bs_name: str) -> str:
return f'{bs_name}-FLOW'
def edit_active_brushstrokes(context):
context.view_layer.depsgraph.update()
bs_ob = get_active_context_brushstrokes_object(context)
bs_ob = get_active_context_brushstrokes_object(context.scene)
if not bs_ob:
return {"CANCELLED"}