Skip to content

Commit

Permalink
Random mesh island colors now works in isolate mode
Browse files Browse the repository at this point in the history
  • Loading branch information
andyp123 committed Apr 21, 2019
1 parent dc951d5 commit aad06a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions vertex_color_master/__init__.py
Expand Up @@ -37,7 +37,7 @@
bl_info = {
"name": "Vertex Color Master",
"author": "Andrew Palmer (with contributions from Bartosz Styperek)",
"version": (0, 81),
"version": (0, 82),
"blender": (2, 80, 0),
"location": "Vertex Paint | View3D > Vertex Color Master",
"description": "Tools for manipulating vertex color data.",
Expand Down Expand Up @@ -90,7 +90,7 @@ def register():
km = wm.keyconfigs.addon.keymaps.new(name='Vertex Paint')
# pie menu
kmi = km.keymap_items.new('wm.call_menu_pie', 'V', 'PRESS')
kmi.properties.name = "vertexcolormaster.pie_main"
kmi.properties.name = "VERTEXCOLORMASTER_MT_PieMain"
kmi.active = True
addon_keymaps.append((km, kmi))
# override 'x' to use VCM flip brush colors
Expand Down
7 changes: 3 additions & 4 deletions vertex_color_master/vcm_menus.py
Expand Up @@ -87,7 +87,7 @@ def draw_isolate_mode_layout(self, context, obj, vcol_id, channel_id, settings):
class VERTEXCOLORMASTER_MT_PieMain(Menu):
# label is displayed at the center of the pie menu.
bl_label = "Vertex Color Master"
bl_idname = "vertexcolormaster.pie_main"
bl_idname = "VERTEXCOLORMASTER_MT_PieMain"

@classmethod
def poll(cls, context):
Expand Down Expand Up @@ -296,11 +296,10 @@ def draw_misc_operations(context, layout, obj, settings, mode='STANDARD', pie=Fa
col = layout.column(align=True)
if mode == 'STANDARD':
row = col.row(align=True)
row.operator('vertexcolormaster.randomize_mesh_island_colors', text="Random Mesh Island Colors")
row = col.row(align=True)
# vertexcolormaster.adjust_hsv is too slow
row.operator('paint.vertex_color_hsv', text="Adjust HSV")
row = col.row(align=True)
row.operator('vertexcolormaster.randomize_mesh_island_colors', text="Random Mesh Island Colors")
row = col.row(align=True)
row.operator('paint.vertex_color_brightness_contrast', text="Brightness/Contrast")
row = col.row(align=True)
row.operator('paint.vertex_color_dirt', text="Dirty Vertex Colors")
Expand Down
38 changes: 26 additions & 12 deletions vertex_color_master/vcm_ops.py
Expand Up @@ -389,28 +389,42 @@ def execute(self, context):
# Used for setting hue with order based color assignment
separationDiff = 1.0 if len(mesh_islands) == 0 else 1.0 / len(mesh_islands)

# If we are in isolate mode, this is used to force greyscale
isolate = get_isolated_channel_ids(context.active_object.data.vertex_colors.active)

for index, island in enumerate(mesh_islands):
color = Color((1, 0, 0)) # (0, 1, 1) HSV

# Determine color based on settings
if self.merge_similar:
face_count = len(island)
if face_count in island_colors.keys():
color = island_colors[face_count]
else:
color.h = random.random() if self.randomize_hue else self.base_hue
color.s = random.random() if self.randomize_saturation else self.base_saturation
color.v = random.random() if self.randomize_value else self.base_value
island_colors[face_count] = color
if isolate is not None:
v = random.random()
color = Color((v, v, v))
island_colors[face_count] = color
else:
color.h = random.random() if self.randomize_hue else self.base_hue
color.s = random.random() if self.randomize_saturation else self.base_saturation
color.v = random.random() if self.randomize_value else self.base_value
island_colors[face_count] = color
else:
if self.order_based:
color.h = index * separationDiff if self.randomize_hue else self.base_hue
color.s = index * separationDiff if self.randomize_saturation else self.base_saturation
color.v = index * separationDiff if self.randomize_value else self.base_value
if isolate is not None:
v = index * separationDiff if self.order_based else random.random()
color = Color((v, v, v))
else:
color.h = random.random() if self.randomize_hue else self.base_hue
color.s = random.random() if self.randomize_saturation else self.base_saturation
color.v = random.random() if self.randomize_value else self.base_value

if self.order_based:
color.h = index * separationDiff if self.randomize_hue else self.base_hue
color.s = index * separationDiff if self.randomize_saturation else self.base_saturation
color.v = index * separationDiff if self.randomize_value else self.base_value
else:
color.h = random.random() if self.randomize_hue else self.base_hue
color.s = random.random() if self.randomize_saturation else self.base_saturation
color.v = random.random() if self.randomize_value else self.base_value

# Set island face colors
for face in island:
for loop in face.loops:
new_color = loop[color_layer]
Expand Down

0 comments on commit aad06a4

Please sign in to comment.