forked from bartvdbraak/blender
BPyMesh_redux: Fixed a rare bug in mesh redux's, collapsed location.
BPyMesh_redux: made redux support non UV Meshes. vertexpaint_selfshadow_ao: turned vertex selfshadow scale into radius.
This commit is contained in:
parent
50a1d9fc8b
commit
2bcf11defb
@ -4,9 +4,11 @@ Ang= Blender.Mathutils.AngleBetweenVecs
|
||||
LineIntersect= Blender.Mathutils.LineIntersect
|
||||
import BPyMesh
|
||||
|
||||
|
||||
#import psyco
|
||||
#psyco.full()
|
||||
try:
|
||||
import psyco
|
||||
psyco.full()
|
||||
except:
|
||||
pass
|
||||
|
||||
def uv_key(uv):
|
||||
return round(uv.x, 5), round(uv.y, 5)
|
||||
@ -42,7 +44,6 @@ def redux(ob, factor=0.5):
|
||||
# Select all verts, de-select as you collapse.
|
||||
for v in me.verts:
|
||||
v.sel=0
|
||||
|
||||
|
||||
# Store new locations for collapsed edges here
|
||||
edge_new_locations= [None] * len(me.edges)
|
||||
@ -249,21 +250,23 @@ def redux(ob, factor=0.5):
|
||||
ed_between= (ed_user.v1.co+ed_user.v2.co) * 0.5
|
||||
v1_scale= ed_between + ((ed_user.v1.co-ed_between) * 100)
|
||||
v2_scale= ed_between + ((ed_user.v2.co-ed_between) * 100)
|
||||
line1x, line2x= LineIntersect(between-nor, between+nor, v1_scale, v2_scale)
|
||||
line_xs= LineIntersect(between-nor, between+nor, v1_scale, v2_scale)
|
||||
if line_xs: # did we intersect? - None if we didnt
|
||||
new_location_count += 1
|
||||
new_location+= line_xs[0]
|
||||
|
||||
new_location_count += 1
|
||||
new_location+= line1x
|
||||
|
||||
if not new_location_count:
|
||||
# Failed to generate a new location or x!=X (NAN)
|
||||
# or, out new location is crazy and further away from the edge center then the edge length.
|
||||
if not new_location_count or\
|
||||
new_location.x!=new_location.x or\
|
||||
(new_location-between).length > (length/2):
|
||||
new_location= between
|
||||
else:
|
||||
new_location= new_location * (1.0/new_location_count)
|
||||
new_location = (new_location + between) * 0.5
|
||||
if new_location.x!=new_location.x:
|
||||
# NAN
|
||||
new_location= between
|
||||
|
||||
# NEW NEW LOCATUON
|
||||
|
||||
# print 'loop', len(me.faces)
|
||||
# Store the collapse location to apply later
|
||||
edge_new_locations[i] = new_location
|
||||
|
||||
|
@ -43,7 +43,7 @@ import BPyMesh
|
||||
# reload(BPyMesh)
|
||||
|
||||
|
||||
def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_CLAMP_CONCAVE, PREF_CLAMP_CONVEX, PREF_SHADOW_ONLY, PREF_SEL_ONLY):
|
||||
def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_RADIUS, PREF_CLAMP_CONCAVE, PREF_CLAMP_CONVEX, PREF_SHADOW_ONLY, PREF_SEL_ONLY):
|
||||
Window.WaitCursor(1)
|
||||
V=Mathutils.Vector
|
||||
M=Mathutils.Matrix
|
||||
@ -98,7 +98,7 @@ def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_CLAMP_CONCAVE,
|
||||
|
||||
|
||||
# BLUR TONE
|
||||
edge_lengths= [ ((ed.v1.co-ed.v2.co).length + 1) / PREF_BLUR_SCALE for ed in me.edges]
|
||||
edge_lengths= [ ed.length for ed in me.edges]
|
||||
|
||||
for i in xrange(PREF_BLUR_ITERATIONS):
|
||||
orig_vert_tone= list(vert_tone)
|
||||
@ -107,14 +107,18 @@ def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_CLAMP_CONCAVE,
|
||||
i2= ed.v2.index
|
||||
l= edge_lengths[ii]
|
||||
|
||||
f=1.0
|
||||
if l < PREF_BLUR_RADIUS:
|
||||
f= l/PREF_BLUR_RADIUS
|
||||
|
||||
len_vert_tone_list_i1 = vert_tone_count[i1]
|
||||
len_vert_tone_list_i2 = vert_tone_count[i2]
|
||||
|
||||
if not len_vert_tone_list_i1: len_vert_tone_list_i1=1
|
||||
if not len_vert_tone_list_i2: len_vert_tone_list_i2=1
|
||||
|
||||
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
|
||||
vert_tone[i1]+= (orig_vert_tone[i2]/len_vert_tone_list_i1)/ f
|
||||
vert_tone[i2]+= (orig_vert_tone[i1]/len_vert_tone_list_i2)/ f
|
||||
|
||||
|
||||
min_tone= min(vert_tone)
|
||||
@ -148,16 +152,16 @@ def main():
|
||||
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_BLUR_ITERATIONS= Draw.Create(1)
|
||||
PREF_BLUR_RADIUS= Draw.Create(0.05)
|
||||
PREF_CLAMP_CONCAVE= Draw.Create(180)
|
||||
PREF_CLAMP_CONVEX= Draw.Create(180)
|
||||
PREF_SHADOW_ONLY= Draw.Create(0)
|
||||
PREF_SEL_ONLY= Draw.Create(0)
|
||||
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).'),\
|
||||
(' Iterations:', PREF_BLUR_ITERATIONS, 0, 40, 'Number times to blur the colors. (higher blurs more)'),\
|
||||
(' Blur Radius:', PREF_BLUR_RADIUS, 0.01, 40.0, 'How much distance effects blur transfur (higher blurs more).'),\
|
||||
'Angle Clipping',\
|
||||
(' Highlight Angle:', PREF_CLAMP_CONVEX, 0, 180, 'Less then 180 limits the angle used in the tonal range.'),\
|
||||
(' Shadow Angle:', PREF_CLAMP_CONCAVE, 0, 180, 'Less then 180 limits the angle used in the tonal range.'),\
|
||||
@ -169,14 +173,14 @@ def main():
|
||||
return
|
||||
|
||||
PREF_BLUR_ITERATIONS= PREF_BLUR_ITERATIONS.val
|
||||
PREF_BLUR_SCALE= PREF_BLUR_SCALE.val
|
||||
PREF_BLUR_RADIUS= PREF_BLUR_RADIUS.val
|
||||
PREF_CLAMP_CONCAVE= PREF_CLAMP_CONCAVE.val
|
||||
PREF_CLAMP_CONVEX= PREF_CLAMP_CONVEX.val
|
||||
PREF_SHADOW_ONLY= PREF_SHADOW_ONLY.val
|
||||
PREF_SEL_ONLY= PREF_SEL_ONLY.val
|
||||
|
||||
#t= sys.time()
|
||||
vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_SCALE, PREF_CLAMP_CONCAVE, PREF_CLAMP_CONVEX, PREF_SHADOW_ONLY, PREF_SEL_ONLY)
|
||||
vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_RADIUS, PREF_CLAMP_CONCAVE, PREF_CLAMP_CONVEX, PREF_SHADOW_ONLY, PREF_SEL_ONLY)
|
||||
#print 'done in %.6f' % (sys.time()-t)
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user