[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12620] branches/pynodes: merge r12572: 12616 from trunk

Nathan Letwory jesterking at letwory.net
Mon Nov 19 06:06:59 CET 2007


Revision: 12620
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12620
Author:   jesterking
Date:     2007-11-19 06:06:59 +0100 (Mon, 19 Nov 2007)

Log Message:
-----------
merge r12572:12616 from trunk

Modified Paths:
--------------
    branches/pynodes/intern/ghost/intern/GHOST_SystemWin32.cpp
    branches/pynodes/release/scripts/wizard_curve2tree.py
    branches/pynodes/source/Makefile
    branches/pynodes/source/blender/blenkernel/BKE_lattice.h
    branches/pynodes/source/blender/blenkernel/BKE_node.h
    branches/pynodes/source/blender/blenkernel/bad_level_call_stubs/stubs.c
    branches/pynodes/source/blender/blenkernel/intern/armature.c
    branches/pynodes/source/blender/blenkernel/intern/constraint.c
    branches/pynodes/source/blender/blenkernel/intern/modifier.c
    branches/pynodes/source/blender/blenkernel/intern/object.c
    branches/pynodes/source/blender/blenkernel/intern/softbody.c
    branches/pynodes/source/blender/blenkernel/intern/texture.c
    branches/pynodes/source/blender/blenloader/intern/readfile.c
    branches/pynodes/source/blender/blenloader/intern/writefile.c
    branches/pynodes/source/blender/include/BSE_sequence.h
    branches/pynodes/source/blender/makesdna/DNA_armature_types.h
    branches/pynodes/source/blender/makesdna/DNA_material_types.h
    branches/pynodes/source/blender/makesdna/DNA_modifier_types.h
    branches/pynodes/source/blender/makesdna/DNA_object_force.h
    branches/pynodes/source/blender/makesdna/DNA_sequence_types.h
    branches/pynodes/source/blender/nodes/intern/CMP_nodes/CMP_scale.c
    branches/pynodes/source/blender/nodes/intern/CMP_nodes/CMP_texture.c
    branches/pynodes/source/blender/python/api2_2x/Mesh.c
    branches/pynodes/source/blender/python/api2_2x/doc/Texture.py
    branches/pynodes/source/blender/python/api2_2x/sceneSequence.c
    branches/pynodes/source/blender/render/extern/include/RE_shader_ext.h
    branches/pynodes/source/blender/render/intern/source/rayshade.c
    branches/pynodes/source/blender/render/intern/source/shadeinput.c
    branches/pynodes/source/blender/render/intern/source/shadeoutput.c
    branches/pynodes/source/blender/render/intern/source/texture.c
    branches/pynodes/source/blender/src/buttons_editing.c
    branches/pynodes/source/blender/src/buttons_object.c
    branches/pynodes/source/blender/src/buttons_shading.c
    branches/pynodes/source/blender/src/drawarmature.c
    branches/pynodes/source/blender/src/drawimage.c
    branches/pynodes/source/blender/src/drawnode.c
    branches/pynodes/source/blender/src/drawobject.c
    branches/pynodes/source/blender/src/drawseq.c
    branches/pynodes/source/blender/src/drawtime.c
    branches/pynodes/source/blender/src/editarmature.c
    branches/pynodes/source/blender/src/editipo.c
    branches/pynodes/source/blender/src/editmesh_lib.c
    branches/pynodes/source/blender/src/editseq.c
    branches/pynodes/source/blender/src/headerbuttons.c
    branches/pynodes/source/blender/src/interface_panel.c
    branches/pynodes/source/blender/src/outliner.c
    branches/pynodes/source/blender/src/poseobject.c
    branches/pynodes/source/blender/src/sequence.c
    branches/pynodes/source/blender/src/transform_conversions.c
    branches/pynodes/source/blender/src/transform_generics.c
    branches/pynodes/source/creator/buildinfo.c
    branches/pynodes/source/creator/creator.c
    branches/pynodes/source/gameengine/Converter/BL_SkinDeformer.cpp
    branches/pynodes/tools/Blender.py

Modified: branches/pynodes/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/pynodes/intern/ghost/intern/GHOST_SystemWin32.cpp	2007-11-19 00:27:25 UTC (rev 12619)
+++ branches/pynodes/intern/ghost/intern/GHOST_SystemWin32.cpp	2007-11-19 05:06:59 UTC (rev 12620)
@@ -54,7 +54,7 @@
 #define WM_MOUSEWHEEL 0x020A
 #endif // WM_MOUSEWHEEL
 #ifndef WHEEL_DELTA
