Skip to content

Commit 1b6185d

Browse files
committed
Add new blur operator for isolate mode
1 parent aad06a4 commit 1b6185d

File tree

5 files changed

+76
-40
lines changed

5 files changed

+76
-40
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ Copy the value of the 'Src' channel to the uv layer in the 'Dst' layer.
145145
## Misc Operations
146146
The 'Misc Operations' section contains features unrelated to the main features of the addon.
147147

148+
### Blur Channel Values
149+
Blurs the values of all the vertices in the mesh to smooth them out. It uses the smooth weights function available in weight paint mode, but allows it to be used interactively on vertex color channel data.
150+
__Note__: This feature is currently only available when a channel has been isolated.
151+
152+
+ __Factor__ (0.5) - The amount of blur to apply.
153+
154+
+ __Iterations__ (1) - The number of times to apply the blur. Increasing this will result in a smoother blur.
155+
156+
+ __Expand/Contract__ (0.0) - Use this to adjust the balance of dark/light values as the blur is applied. It is similar to brightness/contrast adjustment, or the remap operator.
157+
148158
### Randomize Mesh Island Colors
149159
All separate parts of a mesh (islands), will be assigned random colors based on various randomization parameters.
150160

vertex_color_master/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
bl_info = {
3838
"name": "Vertex Color Master",
3939
"author": "Andrew Palmer (with contributions from Bartosz Styperek)",
40-
"version": (0, 82),
40+
"version": (0, 83),
4141
"blender": (2, 80, 0),
4242
"location": "Vertex Paint | View3D > Vertex Color Master",
4343
"description": "Tools for manipulating vertex color data.",
@@ -65,9 +65,9 @@
6565
vcm_ops.VERTEXCOLORMASTER_OT_IsolateChannel,
6666
vcm_ops.VERTEXCOLORMASTER_OT_ApplyIsolatedChannel,
6767
vcm_ops.VERTEXCOLORMASTER_OT_RandomizeMeshIslandColors,
68-
vcm_ops.VERTEXCOLORMASTER_OT_AdjustHSV,
6968
vcm_ops.VERTEXCOLORMASTER_OT_FlipBrushColors,
7069
vcm_ops.VERTEXCOLORMASTER_OT_Gradient,
70+
vcm_ops.VERTEXCOLORMASTER_OT_BlurChannel,
7171
vcm_menus.VERTEXCOLORMASTER_PT_MainPanel,
7272
vcm_menus.VERTEXCOLORMASTER_MT_PieMain,
7373
)

vertex_color_master/vcm_helpers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def color_to_uvs(mesh, src_vcol, dst_uv, src_u_idx=0, src_v_idx=1):
182182
mesh.update()
183183

184184

185-
def weights_to_color(mesh, src_vgroup_idx, dst_vcol, dst_channel_idx):
185+
def weights_to_color(mesh, src_vgroup_idx, dst_vcol, dst_channel_idx, all_channels=False):
186186
vertex_weights = [0.0] * len(mesh.vertices)
187187

188188
# build list of weights for vertex indices
@@ -193,9 +193,14 @@ def weights_to_color(mesh, src_vgroup_idx, dst_vcol, dst_channel_idx):
193193
break
194194

195195
# copy weights to channel of dst color layer
196-
for loop_index, loop in enumerate(mesh.loops):
197-
weight = vertex_weights[loop.vertex_index]
198-
dst_vcol.data[loop_index].color[dst_channel_idx] = weight
196+
if not all_channels:
197+
for loop_index, loop in enumerate(mesh.loops):
198+
weight = vertex_weights[loop.vertex_index]
199+
dst_vcol.data[loop_index].color[dst_channel_idx] = weight
200+
else:
201+
for loop_index, loop in enumerate(mesh.loops):
202+
weight = vertex_weights[loop.vertex_index]
203+
dst_vcol.data[loop_index].color[:3] = [weight]*3
199204

200205
mesh.update()
201206

