[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12552] trunk/blender: Undoing 'undo' fix 12365, it didn't work the same on mac's, Ton would like to fix the bug himself.

Campbell Barton ideasman42 at gmail.com
Sun Nov 11 16:18:54 CET 2007


Revision: 12552
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12552
Author:   campbellbarton
Date:     2007-11-11 16:18:53 +0100 (Sun, 11 Nov 2007)

Log Message:
-----------
Undoing 'undo' fix 12365, it didn't work the same on mac's, Ton would like to fix the bug himself.

Tree From Curve,
- report error when nurbs or poly curves are used.
- don't throw errors when >4 branch's per segment are used. also try deal with this better. though no nice solution exists.
- default speed is 10x slower then before.

Modified Paths:
--------------
    trunk/blender/release/scripts/wizard_curve2tree.py
    trunk/blender/source/blender/include/BIF_usiblender.h
    trunk/blender/source/blender/python/api2_2x/Blender.c
    trunk/blender/source/blender/src/header_info.c
    trunk/blender/source/blender/src/toets.c
    trunk/blender/source/blender/src/usiblender.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/release/scripts/wizard_curve2tree.py
===================================================================
--- trunk/blender/release/scripts/wizard_curve2tree.py	2007-11-10 21:45:56 UTC (rev 12551)
+++ trunk/blender/release/scripts/wizard_curve2tree.py	2007-11-11 15:18:53 UTC (rev 12552)
@@ -14,11 +14,36 @@
 
 """
 
+# --------------------------------------------------------------------------
+# Tree from Curves v0.1 by Campbell Barton (AKA Ideasman42)
+# --------------------------------------------------------------------------
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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 *****
+# --------------------------------------------------------------------------
+
 import bpy
 import Blender
 from Blender.Mathutils import Vector, CrossVecs, AngleBetweenVecs, LineIntersect, TranslationMatrix, ScaleMatrix
 from Blender.Geometry import ClosestPointOnLine
 
+GLOBALS = {}
+GLOBALS['non_bez_error'] = 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):
@@ -59,11 +84,11 @@
 	best_dist = 100000000
 	for i, vec_test in enumerate(vecls):
 		# Dont use yet, we may want to tho
-		#if vec_test: # Seems odd, but use this so we can disable some verts in the list.
-		dist = (vec-vec_test).length
-		if dist < best_dist:
-			best = i
-			best_dist = dist
+		if vec_test: # Seems odd, but use this so we can disable some verts in the list.
+			dist = (vec-vec_test).length
+			if dist < best_dist:
+				best = i
+				best_dist = dist
 	
 	return best
 
@@ -106,11 +131,21 @@
 		
 		
 		# 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)]
-		radlist = [ [None] for i in xrange(steps+1) ]
+		radlist = [ None for i in xrange(steps+1) ]
 
 
 		for spline in curve:
+			
+			if len(spline) < 2: # Ignore single point splines
+				continue
+			
+			if spline.type != 1: # 0 poly, 1 bez, 4 nurbs
+				GLOBALS['non_bez_error'] = 1
+				continue
+			
+				
 			brch = branch()
 			self.branches_all.append(brch)
 			
@@ -121,15 +156,15 @@
 				bez1_vec = bez1.vec
 				bez2_vec = bez2.vec
 				
-				roll1 = bez1.radius
-				roll2 = bez2.radius
+				radius1 = bez1.radius
+				radius2 = bez2.radius
 				
 				# x,y,z,axis
 				for ii in (0,1,2):
 					forward_diff_bezier(bez1_vec[1][ii], bez1_vec[2][ii],  bez2_vec[0][ii], bez2_vec[1][ii], pointlist, steps, ii)
 				
 				# radius - no axis
-				forward_diff_bezier(roll1, roll1 + 0.390464*(roll2-roll1), roll2 - 0.390464*(roll2-roll1),	roll2,	radlist, steps, None)
+				forward_diff_bezier(radius1, radius1 + 0.390464*(radius2-radius1), radius2 - 0.390464*(radius2-radius1),	radius2,	radlist, steps, None)
 				
 				bpoints = [ bpoint(brch, Vector(pointlist[ii]), Vector(), radlist[ii] * self.limbScale) for ii in xrange(len(pointlist)) ]
 				
@@ -176,7 +211,7 @@
 						#
 						# if 3)	this point is within the branch, remove it.
 						while	len(brch_i.bpoints)>2 and\
-								brch_i.bpoints[0].isParent == False and\
+								brch_i.bpoints[0].childCount == 0 and\
 								(brch_i.bpoints[0].co - pt_best_j.nextMidCo).length < pt_best_j.radius * base_trim:
 							
 							# brch_i.bpoints[0].next = 101 # testing.
@@ -184,7 +219,7 @@
 							brch_i.bpoints[0].prev = None
 						
 						brch_i.parent_pt = pt_best_j
-						pt_best_j.isParent = True # dont remove me
+						pt_best_j.childCount += 1 # dont remove me
 						
 						# addas a member of best_j.children later when we have the geometry info available.
 						
@@ -226,17 +261,16 @@
 					if brch.parent_pt:
 						
 						child_locs = [\
-						brch.parent_pt.childPoint(0),\
-						brch.parent_pt.childPoint(1),\
-						brch.parent_pt.childPoint(2),\
-						brch.parent_pt.childPoint(3)]
+						brch.parent_pt.childPointUnused(0),\
+						brch.parent_pt.childPointUnused(1),\
+						brch.parent_pt.childPointUnused(2),\
+						brch.parent_pt.childPointUnused(3)]
 						
 						best_idx = closestVecIndex(brch.bpoints[0].co, child_locs)
 						
 						# Crap! we alredy have a branch here, this is hard to solve nicely :/
 						# Probably the best thing to do here is attach this branch to the base of the one thats alredy there
 						# For even 
-						
 						if brch.parent_pt.children[best_idx]:
 							# Todo - some fun trick! to get the join working.
 							pass
@@ -476,7 +510,9 @@
 							pt.faces[i].smooth = True
 							face_index +=1
 			
-			self.mesh.faceUV = True
+			if self.mesh.faces:
+				self.mesh.faceUV = True
+			
 			for brch in self.branches_all:
 				
 				y_val = 0.0
@@ -560,7 +596,7 @@
 		for i, brch in enumerate(self.branches_all):
 			
 			# get a list of parent points to make into bones. use parents and endpoints
-			bpoints_parent = [pt for pt in brch.bpoints if pt.isParent or pt.prev == None or pt.next == None]
+			bpoints_parent = [pt for pt in brch.bpoints if pt.childCount or pt.prev == None or pt.next == None]
 			bpbone_last = None
 			for j in xrange(len(bpoints_parent)-1):
 				
@@ -648,7 +684,7 @@
 		# print ipo_dict
 		
 		# Sicne its per frame, it increases very fast. scale it down a bit
-		anim_speed = anim_speed/10
+		anim_speed = anim_speed/100
 		
 		# When we have the same trees next to eachother, they will animate the same way unless we give each its own texture or offset settings.
 		# We can use the object's location as a factor - this also will have the advantage? of seeing the animation move across the tree's
@@ -667,10 +703,6 @@
 				pt = self.branches_all[ lookup[0] ].bpoints[ lookup[1] ]
 				anim_speed_final = anim_speed / (1+pt.radius)
 			
-			#for cu in ipo:
-			#	#cu.delBezier(0) 
-			#	#cu.driver = 2 # Python expression
-			#	#cu.driverExpression = 'b.Get("curframe")/100.0'
 			cu = ipo[Blender.Ipo.PO_QUATX]
 			try:	cu.delBezier(0) 
 			except:	pass
@@ -689,10 +721,11 @@
 			cu.driver = 2 # Python expression
 			cu.driverExpression = '%.3f*(%s.evaluate((%.3f,%.3f,(b.Get("curframe")*%.3f)+%.3f)).w-0.5)' % (anim_magnitude, tex_str,  anim_offset.x, anim_offset.y, anim_speed_final, anim_offset.z)
 			
-			
 			#(%s.evaluate((b.Get("curframe")*%.3f,0,0)).w-0.5)*%.3f
 		
 		
+xup = Vector(1,0,0)
+yup = Vector(0,1,0)
 zup = Vector(0,0,1)
 
 class bpoint_bone:
@@ -705,7 +738,7 @@
 class bpoint(object):
 	''' The point in the middle of the branch, not the mesh points
 	'''
-	__slots__ = 'branch', 'co', 'no', 'radius', 'vecs', 'verts', 'children', 'faces', 'next', 'prev', 'isParent', 'bpbone', 'roll_angle', 'nextMidCo', 'childrenMidCo', 'childrenMidRadius', 'targetCos'
+	__slots__ = 'branch', 'co', 'no', 'radius', 'vecs', 'verts', 'children', 'faces', 'next', 'prev', 'childCount', 'bpbone', 'roll_angle', 'nextMidCo', 'childrenMidCo', 'childrenMidRadius', 'targetCos'
 	def __init__(self, brch, co, no, radius):
 		self.branch = brch
 		self.co = co
@@ -717,7 +750,7 @@
 		self.faces = [None, None, None, None]
 		self.next = None
 		self.prev = None
-		self.isParent = False
+		self.childCount = 0
 		self.bpbone = None # bpoint_bone instance
 		
 		# when set, This is the angle we need to roll to best face our branches
@@ -901,7 +934,7 @@
 		'''
 		
 		# self.next.next == None check is so we dont shorten the final length of branches.
-		if self.next == None or self.next.next == None or self.isParent or self.next.isParent:
+		if self.next == None or self.next.next == None or self.childCount or self.next.childCount:
 			return False
 		
 		self.branch.bpoints.remove(self.next)
@@ -918,7 +951,7 @@
 		'''
 		
 		# self.next.next == None check is so we dont shorten the final length of branches.
-		if self.prev == None or self.prev.prev == None or self.prev.isParent or self.prev.prev.isParent:
+		if self.prev == None or self.prev.prev == None or self.prev.childCount or self.prev.prev.childCount:
 			return False
 		
 		self.branch.bpoints.remove(self.prev)
@@ -937,7 +970,7 @@
 		if self.next == None or self.prev == None:
 			return False
 		
-		if self.isParent or self.prev.isParent:
+		if self.childCount or self.prev.childCount:
 			factor = factor_joint;
 		
 		if factor==0.0:
@@ -977,6 +1010,15 @@
 		if index == 2:	return (self.getAbsVec(2) + self.next.getAbsVec(3)) / 2
 		if index == 3:	return (self.getAbsVec(3) + self.next.getAbsVec(0)) / 2
 	
+	def childPointUnused(self, index):
+		'''
+		Same as above but return None when the point is alredy used.
+		'''
+		if self.children[index]:
+			return None
+		return self.childPoint(index)
+		
+	
 	def roll(self, angle):
 		'''
 		Roll the quad about its normal 
@@ -1030,8 +1072,16 @@
 			if self.branch.parent_pt:
 				cross = CrossVecs(self.no, self.branch.getParentFaceCent() - self.branch.parent_pt.getAbsVec( self.branch.getParentQuadIndex() ))
 			else:
-				# parentless branch
-				cross = zup
+				# parentless branch - for best results get a cross thats not the same as the normal, in rare cases this happens.
+				
+				# Was just doing 
+				#  cross = zup
+				# which works most of the time, but no verticle lines
+				
+				if AngleBetweenVecs(self.no, zup) > 1.0:	cross = zup
+				elif AngleBetweenVecs(self.no, yup) > 1.0:	cross = yup
+				else:										cross = xup
+				
 		else:
 			cross = CrossVecs(self.prev.vecs[0], self.no)
 		
@@ -1044,7 +1094,7 @@
 	
 	def hasChildren(self):
 		'''
-		Use .isParent where possible, this does the real check
+		Use .childCount where possible, this does the real check
 		'''
 		if self.children.count(None) == 4:
 			return False
@@ -1086,14 +1136,22 @@
 		The angle off we are from our parent quad,
 		'''
 		# used to roll the parent so its faces us better
+		
+		# Warning this can be zero sometimes, see the try below for the error

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list