Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2006-05-07 18:09:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-05-07 18:09:46 +0400
commit8255bdce574283df7f04ccb24c607c1e45d956e9 (patch)
treefa107fd10bd495907b186a6f2e239365d904b7fe /release/scripts/vertexpaint_selfshadow_ao.py
parentbb52e70c8a3688263af01bc9d2eda3d5e5f077bc (diff)
Added a self shadowing script accessed from the vertex paint menu, it does a fake ao thats more pradictable then radio baking and fairly fast.
Also assed a function to calculate high quality normals (normals are the same even for different topologys).
Diffstat (limited to 'release/scripts/vertexpaint_selfshadow_ao.py')
-rw-r--r--release/scripts/vertexpaint_selfshadow_ao.py173
1 files changed, 173 insertions, 0 deletions
diff --git a/release/scripts/vertexpaint_selfshadow_ao.py b/release/scripts/vertexpaint_selfshadow_ao.py
new file mode 100644
index 00000000000..7f5219f7f8a
--- /dev/null
+++ b/release/scripts/vertexpaint_selfshadow_ao.py
@@ -0,0 +1,173 @@
+#!BPY
+"""
+Name: 'Self Shadow VCols (AO)...'
+Blender: 241
+Group: 'VertexPaint'
+Tooltip: 'Generate Fake Ambient Occlusion with vertex colors.'
+"""
+
+__author__ = ["Campbell Barton"]
+__url__ = ("blender", "elysiun", "http://members.iinet.net.au/~cpbarton/ideasman/")
+__version__ = "0.1"
+__bpydoc__ = """\
+
+Clean Weight
+
+This Script is to be used only in weight paint mode,
+It removes very low weighted verts from the current group with a weight option.
+"""
+
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# Script copyright (C) Campbell J Barton
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+# --------------------------------------------------------------------------
+
+from Blender import *
+import BPyMesh
+reload(BPyMesh)
+
+
+def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_SEL_ONLY):
+
+ V=Mathutils.Vector
+ M=Mathutils.Matrix
+ Ang= Mathutils.AngleBetweenVecs
+
+ nos= BPyMesh.meshPrettyNormals(me)
+
+ vert_tone= [0.0] * len(me.verts)
+ vert_tone_list= [ [] for i in xrange(len(me.verts)) ]
+ ed_face_users = [ [] for i in xrange(len(me.edges)) ]
+
+ fcent= [BPyMesh.faceCent(f) for f in me.faces]
+
+ min_tone=0
+ max_tone=0
+
+ for i, f in enumerate(me.faces):
+ c= fcent[i]
+ fno = f.no*0.0001
+ for v in f.v:
+ #vno=v.no # ugly normal
+ vno= nos[v.index]*0.0001 # pretty notrmal
+
+ l1= (c-v.co).length
+ l2= ((c+fno) - (v.co+vno)).length
+
+ if abs(l1-l2) < 0.0000001:
+ vert_tone_list[v.index].append(0)
+ continue # look at the next vert
+
+ elif l1<l2: # face is facing away from the vert normal
+ convex=1
+ #if v.sel: print "convex"
+ a= Ang(vno, fno)
+ else: # l1>l2
+ convex=-1# concave, darken.
+ #if v.sel: print "concave"
+ a= -Ang(vno, fno)
+
+ #a= Ang(vno, fno) * convex
+
+ #vert_tone[v.index] += a
+ vert_tone_list[v.index].append(a)
+
+
+ # average vert_tone_list into vert_tone
+ for i, tones in enumerate(vert_tone_list):
+ if tones:
+ tone= 0.0
+ for t in tones:
+ tone+=t
+ tone= tone/len(tones)
+
+ vert_tone[i]= tone
+
+
+
+ # BLUR TONE
+ edge_lengths= [ ((ed.v1.co-ed.v2.co).length + 1) * PREF_BLUR_SCALE for ed in me.edges]
+
+ for i in xrange(PREF_BLUR_ITERATIONS):
+ orig_vert_tone= list(vert_tone)
+ for ii, ed in enumerate(me.edges):
+ i1= ed.v1.index
+ i2= ed.v2.index
+ l= edge_lengths[ii]
+
+ vert_tone[i1]+= (orig_vert_tone[i2]/len(vert_tone_list[i1]))/ l
+ vert_tone[i2]+= (orig_vert_tone[i1]/len(vert_tone_list[i2]))/ l
+
+
+ min_tone= min(vert_tone)
+ max_tone= max(vert_tone)
+
+ #print 'min', min_tone, 'max', max_tone
+
+ tone_range= max_tone-min_tone
+ if max_tone==min_tone:
+ return
+ SELFLAG= Mesh.FaceFlags.SELECT
+ for f in me.faces:
+ if not PREF_SEL_ONLY or f.flag & SELFLAG:
+ for i, v in enumerate(f.v):
+ tone= vert_tone[v.index]
+ tone= tone-min_tone
+ tone= (tone/tone_range)
+
+ tone= int(tone*255)
+ f.col[i].r= f.col[i].g= f.col[i].b= tone
+
+
+def main():
+ scn= Scene.GetCurrent()
+ ob= scn.getActiveObject()
+
+ if not ob or ob.getType() != 'Mesh':
+ Draw.PupMenu('Error, no active mesh object, aborting.')
+ return
+
+ me= ob.getData(mesh=1)
+
+ if not me.faceUV:
+ Draw.PupMenu('Error, The active mesh does not have texface/vertex colors. aborting')
+ return
+
+ PREF_BLUR_ITERATIONS= Draw.Create(0)
+ PREF_BLUR_SCALE= Draw.Create(1.0)
+ PREF_SEL_ONLY= Draw.Create(1)
+ pup_block= [\
+ 'Post AO Blur',\
+ (' Iterations:', PREF_BLUR_ITERATIONS, 1, 40, 'Number times to blur the colors. (higher blurs more)'),\
+ (' Blur Radius:', PREF_BLUR_SCALE, 0.1, 10.0, 'How much distance effects blur transfur (higher blurs more).'),\
+ ('Sel Faces Only', PREF_SEL_ONLY, 'Only apply to UV/Face selected faces (mix vpain/uvface select).'),\
+ ]
+
+ if not Draw.PupBlock('Clean Selected Meshes...', pup_block):
+ return
+
+ PREF_BLUR_ITERATIONS= PREF_BLUR_ITERATIONS.val
+ PREF_BLUR_SCALE= PREF_BLUR_SCALE.val
+ PREF_SEL_ONLY= PREF_SEL_ONLY.val
+
+ vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_SEL_ONLY)
+
+if __name__=='__main__':
+ main()
+