vertex_color_master/vcm_menus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ def draw_misc_operations(context, layout, obj, settings, mode='STANDARD', pie=Fa
297297
if mode == 'STANDARD':
298298
row = col.row(align=True)
299299
row.operator('paint.vertex_color_hsv', text="Adjust HSV")
300+
else:
301+
row = col.row(align=True)
302+
row.operator('vertexcolormaster.blur_channel', text="Blur Channel Values")
300303
row = col.row(align=True)
301304
row.operator('vertexcolormaster.randomize_mesh_island_colors', text="Random Mesh Island Colors")
302305
row = col.row(align=True)

vertex_color_master/vcm_ops.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -441,52 +441,70 @@ def execute(self, context):
441441
return {'FINISHED'}
442442

443443

444-
class VERTEXCOLORMASTER_OT_AdjustHSV(bpy.types.Operator):
445-
"""Adjust the Hue, Saturation and Value of the the active vertex colors"""
446-
bl_idname = 'vertexcolormaster.adjust_hsv'
447-
bl_label = 'VCM Adjust HSV'
444+
class VERTEXCOLORMASTER_OT_BlurChannel(bpy.types.Operator):
445+
"""Blur values of a particular channel"""
446+
bl_idname = 'vertexcolormaster.blur_channel'
447+
bl_label = 'VCM Blur Channel'
448448
bl_options = {'REGISTER', 'UNDO'}
449449

450-
colorize: BoolProperty(
451-
name="Colorize",
452-
description="Colorize the mesh instead of adjusting hue.",
453-
default=False
454-
)
450+
factor: FloatProperty(
451+
name="Factor",
452+
description="Amount of blur to apply.",
453+
default=0.5,
454+
min=0.0,
455+
max=1.0
456+
)
455457

456-
hue_adjust: FloatProperty(
457-
name="Hue",
458-
description="Hue adjustment.",
459-
default=0.0,
460-
min=-0.5,
461-
max=0.5
462-
)
458+
iterations: IntProperty(
459+
name="Iterations",
460+
description="Number of iterations to blur values.",
461+
default=1,
462+
min=1,
463+
max=200
464+
)
463465

464-
sat_adjust: FloatProperty(
465-
name="Saturation",
466-
description="Saturation adjustment.",
466+
expand: FloatProperty(
467+
name="Expand/Contract",
468+
description="Alter how the blur affects the distribution of dark/light values.",
467469
default=0.0,
468470
min=-1.0,
469471
max=1.0
470-
)
472+
)
471473

472-
val_adjust: FloatProperty(
473-
name="Value",
474-
description="Value adjustment.",
475-
default=0.0,
476-
min=-1.0,
477-
max=1.0
478-
)
474+
@classmethod
475+
def poll(cls, context):
476+
obj = context.active_object
477+
return bpy.context.object.mode == 'VERTEX_PAINT' and obj is not None and obj.type == 'MESH'
479478

480479
def execute(self, context):
481-
settings = context.scene.vertex_color_master_settings
482-
mesh = context.active_object.data
483-
vcol = mesh.vertex_colors.active
480+
obj = context.active_object
481+
mesh = obj.data
482+
vcol = mesh.vertex_colors.active if mesh.vertex_colors else mesh.vertex_colors.new()
483+
isolate = get_isolated_channel_ids(vcol)
484484

485-
if vcol is None:
486-
self.report({'ERROR'}, "Can't modify HSV when no vertex color data exists.")
487-
return {'FINISHED'}
485+
if isolate is None:
486+
self.report({'ERROR'}, "Blur only works with an isolated channel")
487+
return {'CANCELLED'}
488+
489+
vgroup_id = 'vcm_temp_weights'
490+
vgroup = obj.vertex_groups.new(name=vgroup_id)
491+
obj.vertex_groups.active_index = vgroup.index
492+
493+
channel_idx = channel_id_to_idx(isolate[1])
494+
color_to_weights(obj, vcol, channel_idx, vgroup.index)
495+
496+
bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
497+
bpy.ops.object.vertex_group_smooth(
498+
group_select_mode='ACTIVE',
499+
factor=self.factor,
500+
repeat=self.iterations,
501+
expand=self.expand
502+
)
503+
bpy.ops.object.mode_set(mode='VERTEX_PAINT', toggle=False)
504+
505+
weights_to_color(mesh, vgroup.index, vcol, channel_idx, all_channels=True)
488506

489-
adjust_hsv(mesh, vcol, self.hue_adjust, self.sat_adjust, self.val_adjust, self.colorize)
507+
obj.vertex_groups.remove(vgroup)
490508

491509
return {'FINISHED'}
492510

0 commit comments

Comments
 (0)