Fix T76041: Low contrast dirty vertex colors with loose geometry

Add option to normalize vertex colors.
This commit is contained in:
Philipp Oeser 2020-06-17 13:32:45 +10:00 committed by Campbell Barton
parent f9be5374ac
commit 3ff9769762
1 changed files with 20 additions and 10 deletions

View File

@ -32,7 +32,7 @@ def get_vcolor_layer_data(me):
return lay.data
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, normalize):
from mathutils import Vector
from math import acos
import array
@ -74,14 +74,14 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
tot_con = len(con[i])
if tot_con == 0:
continue
ang = pi / 2.0 # assume 90°, i. e. flat
else:
vec /= tot_con
vec /= tot_con
# angle is the acos() of the dot product between normal and connected verts.
# > 90 degrees: convex
# < 90 degrees: concave
ang = acos(no.dot(vec))
# angle is the acos() of the dot product between normal and connected verts.
# > 90 degrees: convex
# < 90 degrees: concave
ang = acos(no.dot(vec))
# enforce min/max
ang = max(clamp_dirt, ang)
@ -104,8 +104,12 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
vert_tone[j] /= len(c) * blur_strength + 1
del orig_vert_tone
min_tone = min(vert_tone)
max_tone = max(vert_tone)
if normalize:
min_tone = min(vert_tone)
max_tone = max(vert_tone)
else:
min_tone = clamp_dirt
max_tone = clamp_clean
tone_range = max_tone - min_tone
@ -181,6 +185,11 @@ class VertexPaintDirt(Operator):
description="Don't calculate cleans for convex areas",
default=False,
)
normalize: BoolProperty(
name="Normalize",
description="Normalize the colors, increasing the contrast",
default=True,
)
@classmethod
def poll(cls, context):
@ -198,6 +207,7 @@ class VertexPaintDirt(Operator):
self.dirt_angle,
self.clean_angle,
self.dirt_only,
self.normalize,
)
return ret