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
Notes: blender-bot 2023-02-14 09:35:29 +01:00
Referenced by issue #43345, Dirty Vertex Colors - incoherent behavior
1 changed files with 11 additions and 21 deletions

View File

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