Brushstroke Tools: Initial Version #328
@ -1,6 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import random
|
import random
|
||||||
from . import utils
|
from . import utils
|
||||||
|
import mathutils
|
||||||
|
|
||||||
class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
||||||
""" Create new object according to method and type.
|
""" Create new object according to method and type.
|
||||||
@ -155,6 +156,27 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
|||||||
# transfer modifier info data from preset to brush strokes
|
# transfer modifier info data from preset to brush strokes
|
||||||
utils.deep_copy_mod_info(settings.preset_object, brushstrokes_object)
|
utils.deep_copy_mod_info(settings.preset_object, brushstrokes_object)
|
||||||
|
|
||||||
|
# estimate dimensions
|
||||||
|
|
||||||
|
if settings.estimate_dimensions:
|
||||||
|
bb_min = mathutils.Vector(surface_object.bound_box[0])
|
||||||
|
bb_max = mathutils.Vector(surface_object.bound_box[6])
|
||||||
|
bb_radius = mathutils.Vector([abs(co) for co in bb_max-bb_min]).length * 0.5
|
||||||
|
|
||||||
|
surf_est = 4 * 3.142 * bb_radius**2
|
||||||
|
|
||||||
|
mod = brushstrokes_object.modifiers['Brushstrokes']
|
||||||
|
if settings.brushstroke_method == 'SURFACE_FILL':
|
||||||
|
# set density
|
||||||
|
mod['Socket_7'] = utils.round_n(1000 / surf_est, 2)
|
||||||
|
# set length
|
||||||
|
mod['Socket_11'] = utils.round_n(bb_radius * 0.5, 2)
|
||||||
|
# set width
|
||||||
|
mod['Socket_13'] = utils.round_n(bb_radius * 0.05, 2)
|
||||||
|
elif settings.brushstroke_method == 'SURFACE_DRAW':
|
||||||
|
# set width
|
||||||
|
mod['Socket_5'] = utils.round_n(bb_radius * 0.05, 2)
|
||||||
|
|
||||||
# refresh UI
|
# refresh UI
|
||||||
for mod in brushstrokes_object.modifiers:
|
for mod in brushstrokes_object.modifiers:
|
||||||
mod.node_group.interface_update(context)
|
mod.node_group.interface_update(context)
|
||||||
|
@ -231,6 +231,9 @@ class BSBST_Settings(bpy.types.PropertyGroup):
|
|||||||
edit_toggle: bpy.props.BoolProperty(default=True,
|
edit_toggle: bpy.props.BoolProperty(default=True,
|
||||||
name='Edit Active Brushstrokes',
|
name='Edit Active Brushstrokes',
|
||||||
description="Jump into the corresponding edit mode when selecting/creating a brushstrokes layer")
|
description="Jump into the corresponding edit mode when selecting/creating a brushstrokes layer")
|
||||||
|
estimate_dimensions: bpy.props.BoolProperty(default=True,
|
||||||
|
name='Estimate Dimensions',
|
||||||
|
description="Estimate the length, width and distribution density of the brush strokes based on the bounding box to provide a reasonable starting point regardless of scale")
|
||||||
|
|
||||||
classes = [
|
classes = [
|
||||||
BSBST_socket_info,
|
BSBST_socket_info,
|
||||||
|
@ -187,6 +187,7 @@ class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
|
|||||||
|
|
||||||
new_advanced_panel.prop(settings, 'assign_materials')
|
new_advanced_panel.prop(settings, 'assign_materials')
|
||||||
new_advanced_panel.prop(settings, 'reuse_flow')
|
new_advanced_panel.prop(settings, 'reuse_flow')
|
||||||
|
new_advanced_panel.prop(settings, 'estimate_dimensions')
|
||||||
new_advanced_panel.prop(settings, 'style_context')
|
new_advanced_panel.prop(settings, 'style_context')
|
||||||
|
|
||||||
# identify style context
|
# identify style context
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.app.handlers import persistent
|
from bpy.app.handlers import persistent
|
||||||
|
import math
|
||||||
|
|
||||||
ng_list = [
|
ng_list = [
|
||||||
".brushstroke_tools.processing",
|
".brushstroke_tools.processing",
|
||||||
@ -281,6 +282,11 @@ def edit_active_brushstrokes(context):
|
|||||||
bpy.ops.wm.tool_set_by_id(name="brushstroke_tools.draw")
|
bpy.ops.wm.tool_set_by_id(name="brushstroke_tools.draw")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def round_n(val, n):
|
||||||
|
""" Round value to n number of significant digits.
|
||||||
|
"""
|
||||||
|
return round(val, n-int(math.floor(math.log10(abs(val))))-1)
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user