Brushstroke Tools: Initial Version #328
@ -495,6 +495,46 @@ class BSBST_OT_select_surface(bpy.types.Operator):
|
|||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class BSBST_OT_assign_surface(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Assign a surface object for the active context brushstrokes.
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.assign_surface"
|
||||||
|
bl_label = "Assign Surface"
|
||||||
|
bl_description = "Assign a surface object for the active context brushstrokes"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
surface_object: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
return bool(settings.context_brushstrokes)
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
bs_ob = utils.get_active_context_brushstrokes_object(context)
|
||||||
|
if not bs_ob:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
surface_object = bpy.data.objects.get(self.surface_object)
|
||||||
|
|
||||||
|
if not surface_object:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
utils.set_surface_object(bs_ob, surface_object)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.prop_search(self, 'surface_object', bpy.data, 'objects')
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
bs_ob = utils.get_active_context_brushstrokes_object(context)
|
||||||
|
surf_ob = utils.get_surface_object(bs_ob)
|
||||||
|
if surf_ob:
|
||||||
|
self.surface_object = surf_ob.name
|
||||||
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
def set_brushstrokes_deformable(bs_ob, deformable):
|
def set_brushstrokes_deformable(bs_ob, deformable):
|
||||||
flow_ob = utils.get_flow_object(bs_ob)
|
flow_ob = utils.get_flow_object(bs_ob)
|
||||||
|
|
||||||
@ -1039,6 +1079,7 @@ classes = [
|
|||||||
BSBST_OT_copy_flow,
|
BSBST_OT_copy_flow,
|
||||||
BSBST_OT_switch_deformable,
|
BSBST_OT_switch_deformable,
|
||||||
BSBST_OT_select_surface,
|
BSBST_OT_select_surface,
|
||||||
|
BSBST_OT_assign_surface,
|
||||||
BSBST_OT_init_preset,
|
BSBST_OT_init_preset,
|
||||||
BSBST_OT_make_preset,
|
BSBST_OT_make_preset,
|
||||||
BSBST_OT_preset_add_mod,
|
BSBST_OT_preset_add_mod,
|
||||||
|
@ -300,6 +300,8 @@ class BSBST_MT_bs_context_menu(bpy.types.Menu):
|
|||||||
|
|
||||||
op = layout.operator('brushstroke_tools.copy_flow')
|
op = layout.operator('brushstroke_tools.copy_flow')
|
||||||
|
|
||||||
|
op = layout.operator("brushstroke_tools.assign_surface")
|
||||||
|
|
||||||
class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
|
class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
|
||||||
bl_space_type = 'VIEW_3D'
|
bl_space_type = 'VIEW_3D'
|
||||||
bl_region_type = 'UI'
|
bl_region_type = 'UI'
|
||||||
|
@ -458,27 +458,34 @@ def get_surface_object(bs):
|
|||||||
return None
|
return None
|
||||||
return bs['BSBST_surface_object']
|
return bs['BSBST_surface_object']
|
||||||
|
|
||||||
def set_surface_object(bs, ob):
|
def set_surface_object(bs, surf_ob):
|
||||||
if not bs:
|
if not bs:
|
||||||
return
|
return
|
||||||
|
objects = [bs]
|
||||||
|
flow_ob = get_flow_object(bs)
|
||||||
|
if flow_ob:
|
||||||
|
objects += [flow_ob]
|
||||||
# assign surface pointer
|
# assign surface pointer
|
||||||
for mod in bs.modifiers:
|
for ob in objects:
|
||||||
mod_info = bs.modifier_info.get(mod.name)
|
for mod in bs.modifiers:
|
||||||
if not mod_info:
|
mod_info = bs.modifier_info.get(mod.name)
|
||||||
continue
|
if not mod_info:
|
||||||
for s in mod_info.socket_info:
|
|
||||||
if not s.link_context:
|
|
||||||
continue
|
continue
|
||||||
if not s.link_context_type == 'SURFACE_OBJECT':
|
for s in mod_info.socket_info:
|
||||||
continue
|
if not s.link_context:
|
||||||
mod[s.name] = ob
|
continue
|
||||||
ob.update_tag()
|
if not s.link_context_type == 'SURFACE_OBJECT':
|
||||||
|
continue
|
||||||
|
mod[s.name] = surf_ob
|
||||||
|
ob.parent = surf_ob
|
||||||
|
ob.parent_type = 'OBJECT'
|
||||||
|
surf_ob.update_tag()
|
||||||
|
|
||||||
if bs.type == 'CURVES':
|
if bs.type == 'CURVES':
|
||||||
bs.data.surface = ob
|
bs.data.surface = surf_ob
|
||||||
bs.data.surface_uv_map = ob.data.uv_layers.active.name
|
bs.data.surface_uv_map = surf_ob.data.uv_layers.active.name
|
||||||
|
|
||||||
bs['BSBST_surface_object'] = ob
|
bs['BSBST_surface_object'] = surf_ob
|
||||||
|
|
||||||
def get_flow_object(bs):
|
def get_flow_object(bs):
|
||||||
if not bs:
|
if not bs:
|
||||||
|
Loading…
Reference in New Issue
Block a user