[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12688] trunk/blender/release/scripts/ wizard_curve2tree.py: * Improved Fill Twigs, they now join to make a continues skin like other branches.
Campbell Barton
ideasman42 at gmail.com
Tue Nov 27 12:57:18 CET 2007
Revision: 12688
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12688
Author: campbellbarton
Date: 2007-11-27 12:57:18 +0100 (Tue, 27 Nov 2007)
Log Message:
-----------
* Improved Fill Twigs, they now join to make a continues skin like other branches.
* Improved dupli-leaf placement - (should be good enough to use for final renders)
Modified Paths:
--------------
trunk/blender/release/scripts/wizard_curve2tree.py
Modified: trunk/blender/release/scripts/wizard_curve2tree.py
===================================================================
--- trunk/blender/release/scripts/wizard_curve2tree.py 2007-11-27 11:17:52 UTC (rev 12687)
+++ trunk/blender/release/scripts/wizard_curve2tree.py 2007-11-27 11:57:18 UTC (rev 12688)
@@ -41,10 +41,17 @@
import BPyMesh
from Blender.Mathutils import Vector, Matrix, CrossVecs, AngleBetweenVecs, LineIntersect, TranslationMatrix, ScaleMatrix, RotationMatrix, Rand
from Blender.Geometry import ClosestPointOnLine
+from Blender.Noise import randuvec
GLOBALS = {}
GLOBALS['non_bez_error'] = 0
+def AngleBetweenVecsSafe(a1, a2):
+ try:
+ return AngleBetweenVecs(a1,a2)
+ except:
+ return 180.0
+
# Copied from blender, we could wrap this! - BKE_curve.c
# But probably not toooo bad in python
def forward_diff_bezier(q0, q1, q2, q3, pointlist, steps, axis):
@@ -146,6 +153,10 @@
eul = 0.00001
+BRANCH_TYPE_CURVE = 0
+BRANCH_TYPE_GROWN = 1
+BRANCH_TYPE_FILL = 2
+
class tree:
def __init__(self):
self.branches_all = []
@@ -214,6 +225,8 @@
brch = branch()
+ brch.type = BRANCH_TYPE_CURVE
+
self.branches_all.append(brch)
bez_list = list(spline)
@@ -221,13 +234,15 @@
bez1 = bez_list[i-1]
bez2 = bez_list[i]
points_from_bezier_seg(self.steps, pointlist, radlist, bez1.vec, bez2.vec, bez1.radius, bez2.radius)
- bpoints = [ bpoint(brch, Vector(pointlist[ii]), Vector(), radlist[ii] * self.limbScale) for ii in xrange(len(pointlist)) ]
+
+
# remove endpoint for all but the last
+ len_pointlist = len(pointlist)
if i != len(bez_list)-1:
- bpoints.pop()
+ len_pointlist -= 1
- brch.bpoints.extend(bpoints)
+ brch.bpoints.extend([ bpoint(brch, Vector(pointlist[ii]), Vector(), radlist[ii] * self.limbScale) for ii in xrange(len_pointlist) ])
# Finalize once point data is there
brch.calcData()
@@ -653,6 +668,8 @@
'''
+ rnd = [1]
+
segments_all = []
segments_level = []
@@ -706,9 +723,10 @@
if twig_fill_shape_rand==0.0:
return (parentCo + ch1Co + ch2Co) / 3.0
else:
- w1 = Rand(0.0, twig_fill_shape_rand) + (1-twig_fill_shape_rand)
- w2 = Rand(0.0, twig_fill_shape_rand) + (1-twig_fill_shape_rand)
- w3 = Rand(0.0, twig_fill_shape_rand) + (1-twig_fill_shape_rand)
+
+ w1 = (next_random_num(rnd)*twig_fill_shape_rand) + (1-twig_fill_shape_rand)
+ w2 = (next_random_num(rnd)*twig_fill_shape_rand) + (1-twig_fill_shape_rand)
+ w3 = (next_random_num(rnd)*twig_fill_shape_rand) + (1-twig_fill_shape_rand)
wtot = w1+w2+w3
w1=w1/wtot
w2=w2/wtot
@@ -739,9 +757,30 @@
self.brothers = []
self.no = Vector() # only endpoints have these
- self.id = len(segments_all)
- self.bpt = None # branch point for root segs only
+ # self.id = len(segments_all)
+ # First value is the bpoint,
+ # Second value is what to do -
+ # 0 - dont join
+ # 1 - Join to parent (tree point)
+ # 2 - join to parent, point from another fill-twig branch we just created.
+
+ self.bpt = (None, False) # branch point for root segs only
+ self.new_bpt = None
+
+ self.used = False # use this to tell if we are apart of a branch
+
+ def sibling(self):
+ i = self.parent.children.index(self)
+
+ if i == 0:
+ return self.parent.children[ 1 ]
+ elif i == 1:
+ return self.parent.children[ 0 ]
+ else:
+ raise "error"
+
+
def getHeadHandle(self):
"""
For Bezier only
@@ -803,7 +842,9 @@
for seg_child in self.children:
seg_child.calcLevelFromRoot()
-
+
+ # Dont use for now, but scale worked, transform was never tested.
+ """
def transform(self, matrix):
self.headCo = self.headCo * matrix
self.tailCo = self.tailCo * matrix
@@ -829,13 +870,14 @@
if self.children:
self.children[0].scale(scale, cent)
self.children[1].scale(scale, cent)
-
+ """
def recalcChildLoc(self):
if not self.children:
return
ch1 = self.children[0]
ch2 = self.children[1]
new_mid = mergeCo(self.headCo, ch1.tailCo, ch2.tailCo, twig_fill_shape_rand)
+
self.tailCo[:] = ch1.headCo[:] = ch2.headCo[:] = new_mid
ch1.recalcChildLoc()
@@ -845,14 +887,41 @@
"""
Merge other into self and make a new segment
"""
+ """
+ seg_child = segment(self.levelFromLeaf)
+ self.levelFromLeaf += 1
+ seg_child.parent = other.parent = self
+
+ # No need, recalcChildLoc sets the other coords
+ #self.parent.tailCo = (self.headCo + self.tailCo + other.tailCo) / 3.0
+ #self.parent.headCo[:] = self.headCo
+
+ seg_child.headCo[:] = self.headCo
+
+ # isect = LineIntersect(self.headCo, self.tailCo, other.headCo, other.tailCo)
+ # new_head = (isect[0]+isect[1]) * 0.5
+
+ seg_child.mergeCount += 1
+ other.mergeCount += 1
+
+ self.children.extend([ seg_child, other ])
+
+ self.recalcChildLoc()
+
+ # print 'merging', self.id, other.id
+ """
+
#new_head = (self.headCo + self.tailCo + other.headCo + other.tailCo) * 0.25
+
self.parent = other.parent = segment(self.levelFromLeaf + 1)
- self.parent.tailCo = (self.headCo + self.tailCo + other.tailCo) / 3.0
+ # No need, recalcChildLoc sets the self.parent.tailCo
+ # self.parent.tailCo = (self.headCo + self.tailCo + other.tailCo) / 3.0
+
self.parent.headCo[:] = self.headCo
self.parent.bpt = self.bpt
- self.bpt = None
+ self.bpt = (None, False)
# isect = LineIntersect(self.headCo, self.tailCo, other.headCo, other.tailCo)
# new_head = (isect[0]+isect[1]) * 0.5
@@ -865,6 +934,7 @@
self.parent.recalcChildLoc()
# print 'merging', self.id, other.id
+
def findBestMerge(self, twig_fill_fork_angle_max):
# print "findBestMerge"
if self.parent != None:
@@ -903,7 +973,7 @@
def getLength(self):
return (self.headCo - self.tailCo).length
-
+ """
def toMatrix(self, LEAF_SCALE, LEAF_RANDSCALE, LEAF_RANDVEC):
if LEAF_RANDSCALE: scale = LEAF_SCALE * Rand(1.0-LEAF_RANDSCALE, 1.0+LEAF_RANDSCALE)
else: scale = LEAF_SCALE * 1.0
@@ -912,7 +982,7 @@
else: rand_vec = Vector( )
return Matrix([scale,0,0],[0,scale,0],[0,0,scale]).resize4x4() * (self.no + rand_vec).toTrackQuat('x', 'z').toMatrix().resize4x4() * TranslationMatrix(self.tailCo)
-
+ """
def distripute_seg_on_mesh(me__, face_group):
"""
add segment endpoints
@@ -941,7 +1011,7 @@
# Dont need to return anything, added when created.
- def find_leaf_attach_point(seg, interior_points, twig_fill_rand_scale):
+ def set_seg_attach_point(seg, interior_points, twig_fill_rand_scale):
"""
Can only run on end nodes that have normals set
"""
@@ -952,7 +1022,7 @@
for pt in interior_points:
# line from the point to the seg endpoint
- line_normal = seg.tailCo - pt.co
+ line_normal = seg.tailCo - pt.nextMidCo
l = line_normal.length
cross1 = CrossVecs( seg.no, line_normal )
@@ -969,19 +1039,33 @@
if l < best_dist:
best_pt = pt
- best_co = pt.co.copy()
+ best_co = pt.nextMidCo
best_dist = l
-
+
# twig_fill_rand_scale
seg.headCo = best_co.copy()
if twig_fill_rand_scale:
seg_dir = seg.tailCo - seg.headCo
- seg_dir.length = seg_dir.length * ( 1.0 - Rand(0.0, twig_fill_rand_scale) )
+
+ seg_dir.length = seg_dir.length * ( 1.0 - (next_random_num(rnd)*twig_fill_rand_scale) )
seg.tailCo = seg.headCo + seg_dir
- seg.bpt = best_pt
+
+ if best_pt.childCount < 4:
+ # Watch this!!! adding a user before its attached and the branch is created!
+ # make sure if its not added later on, this isnt left added
+ best_pt.childCount += 1
+
+ # True/False denotes weather we try to connect to our parent branch
+ seg.bpt = (best_pt, True)
+ else:
+ seg.bpt = (best_pt, False)
+
+ return True
+
+
# END Twig code, next add them
@@ -1010,9 +1094,10 @@
break # no need to check new branches are inside us
for pt in brch.bpoints:
- if self_tree.isPointInTwigBounds(pt.co, True): # selected_only
- interior_points.append(pt)
- interior_normal += pt.no * pt.radius
+ if pt.next and pt.childCount < 4: # cannot attach to the last points
+ if self_tree.isPointInTwigBounds(pt.co, True): # selected_only
+ interior_points.append(pt)
+ interior_normal += pt.no * pt.radius
segments_all[:] = []
segments_level[:] = []
@@ -1022,7 +1107,8 @@
distripute_seg_on_mesh( self_tree.objectTwigBoundsMesh, face_group )
for seg in segments_level[0]: # only be zero segments
- find_leaf_attach_point(seg, interior_points, twig_fill_rand_scale)
+ # Warning, increments the child count for bpoints we attach to!!
+ set_seg_attach_point(seg, interior_points, twig_fill_rand_scale)
# Try sorting by other properties! this is ok for now
for segments_level_current in segments_level:
@@ -1041,25 +1127,20 @@
for seg in segments_level[level+1]:
seg.calcBrothers()
- # Randomize scale recursively
- # This way sucks, just randomize starting lengths
- """
- if twig_fill_rand_scale != 0.0: # 0.0 - 1.0
- for seg in segments_all:
- #if seg.levelFromLeaf == 0:
- if 1:
- sca = 1.0 + Rand(-twig_fill_rand_scale, twig_fill_rand_scale)
- # print sca, 'SCALE'
- seg.scale(sca)
- """
-
for seg in segments_all:
if seg.parent == None:
seg.levelFromRoot = 0
seg.calcLevelFromRoot()
- for i, seg in enumerate(segments_all):
+ '''
+ for i, seg in enumerate(segments_all):
+ # Make a branch from this data!
+ brch = branch()
+ brch.type = BRANCH_TYPE_FILL
+ self_tree.branches_all.append(brch)
+
+ # ============================= do this per bez pair
# 1 is the base and 2 is the tail
#p1_h1 = seg.getHeadHandle()
@@ -1070,26 +1151,28 @@
p2_co = seg.tailCo.copy()
#p2_h2 = seg.getTailHandle() # isnt used
- # Make a branch from this data!
- brch = branch()
- self_tree.branches_all.append(brch)
-
- # ============================= do this per bez pair
bez1_vec = (None, p1_co, p1_h2)
bez2_vec = (p2_h1, p2_co, None)
seg_root = seg.getRootSeg()
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list