[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12609] trunk/blender: * wizard_curve2tree .py - Automatic alpha blended, textured image joins using material textures and UV layers.
Campbell Barton
ideasman42 at gmail.com
Fri Nov 16 15:47:31 CET 2007
Revision: 12609
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12609
Author: campbellbarton
Date: 2007-11-16 15:47:31 +0100 (Fri, 16 Nov 2007)
Log Message:
-----------
* wizard_curve2tree.py - Automatic alpha blended, textured image joins using material textures and UV layers. Also added some detail options and made it easier to get low poly results.
* Mesh.c bugfix, "mesh.verts = None" didn't set the mesh->mselect pointer to NULL, wizard_curve2tree so would crash when in editmode.
* Texture.py - MTex.uvlayer doc was missing
* buttons_shading.c - Stencil tooltip was stupid.
Modified Paths:
--------------
trunk/blender/release/scripts/wizard_curve2tree.py
trunk/blender/source/blender/python/api2_2x/Mesh.c
trunk/blender/source/blender/python/api2_2x/doc/Texture.py
trunk/blender/source/blender/src/buttons_shading.c
Modified: trunk/blender/release/scripts/wizard_curve2tree.py
===================================================================
--- trunk/blender/release/scripts/wizard_curve2tree.py 2007-11-16 14:41:07 UTC (rev 12608)
+++ trunk/blender/release/scripts/wizard_curve2tree.py 2007-11-16 14:47:31 UTC (rev 12609)
@@ -79,6 +79,24 @@
Blender.Window.RedrawAll()
print 'debugging', co
+def freshMesh(mesh):
+ '''
+ Utility function to get a new mesh or clear the existing one, but dont clear everything.
+ '''
+ if mesh:
+ materials = mesh.materials
+ mesh.verts = None
+ for group in mesh.getVertGroupNames():
+ mesh.removeVertGroup(group)
+
+ # Add materials back
+ mesh.materials = materials
+ else:
+ mesh = bpy.data.meshes.new()
+
+ return mesh
+
+
def closestVecIndex(vec, vecls):
best= -1
best_dist = 100000000
@@ -134,7 +152,6 @@
# self.limbScale = (bb[0] - bb[7]).length / 2.825 # THIS IS GOOD WHEN NON SUBSURRFED
self.limbScale = (bb[0] - bb[7]).length / 1.8
-
# forward_diff_bezier will fill in the blanks
# nice we can reuse these for every curve segment :)
pointlist = [[None, None, None] for i in xrange(steps+1)]
@@ -211,13 +228,13 @@
twig_random_orientation = 180,\
twig_random_angle = 33,\
twig_recursive=True,\
+ twig_recursive_limit=3,\
twig_ob_bounds=None,\
twig_ob_bounds_prune=True,\
twig_ob_bounds_prune_taper=True,\
):
'''
build tree data - fromCurve must run first
-
'''
# Sort the branchs by the first radius, so big branchs get joins first
@@ -285,6 +302,9 @@
if twig_ob_bounds: # Only spawn twigs inside this mesh
self.setTwigBounds(twig_ob_bounds)
+ if not twig_recursive:
+ twig_recursive_limit = 0
+
self.buildTwigs(twig_ratio)
branches_twig_attached = []
@@ -303,8 +323,8 @@
branches_twig_sort.sort() # this will sort the branches with best braches for adding twigs to at the start of the list
for tmp_sortval, twig_pt_index, brch_parent in branches_twig_sort: # tmp_sortval is not used.
-
- if twig_pt_index != -1:
+ if twig_pt_index != -1 and (twig_recursive_limit==0 or brch_parent.generation <= twig_recursive_limit):
+
if brch_twig_index >= len(self.branches_twigs):
break
@@ -364,9 +384,9 @@
# we would not have been but here if the bounds were outside
if twig_ob_bounds_prune:
brch_twig.boundsTrim()
-
if twig_ob_bounds_prune_taper:
# taper to a point. we could use some nice taper algo here - just linear atm.
+
brch_twig.taper()
# Make sure this dosnt mess up anything else
@@ -375,8 +395,9 @@
# Add to the branches
#self.branches_all.append(brch_twig)
- if len(brch_twig.bpoints) > 4:
+ if len(brch_twig.bpoints) > 2:
branches_twig_attached.append(brch_twig)
+ brch_twig.generation = brch_parent.generation + 1
else:
# Dont add the branch
parent_pt.childCount -= 1
@@ -437,7 +458,7 @@
print None
'''
- def optimizeSpacing(self, density=1.0, joint_compression=1.0, joint_smooth=1.0):
+ def optimizeSpacing(self, seg_density=0.5, seg_density_angle=20.0, seg_density_radius=0.3, joint_compression=1.0, joint_smooth=1.0):
'''
Optimize spacing, taking branch hierarchy children into account,
can add or subdivide segments so branch joins dont look horrible.
@@ -452,7 +473,7 @@
# Collapsing
for brch in self.branches_all:
- brch.collapsePoints(density, joint_smooth)
+ brch.collapsePoints(seg_density, seg_density_angle, seg_density_radius, joint_smooth)
for brch in self.branches_all:
brch.branchReJoin()
@@ -514,25 +535,8 @@
- def toMesh(self, mesh=None, do_uv=True, do_uv_keep_vproportion=True, do_uv_uscale=False, uv_image = None, uv_x_scale=1.0, uv_y_scale=4.0, do_cap_ends=False):
- # Simple points
- '''
- self.mesh = bpy.data.meshes.new()
- self.objectCurve = bpy.data.scenes.active.objects.new(self.mesh)
- self.mesh.verts.extend([ pt.co for brch in self.branches_all for pt in brch.bpoints ])
- '''
- if mesh:
- self.mesh = mesh
- materials = mesh.materials
- mesh.verts = None
- for group in mesh.getVertGroupNames():
- mesh.removeVertGroup(group)
-
- # Add materials back
- mesh.materials = materials
- else:
- self.mesh = bpy.data.meshes.new()
-
+ def toMesh(self, mesh=None, do_uv=True, do_uv_keep_vproportion=True, do_uv_vnormalize=False, do_uv_uscale=False, uv_image = None, uv_x_scale=1.0, uv_y_scale=4.0, do_uv_blend_layer= False, do_cap_ends=False):
+ self.mesh = freshMesh(mesh)
totverts = 0
for brch in self.branches_all:
@@ -669,20 +673,37 @@
for pt in brch.bpoints:
pt.toMesh(self.mesh)
- faces = self.mesh.faces
- faces_extend = [ face for brch in self.branches_all for pt in brch.bpoints for face in pt.faces if face ]
+ #faces_extend = [ face for brch in self.branches_all for pt in brch.bpoints for face in pt.faces if face ]
+
+
+
+ faces_extend = []
+ for brch in self.branches_all:
+ if brch.parent_pt:
+ faces_extend.extend(brch.faces)
+ for pt in brch.bpoints:
+ for face in pt.faces:
+ if face:
+ faces_extend.append(face)
+
if do_cap_ends:
# TODO - UV map and image?
faces_extend.extend([ brch.bpoints[-1].verts for brch in self.branches_all ])
-
- faces.extend(faces_extend)
+ faces = self.mesh.faces
+ faces.extend(faces_extend)
if do_uv:
# Assign the faces back
face_index = 0
for brch in self.branches_all:
+ if brch.parent_pt:
+ for i in (0,1,2,3):
+ face = brch.faces[i] = faces[face_index+i]
+ face.smooth = 1
+ face_index +=4
+
for pt in brch.bpoints:
for i in (0,1,2,3):
if pt.faces[i]:
@@ -690,9 +711,13 @@
pt.faces[i].smooth = True
face_index +=1
- if self.mesh.faces:
- self.mesh.faceUV = True
+ #if self.mesh.faces:
+ # self.mesh.faceUV = True
+ mesh.addUVLayer( 'base' )
+ # rename the uv layer
+ #mesh.renameUVLayer(mesh.getUVLayerNames()[0], 'base')
+
for brch in self.branches_all:
uv_x_scale_branch = 1.0
@@ -703,41 +728,162 @@
uv_x_scale_branch = uv_x_scale_branch / len(brch.bpoints)
# uv_x_scale_branch = brch.bpoints[0].radius
+
+ if do_uv_vnormalize:
+ uv_normalize = []
+
+ def uvmap_faces(my_faces, y_val, y_size):
+ '''
+ Accept a branch or pt faces
+ '''
+ uv_ls = [None, None, None, None]
+ for i in (0,1,2,3):
+ if my_faces[i]:
+ if uv_image:
+ my_faces[i].image = uv_image
+ uvs = my_faces[i].uv
+ else:
+ # Use these for calculating blending values
+ uvs = [Vector(0,0), Vector(0,0), Vector(0,0), Vector(0,0)]
+
+ uv_ls[i] = uvs
+
+ x1 = i*0.25 * uv_x_scale * uv_x_scale_branch
+ x2 = (i+1)*0.25 * uv_x_scale * uv_x_scale_branch
+
+ uvs[3].x = x1;
+ uvs[3].y = y_val+y_size
+
+ uvs[0].x = x1
+ uvs[0].y = y_val
+
+ uvs[1].x = x2
+ uvs[1].y = y_val
+
+ uvs[2].x = x2
+ uvs[2].y = y_val+y_size
+
+ if do_uv_vnormalize:
+ uv_normalize.extend(uvs)
+ return uv_ls
+
+ # Done uvmap_faces
y_val = 0.0
+
+ if brch.parent_pt:
+ y_size = (brch.getParentFaceCent() - brch.bpoints[0].co).length
+
+ if do_uv_keep_vproportion:
+ y_size = y_size / ((brch.bpoints[0].radius + brch.parent_pt.radius)/2) * uv_y_scale
+
+ brch.uv = uvmap_faces(brch.faces, 0.0, y_size)
+
+ y_val += y_size
+
for pt in brch.bpoints:
if pt.next:
y_size = (pt.co-pt.next.co).length
-
# scale the uvs by the radius, avoids stritching.
if do_uv_keep_vproportion:
y_size = y_size / pt.radius * uv_y_scale
+ pt.uv = uvmap_faces(pt.faces, y_val, y_size)
+ y_val += y_size
+
+
+ if do_uv_vnormalize and uv_normalize:
+ # Use yscale here so you can choose to have half the normalized value say.
+ vscale = (1/uv_normalize[-1].y) * uv_y_scale
+ for uv in uv_normalize:
+ uv.y *= vscale
+
+
+
+ # Done with UV mapping the first layer! now map the blend layers
+ if do_uv_blend_layer:
+
+
+
+ # Set up the blend UV layer - this is simply the blending for branch joints
+ mesh.addUVLayer( 'blend' )
+ mesh.activeUVLayer = 'blend'
+
+ # Set all faces to be on full blend
+ for f in mesh.faces:
+ for uv in f.uv:
+ uv.y = uv.x = 0.0
+
+ for brch in self.branches_all:
+ if brch.parent_pt:
+ for f in brch.faces:
+ if f:
+ uvs = f.uv
+ uvs[0].x = uvs[1].x = uvs[2].x = uvs[3].x = 0.0
+ uvs[0].y = uvs[1].y = 1.0 # swap these? - same as inverting the blend
+ uvs[2].y = uvs[3].y = 0.0
+
+ # Set up the join UV layer, this overlays nice blended
+ mesh.addUVLayer( 'join' )
+ mesh.activeUVLayer = 'join'
+
+ # Set all faces to be on full blend
+ for f in mesh.faces:
+ for uv in f.uv:
+ uv.y = uv.x = 0.0
+
+ for brch in self.branches_all:
+ if brch.parent_pt:
+ # The UV's that this branch would cover if it was a face,
+ uvs_base = brch.parent_pt.uv[brch.getParentQuadIndex()]
- for i in (0,1,2,3):
- if pt.faces[i]:
- if uv_image:
- pt.faces[i].image = uv_image
-
- uvs = pt.faces[i].uv
-
- x1 = i*0.25 * uv_x_scale * uv_x_scale_branch
- x2 = (i+1)*0.25 * uv_x_scale * uv_x_scale_branch
-
- uvs[3].x = x1;
- uvs[3].y = y_val+y_size
-
- uvs[0].x = x1
- uvs[0].y = y_val
-
- uvs[1].x = x2
- uvs[1].y = y_val
-
- uvs[2].x = x2
- uvs[2].y = y_val+y_size
+ uvs_base_mid = Vector(0,0)
+ for uv in uvs_base:
+ uvs_base_mid += uv
+
+ uvs_base_mid *= 0.25
- if pt.next:
- y_val += y_size
+ # TODO - Factor scale and distance in here
+ ## uvs_base_small = [(uv+uvs_base_mid)*0.5 for uv in uvs_base]
+ uvs_base_small = [uvs_base_mid, uvs_base_mid, uvs_base_mid, uvs_base_mid]
+
+ if brch.faces[0]:
+ f = brch.faces[0]
+ uvs = f.uv
+ uvs[0][:] = uvs_base[0]
+ uvs[1][:] = uvs_base[1]
+
+ uvs[2][:] = uvs_base_small[1]
+ uvs[3][:] = uvs_base_small[0]
+
+ if brch.faces[1]:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list