Fix T43345: Dirty Vertex Colors - odd behavior

was cancelling when the dynamic range was zero, but gave odd behavior,
using the last value, not the values from the UI.
This commit is contained in:
Campbell Barton
2015-01-26 22:38:59 +11:00
parent 027361c898
commit b648ba4103

View File

@@ -27,11 +27,9 @@
def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only): def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only):
from mathutils import Vector from mathutils import Vector
from math import acos from math import acos
import array
vert_tone = [0.0] * len(me.vertices) vert_tone = array.array("f", [0.0]) * len(me.vertices)
min_tone = 180.0
max_tone = 0.0
# create lookup table for each vertex's connected vertices (via edges) # create lookup table for each vertex's connected vertices (via edges)
con = [] con = []
@@ -74,7 +72,7 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
# blur tones # blur tones
for i in range(blur_iterations): for i in range(blur_iterations):
# backup the original tones # backup the original tones
orig_vert_tone = list(vert_tone) orig_vert_tone = vert_tone[:]
# use connected verts look up for blurring # use connected verts look up for blurring
for j, c in enumerate(con): for j, c in enumerate(con):
@@ -82,20 +80,18 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
vert_tone[j] += blur_strength * orig_vert_tone[v] vert_tone[j] += blur_strength * orig_vert_tone[v]
vert_tone[j] /= len(c) * blur_strength + 1 vert_tone[j] /= len(c) * blur_strength + 1
del orig_vert_tone
min_tone = min(vert_tone) min_tone = min(vert_tone)
max_tone = max(vert_tone) max_tone = max(vert_tone)
# debug information
# print(min_tone * 2 * math.pi)
# print(max_tone * 2 * math.pi)
# print(clamp_clean)
# print(clamp_dirt)
tone_range = max_tone - min_tone tone_range = max_tone - min_tone
if not tone_range: if tone_range < 0.0001:
return {'CANCELLED'} # weak, don't cancel, see T43345
tone_range = 0.0
else:
tone_range = 1.0 / tone_range
active_col_layer = None active_col_layer = None
@@ -112,7 +108,6 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
return {'CANCELLED'} return {'CANCELLED'}
use_paint_mask = me.use_paint_mask use_paint_mask = me.use_paint_mask
for i, p in enumerate(me.polygons): for i, p in enumerate(me.polygons):
if not use_paint_mask or p.select: if not use_paint_mask or p.select:
for loop_index in p.loop_indices: for loop_index in p.loop_indices:
@@ -120,11 +115,10 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
v = loop.vertex_index v = loop.vertex_index
col = active_col_layer[loop_index].color col = active_col_layer[loop_index].color
tone = vert_tone[v] tone = vert_tone[v]
tone = (tone - min_tone) / tone_range tone = (tone - min_tone) * tone_range
if dirt_only: if dirt_only:
tone = min(tone, 0.5) tone = min(tone, 0.5) * 2.0
tone *= 2.0
col[0] = tone * col[0] col[0] = tone * col[0]
col[1] = tone * col[1] col[1] = tone * col[1]
@@ -187,10 +181,6 @@ class VertexPaintDirt(Operator):
obj = context.object obj = context.object
mesh = obj.data mesh = obj.data
t = time.time()
ret = applyVertexDirt(mesh, self.blur_iterations, self.blur_strength, self.dirt_angle, self.clean_angle, self.dirt_only) ret = applyVertexDirt(mesh, self.blur_iterations, self.blur_strength, self.dirt_angle, self.clean_angle, self.dirt_only)
print('Dirt calculated in %.6f' % (time.time() - t))
return ret return ret