Brushstroke Tools: Initial Version #328
@ -225,6 +225,7 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
||||
mod.show_group_selector = False
|
||||
|
||||
# update brushstroke context
|
||||
utils.find_context_brushstrokes(None)
|
||||
for i, name in enumerate([bs.name for bs in settings.context_brushstrokes]):
|
||||
if name == brushstrokes_object.name:
|
||||
settings.active_context_brushstrokes_index = i
|
||||
|
@ -1,55 +1,5 @@
|
||||
import bpy
|
||||
from . import utils, icons
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
@persistent
|
||||
def find_context_brushstrokes(dummy):
|
||||
context = bpy.context
|
||||
settings = context.scene.BSBST_settings
|
||||
|
||||
edit_toggle = settings.edit_toggle
|
||||
settings.edit_toggle = False
|
||||
len_prev = len(settings.context_brushstrokes)
|
||||
name_prev = settings.context_brushstrokes[settings.active_context_brushstrokes_index].name if len_prev else ''
|
||||
idx = settings.active_context_brushstrokes_index
|
||||
# identify context brushstrokes
|
||||
for el in range(len(settings.context_brushstrokes)):
|
||||
settings.context_brushstrokes.remove(0)
|
||||
context_object = context.object
|
||||
surf_ob = utils.get_surface_object(context_object)
|
||||
if surf_ob:
|
||||
context_object = surf_ob
|
||||
for ob in bpy.data.objects:
|
||||
if not utils.is_brushstrokes_object(ob):
|
||||
continue
|
||||
surf_ob = utils.get_surface_object(ob)
|
||||
flow_ob = utils.get_flow_object(ob)
|
||||
if not surf_ob:
|
||||
if not flow_ob:
|
||||
continue
|
||||
if not surf_ob == context_object:
|
||||
if not flow_ob == context_object:
|
||||
continue
|
||||
bs = settings.context_brushstrokes.add()
|
||||
bs.name = ob.name
|
||||
bs.method = ob['BSBST_method']
|
||||
bs.hide_viewport_base = ob.hide_get()
|
||||
if name_prev == ob.name:
|
||||
idx = len(settings.context_brushstrokes)-1
|
||||
if not settings.context_brushstrokes:
|
||||
settings.edit_toggle = edit_toggle
|
||||
return
|
||||
if context.object:
|
||||
for i, bs in enumerate(settings.context_brushstrokes):
|
||||
if bs.name == context.object.name:
|
||||
settings.silent_switch = True
|
||||
settings.active_context_brushstrokes_index = i
|
||||
settings.silent_switch = False
|
||||
elif len_prev == len(settings.context_brushstrokes):
|
||||
settings.active_context_brushstrokes_index = idx
|
||||
|
||||
settings.active_context_brushstrokes_index = max(min(settings.active_context_brushstrokes_index, len(settings.context_brushstrokes)-1), 0)
|
||||
settings.edit_toggle = edit_toggle
|
||||
|
||||
def update_active_brushstrokes(self, context):
|
||||
settings = context.scene.BSBST_settings
|
||||
@ -153,6 +103,8 @@ def set_active_context_brushstrokes_index(self, value):
|
||||
return
|
||||
if not bs_ob:
|
||||
return
|
||||
if not bpy.context.object:
|
||||
return
|
||||
view_layer = bpy.context.view_layer
|
||||
if bpy.context.object.visible_get(view_layer = view_layer):
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
@ -300,7 +252,7 @@ def register():
|
||||
bpy.types.Object.modifier_info = bpy.props.CollectionProperty(type=BSBST_modifier_info)
|
||||
bpy.types.Material.brush_style = bpy.props.StringProperty(get=get_brush_style, set=set_brush_style, search=get_brush_style_items, search_options={'SORT'})
|
||||
|
||||
bpy.app.handlers.depsgraph_update_post.append(find_context_brushstrokes)
|
||||
bpy.app.handlers.depsgraph_update_post.append(utils.find_context_brushstrokes)
|
||||
|
||||
def unregister():
|
||||
for c in reversed(classes):
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
import bpy
|
||||
from bpy.app.handlers import persistent
|
||||
import math, shutil, errno
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
ng_list = [
|
||||
".brushstroke_tools.draw_processing",
|
||||
@ -21,6 +22,57 @@ linkable_sockets = [
|
||||
|
||||
asset_lib_name = 'Brushstroke Tools Library'
|
||||
|
||||
@persistent
|
||||
def find_context_brushstrokes(dummy):
|
||||
context = bpy.context
|
||||
settings = context.scene.BSBST_settings
|
||||
|
||||
edit_toggle = settings.edit_toggle
|
||||
settings.edit_toggle = False
|
||||
len_prev = len(settings.context_brushstrokes)
|
||||
name_prev = settings.context_brushstrokes[settings.active_context_brushstrokes_index].name if len_prev else ''
|
||||
idx = settings.active_context_brushstrokes_index
|
||||
# identify context brushstrokes
|
||||
for el in range(len(settings.context_brushstrokes)):
|
||||
settings.context_brushstrokes.remove(0)
|
||||
context_object = context.object
|
||||
surf_ob = get_surface_object(context_object)
|
||||
if surf_ob:
|
||||
context_object = surf_ob
|
||||
for ob in bpy.data.objects:
|
||||
if not is_brushstrokes_object(ob):
|
||||
continue
|
||||
surf_ob = get_surface_object(ob)
|
||||
flow_ob = get_flow_object(ob)
|
||||
if not surf_ob:
|
||||
if not flow_ob:
|
||||
continue
|
||||
if not surf_ob == context_object:
|
||||
if not flow_ob == context_object:
|
||||
continue
|
||||
bs = settings.context_brushstrokes.add()
|
||||
bs.name = ob.name
|
||||
bs.method = ob['BSBST_method']
|
||||
bs.hide_viewport_base = ob.hide_get()
|
||||
if name_prev == ob.name:
|
||||
idx = len(settings.context_brushstrokes)-1
|
||||
if not settings.context_brushstrokes:
|
||||
settings.edit_toggle = edit_toggle
|
||||
return
|
||||
if context.object:
|
||||
for i, bs in enumerate(settings.context_brushstrokes):
|
||||
if bs.name == context.object.name:
|
||||
settings.silent_switch = True
|
||||
settings.active_context_brushstrokes_index = i
|
||||
settings.silent_switch = False
|
||||
elif len_prev == len(settings.context_brushstrokes):
|
||||
settings.silent_switch = True
|
||||
settings.active_context_brushstrokes_index = idx
|
||||
settings.silent_switch = False
|
||||
|
||||
settings.active_context_brushstrokes_index = max(min(settings.active_context_brushstrokes_index, len(settings.context_brushstrokes)-1), 0)
|
||||
settings.edit_toggle = edit_toggle
|
||||
|
||||
@persistent
|
||||
def refresh_preset(dummy):
|
||||
settings = bpy.context.scene.BSBST_settings
|
||||
|
Loading…
Reference in New Issue
Block a user