[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24260] trunk/blender/release/scripts/io/ vertexpaint_dirt.py: update from Keith Boshoff, use selected faces while in face-mask mode as well as some other cleanup
Campbell Barton
ideasman42 at gmail.com
Mon Nov 2 21:18:05 CET 2009
Revision: 24260
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24260
Author: campbellbarton
Date: 2009-11-02 21:18:05 +0100 (Mon, 02 Nov 2009)
Log Message:
-----------
update from Keith Boshoff, use selected faces while in face-mask mode as well as some other cleanup
Modified Paths:
--------------
trunk/blender/release/scripts/io/vertexpaint_dirt.py
Modified: trunk/blender/release/scripts/io/vertexpaint_dirt.py
===================================================================
--- trunk/blender/release/scripts/io/vertexpaint_dirt.py 2009-11-02 19:37:18 UTC (rev 24259)
+++ trunk/blender/release/scripts/io/vertexpaint_dirt.py 2009-11-02 20:18:05 UTC (rev 24260)
@@ -1,7 +1,3 @@
-# bl_author = ["Campbell Barton aka ideasman42", "Keith Boshoff aka Wahooney"]
-# bl_url = ["www.blender.org", "blenderartists.org", "www.python.org"]
-# bl_version = "0.2"
-
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) Campbell J Barton
@@ -25,6 +21,8 @@
# History
#
+# Originally written by Campbell Barton aka ideasman42
+#
# 2009-11-01: * 2.5 port by Keith "Wahooney" Boshoff
# * Replaced old method with my own, speed is similar (about 0.001 sec on Suzanne)
# but results are far more accurate
@@ -38,20 +36,21 @@
from Mathutils import Vector
from bpy.props import *
-def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only, sel_only):
+def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only):
## Window.WaitCursor(1)
#BPyMesh.meshCalcNormals(me)
- vert_tone= [0.0] * len(me.verts)
- vert_tone_count= [0] * len(me.verts)
+ vert_tone = [0.0] * len(me.verts)
+ min_tone =180.0
+ max_tone =0.0
+
# create lookup table for each vertex's connected vertices (via edges)
+ con = []
+
con = [[] for i in range(len(me.verts))]
- min_tone=180.0
- max_tone=0.0
-
# add connected verts
for e in me.edges:
con[e.verts[0]].append(e.verts[1])
@@ -73,64 +72,56 @@
ang = math.acos(no.dot(vec))
# enforce min/max
+ ang = max(clamp_dirt, ang)
- vert_tone[v.index] = max(clamp_clean, min(clamp_dirt, ang))
+ if not dirt_only:
+ ang = min(clamp_clean, ang)
- # average vert_tone_list into vert_tonef
-# for i, tones in enumerate(vert_tone):
-# if vert_tone_count[i]:
-# vert_tone[i] = vert_tone[i] / vert_tone_count[i]
+ vert_tone[v.index] = ang
- # Below we use edges to blur along so the edges need counting, not the faces
- vert_tone_count= [0] * len(me.verts)
- for ed in me.edges:
- vert_tone_count[ed.verts[0]] += 1
- vert_tone_count[ed.verts[1]] += 1
-
-
- # Blur tone
- blur = blur_strength
- blur_inv = 1.0 - blur_strength
-
+ # blur tones
for i in range(blur_iterations):
-
# backup the original tones
- orig_vert_tone= list(vert_tone)
+ orig_vert_tone = list(vert_tone)
- for ed in me.edges:
+ # use connected verts look up for blurring
+ for j, c in enumerate(con):
+ for v in c:
+ vert_tone[j] += blur_strength * orig_vert_tone[v]
- i1 = ed.verts[0]
- i2 = ed.verts[1]
+ vert_tone[j] /= len(c) * blur_strength + 1
- val1 = (orig_vert_tone[i2]*blur) + (orig_vert_tone[i1]*blur_inv)
- val2 = (orig_vert_tone[i1]*blur) + (orig_vert_tone[i2]*blur_inv)
+ min_tone = min(vert_tone)
+ max_tone = max(vert_tone)
- # Apply the ton divided by the number of faces connected
- vert_tone[i1] += val1 / max(vert_tone_count[i1], 1)
- vert_tone[i2] += val2 / max(vert_tone_count[i2], 1)
+ # 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
- min_tone= min(vert_tone)
- max_tone= max(vert_tone)
-
- print(min_tone)
- print(max_tone)
- print(clamp_clean)
- print(clamp_dirt)
-
- tone_range= max_tone-min_tone
- if max_tone==min_tone:
+ if not tone_range:
return
- for lay in me.vertex_colors:
- if lay.active:
- active_col_layer = lay.data
+ active_col_layer = None
+ if len(me.vertex_colors):
+ for lay in me.vertex_colors:
+ if lay.active:
+ active_col_layer = lay.data
+ else:
+ bpy.ops.mesh.vertex_color_add()
+ me.vertex_colors[0].active = True
+ active_col_layer = me.vertex_colors[0].data
+
if not active_col_layer:
- return('CANCELLED', )
+ return("CANCELLED", )
for i, f in enumerate(me.faces):
- if not sel_only or f.sel:
+ if not me.use_paint_mask or f.selected:
+
f_col = active_col_layer[i]
f_col = [f_col.color1, f_col.color2, f_col.color3, f_col.color4]
@@ -140,49 +131,47 @@
tone = vert_tone[me.verts[v].index]
tone = (tone-min_tone)/tone_range
+ if dirt_only:
+ tone = min(tone, 0.5)
+ tone *= 2
+
col[0] = tone*col[0]
col[1] = tone*col[1]
col[2] = tone*col[2]
## Window.WaitCursor(0)
-
class VertexPaintDirt(bpy.types.Operator):
- '''This script uses the concavity of vertices to shade the mesh, and optionaly blur the shading to remove artifacts from spesific edges.'''
bl_idname = "mesh.vertex_paint_dirt"
bl_label = "Dirty Vertex Colors"
bl_register = True
bl_undo = True
- blur_strength = FloatProperty(name="Blur Strength", description="Blur strength per iteration", default=1.0, min=0.01, max=1.0)
- blur_iterations = IntProperty(name="Blur Iterations", description="Number times to blur the colors. (higher blurs more)", default=1, min=0, max=40)
- clean_angle = FloatProperty(name="Highlight Angle", description="Less then 90 limits the angle used in the tonal range", default=0.0, min=0.0, max=180.0)
- dirt_angle = FloatProperty(name="Dirt Angle", description="Less then 90 limits the angle used in the tonal range", default=180.0, min=0.0, max=180.0)
- dirt_only = BoolProperty(name="Dirt Only", description="Dont calculate cleans for convex areas", default=False)
- sel_faces_only = BoolProperty(name="Selected Faces Only", description="Only apply to UV/Face selected faces (mix vpain/uvface select)", default=False)
+ blur_strength = FloatProperty(name = "Blur Strength", description = "Blur strength per iteration", default = 1.0, min = 0.01, max = 1.0)
+ blur_iterations = IntProperty(name = "Blur Iterations", description = "Number times to blur the colors. (higher blurs more)", default = 1, min = 0, max = 40)
+ clean_angle = FloatProperty(name = "Highlight Angle", description = "Less then 90 limits the angle used in the tonal range", default = 180.0, min = 0.0, max = 180.0)
+ dirt_angle = FloatProperty(name = "Dirt Angle", description = "Less then 90 limits the angle used in the tonal range", default = 0.0, min = 0.0, max = 180.0)
+ dirt_only = BoolProperty(name= "Dirt Only", description = "Dont calculate cleans for convex areas", default = False)
def execute(self, context):
- sce= context.scene
- ob= context.object
+ sce = context.scene
+ ob = context.object
if not ob or ob.type != 'MESH':
print('Error, no active mesh object, aborting.')
- print(ob)
- print(ob.type)
return('CANCELLED',)
me = ob.data
t = time.time()
- applyVertexDirt(me, self.blur_iterations, self.blur_strength, math.radians(self.dirt_angle), math.radians(self.clean_angle), self.dirt_only, self.sel_faces_only)
+ applyVertexDirt(me, self.blur_iterations, self.blur_strength, math.radians(self.dirt_angle), math.radians(self.clean_angle), self.dirt_only)
- print('done in %.6f' % (time.time()-t))
+ print('Dirt calculated in %.6f' % (time.time()-t))
return('FINISHED',)
-
bpy.ops.add(VertexPaintDirt)
if __name__ == "__main__":
More information about the Bf-blender-cvs
mailing list