-#define WHEEL_DELTA 120	/* Value for rolling one detent */
+#define WHEEL_DELTA 120	/* Value for rolling one detent, (old convention! MS changed it) */
 #endif // WHEEL_DELTA
 
 
@@ -479,7 +479,11 @@
 {
 	// short fwKeys = LOWORD(wParam);			// key flags
 	int zDelta = (short) HIWORD(wParam);	// wheel rotation
-	zDelta /= WHEEL_DELTA;
+	
+	// zDelta /= WHEEL_DELTA;
+	// temporary fix below: microsoft now has added more precision, making the above division not work
+	if (zDelta <= 0 ) zDelta= -1; else zDelta= 1;	
+	
 	// short xPos = (short) LOWORD(lParam);	// horizontal position of pointer
 	// short yPos = (short) HIWORD(lParam);	// vertical position of pointer
 	return new GHOST_EventWheel (getSystem()->getMilliSeconds(), window, zDelta);

Modified: branches/pynodes/release/scripts/wizard_curve2tree.py
===================================================================
--- branches/pynodes/release/scripts/wizard_curve2tree.py	2007-11-19 00:27:25 UTC (rev 12619)
+++ branches/pynodes/release/scripts/wizard_curve2tree.py	2007-11-19 05:06:59 UTC (rev 12620)
@@ -38,7 +38,7 @@
 
 import bpy
 import Blender
-from Blender.Mathutils import Vector, CrossVecs, AngleBetweenVecs, LineIntersect, TranslationMatrix, ScaleMatrix
+from Blender.Mathutils import Vector, Matrix, CrossVecs, AngleBetweenVecs, LineIntersect, TranslationMatrix, ScaleMatrix, RotationMatrix, Rand
 from Blender.Geometry import ClosestPointOnLine
 
 GLOBALS = {}
@@ -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
@@ -98,9 +116,14 @@
 	def __init__(self):
 		self.branches_all =		[]
 		self.branches_root =	[]
+		self.branches_twigs =	[]
 		self.mesh = None
 		self.armature = None
-		self.object = None
+		self.objectCurve = None
+		self.objectCurveMat = None
+		self.objectTwigBounds = None # use for twigs only at the moment.
+		self.objectTwigBoundsIMat = None
+		self.objectTwigBoundsMesh = None
 		self.limbScale = 1.0
 		
 		self.debug_objects = []
@@ -109,16 +132,17 @@
 		s = ''
 		s += '[Tree]'
 		s += '  limbScale: %.6f' % self.limbScale
-		s += '  object: %s' % self.object
+		s += '  object: %s' % self.objectCurve
 		
 		for brch in self.branches_root:
 			s += str(brch)
 		return s
 	
-	def fromCurve(self, object):
+	def fromCurve(self, objectCurve):
 		# Now calculate the normals
-		self.object = object
-		curve = object.data
+		self.objectCurve = objectCurve
+		self.objectCurveMat = objectCurve.matrixWorld
+		curve = objectCurve.data
 		steps = curve.resolu # curve resolution
 		
 		# Set the curve object scale
@@ -128,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)]
@@ -162,7 +185,7 @@
 				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
+				# radius - no axis, Copied from blenders BBone roll interpolation.
 				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)) ]
@@ -172,24 +195,52 @@
 					bpoints.pop()
 				
 				brch.bpoints.extend(bpoints)
-		
+			
+			# Finalize once point data is there
+			brch.calcData()
+			
 		# Sort from big to small, so big branches get priority
 		self.branches_all.sort( key = lambda brch: -brch.bpoints[0].radius )
 		
-		for i, brch in enumerate(self.branches_all):
-			brch.calcPointLinkedList()
-			brch.calcPointExtras()
-			# brch.myindex = i
+	def setTwigBounds(self, objectMesh):
+		self.objectTwigBounds = objectMesh
+		self.objectTwigBoundsMesh = objectMesh.getData(mesh=1)
+		self.objectTwigBoundsIMat = objectMesh.matrixWorld.copy().invert()
+		#self.objectTwigBoundsIMat = objectMesh.matrixWorld.copy()
 		
-		
+		for brch in self.branches_all:
+			brch.calcTwigBounds(self)
+	
+	def isPointInTwigBounds(self, co):
+		return self.objectTwigBoundsMesh.pointInside(co * self.objectCurveMat * self.objectTwigBoundsIMat)
+	
 	def resetTags(self, value):
 		for brch in self.branches_all:
 			brch.tag = value
 	
-	def buildConnections(self, sloppy=1.0, base_trim = 1.0):
+	def buildConnections(	self,\
+							sloppy = 1.0,\
+							connect_base_trim = 1.0,\
+							do_twigs = False,\
+							twig_ratio = 2.0,\
+							twig_scale = 0.8,\
+							twig_scale_width = 1.0,\
+							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,\
+							twig_placement_maxradius=10.0,\
+							twig_placement_maxtwig=0,\
+							twig_follow_parent=0.0,\
+							twig_follow_x=0.0,\
+							twig_follow_y=0.0,\
+							twig_follow_z=0.0,\
+						):
 		'''
 		build tree data - fromCurve must run first
-		
 		'''
 		
 		# Sort the branchs by the first radius, so big branchs get joins first
@@ -214,25 +265,11 @@
 						
 						# Check its in range, allow for a bit out - hense the sloppy
 						if dist < pt_best_j.radius * sloppy:
-							
-							# if 1)	dont remove the whole branch, maybe an option but later
-							# if 2)	we are alredy a parent, cant remove me now.... darn :/ not nice...
-							#		could do this properly but it would be slower and its a corner case.
-							#
-							# if 3)	this point is within the branch, remove it.
-							
-							
-							while	len(brch_i.bpoints)>2 and\
-									brch_i.bpoints[0].childCount == 0 and\
-									(brch_i.bpoints[0].co - pt_best_j.nextMidCo).length < pt_best_j.radius * base_trim:
-								
-								del brch_i.bpoints[0]
-								brch_i.bpoints[0].prev = None
-							
-							
 							brch_i.parent_pt = pt_best_j
 							pt_best_j.childCount += 1 # dont remove me
 							
+							brch_i.baseTrim(connect_base_trim)
+							
 							'''
 							if pt_best_j.childCount>4:
 								raise "ERROR"
@@ -263,6 +300,168 @@
 			brch.checkPointList()
 		'''
 		
+		# Important we so this with existing parent/child but before connecting and calculating verts.
+		
+		if do_twigs:
+			irational_num = 22.0/7.0 # use to make the random number more odd
+			
+			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 = []
+			
+			# This wont add all! :/
+			brch_twig_index = 0
+			brch_twig_index_LAST = -1 # use this to prevent in inf loop, since its possible we cant place every branch
+			while brch_twig_index < len(self.branches_twigs) and brch_twig_index_LAST != brch_twig_index:
+				###print "While"
+				### print brch_twig_index, len(self.branches_twigs) # if this dosnt change, quit the while
+				
+				brch_twig_index_LAST = brch_twig_index
+				
+				# new twigs have been added, recalculate
+				branches_twig_sort = [brch.bestTwigSegment() for brch in self.branches_all]
+				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 and \
+							(twig_recursive_limit == 0 or brch_parent.generation < twig_recursive_limit) and \
+							(twig_placement_maxtwig == 0 or brch_parent.twig_count < twig_placement_maxtwig) and \
+							brch_parent.bpoints[twig_pt_index].radius < twig_placement_maxradius:
+						
+						if brch_twig_index >= len(self.branches_twigs):
+							break
+						
+						brch_twig = self.branches_twigs[brch_twig_index]
+						parent_pt = brch_parent.bpoints[twig_pt_index]
+						
+						brch_twig.parent_pt = parent_pt
+						parent_pt.childCount += 1
+						
+						# Scale this twig using this way...
+						# The size of the parent, scaled by the parent point's radius,
+						# ...compared to the parent branch;s root point radius.
+						# Also take into account the length of the parent branch
+						# Use this for pretend random numbers too.
+						scale = twig_scale * (parent_pt.branch.bpoints[0].radius / brch_twig.bpoints[0].radius) * (parent_pt.radius / parent_pt.branch.bpoints[0].radius)
+						
+						# Random orientation
+						# THIS IS NOT RANDOM - Dont be real random so we can always get re-produceale results.
+						if twig_random_orientation:	rnd1 = (((irational_num * scale * 10000000) % 360) - 180) * twig_random_orientation
+						else:						rnd1 = 0.0
+						if twig_random_angle:		rnd2 = (((irational_num * scale * 66666666) % 360) - 180) * twig_random_angle
+						else:						rnd2 = 0.0
+						
+						
+						# Align this with the existing branch
+						angle = AngleBetweenVecs(zup, parent_pt.no)
+						cross = CrossVecs(zup, parent_pt.no)
+						mat_align = RotationMatrix(angle, 3, 'r', cross)
+						
+						# Use the bend on the point to work out which way to make the branch point!
+						if parent_pt.prev:	cross = CrossVecs(parent_pt.no, parent_pt.prev.no - parent_pt.no)
+						else:				cross = CrossVecs(parent_pt.no, parent_pt.next.no - parent_pt.no)
+						
+						if parent_pt.branch.parent_pt:
+							angle = AngleBetweenVecs(parent_pt.branch.parent_pt.no, parent_pt.no)
+						else:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list