1   
  2   
  3  """ 
  4  The Blender.Geometry submodule. 
  5   
  6  Geometry 
  7  ======== 
  8  (when accessing it from the Game Engine use Geometry instead of Blender.Geometry) 
  9   
 10  This new module provides access to a geometry function. 
 11  """ 
 12   
 14          """ 
 15          Takes a list of polylines and calculates triangles that would fill in the polylines. 
 16          Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once. 
 17          @type polylines: List of lists containing vectors, each representing a closed polyline. 
 18          @rtype: list 
 19          @return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given. 
 20          @note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored. 
 21          @note: The order of points in a polyline effect the direction returned triangles face, reverse the order of a polyline to flip the normal of returned faces. 
 22   
 23          I{B{Example:}} 
 24   
 25          The example below creates 2 polylines and fills them in with faces, then makes a mesh in the current scene:: 
 26                  import Blender 
 27                  Vector= Blender.Mathutils.Vector 
 28   
 29                  # Outline of 5 points 
 30                  polyline1= [Vector(-2.0, 1.0, 1.0), Vector(-1.0, 2.0, 1.0), Vector(1.0, 2.0, 1.0), Vector(1.0, -1.0, 1.0), Vector(-1.0, -1.0, 1.0)] 
 31                  polyline2= [Vector(-1, 1, 1.0), Vector(0, 1, 1.0), Vector(0, 0, 1.0), Vector(-1.0, 0.0, 1.0)] 
 32                  fill= Blender.Geometry.PolyFill([polyline1, polyline2]) 
 33   
 34                  # Make a new mesh and add the truangles into it 
 35                  me= Blender.Mesh.New() 
 36                  me.verts.extend(polyline1) 
 37                  me.verts.extend(polyline2) 
 38                  me.faces.extend(fill) # Add the faces, they reference the verts in polyline 1 and 2 
 39   
 40                  scn = Blender.Scene.GetCurrent() 
 41                  ob = scn.objects.new(me) 
 42                  Blender.Redraw() 
 43          """ 
  44   
 46          """ 
 47          Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line. 
 48          @rtype: Vector 
 49          @return: a 2D Vector for the intersection or None where there is no intersection. 
 50          """ 
  51   
 53          """ 
 54          Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line. 
 55          @rtype: tuple 
 56          @return: a tuple containing a vector and a float, the vector is the closest point on the line, the float is the position on the line, between 0 and 1 the point is on the line. 
 57          """ 
  58   
 60          """ 
 61          Takes 4 vectors (one for the test point and 3 for the triangle) 
 62          This is a 2d function so only X and Y are used, Z and W will be ignored. 
 63          @rtype: int 
 64          @return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection. 
 65          """ 
  66   
 68          """ 
 69          Takes 5 vectors (one for the test point and 5 for the quad) 
 70          This is a 2d function so only X and Y are used, Z and W will be ignored. 
 71          @rtype: int 
 72          @return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection. 
 73          """ 
  74   
 76          """ 
 77          Takes a list of 2D boxes and packs them into a square. 
 78          Each box in boxlist must be a list of at least 4 items - [x,y,w,h], after running this script, 
 79          the X and Y values in each box will be moved to packed, non overlapping locations. 
 80           
 81          Example:: 
 82   
 83                  # Make 500 random boxes, pack them and make a mesh from it 
 84                  from Blender import Geometry, Scene, Mesh 
 85                  import random 
 86                  boxes = [] 
 87                  for i in xrange(500): 
 88                          boxes.append( [0,0, random.random()+0.1, random.random()+0.1] ) 
 89                  boxsize = Geometry.BoxPack2D(boxes) 
 90                  print 'BoxSize', boxsize 
 91                  me = Mesh.New() 
 92                  for x in boxes: 
 93                          me.verts.extend([(x[0],x[1], 0), (x[0],x[1]+x[3], 0), (x[0]+x[2],x[1]+x[3], 0), (x[0]+x[2],x[1], 0) ]) 
 94                          v1= me.verts[-1] 
 95                          v2= me.verts[-2] 
 96                          v3= me.verts[-3] 
 97                          v4= me.verts[-4] 
 98                          me.faces.extend([(v1,v2,v3,v4)]) 
 99                  scn = Scene.GetCurrent() 
100                  scn.objects.new(me) 
101           
102          @note: Each boxlist item can be longer then 4, the extra items are ignored and stay untouched. 
103          @rtype: tuple 
104          @return: a tuple pair - (width, height) of all the packed boxes. 
105          """ 
 106 -def BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution): 
 107          """ 
108          Takes 4 vectors representing a bezier curve and returns a list of vector points. 
109          @note: any vector size is supported, the largest dimension from the input will be used for all returned vectors/ 
110          @rtype: list 
111          @return: a list of vectors the size of resolution including the start and end points (vec_knot_1 and vec_knot_2) 
112          """ 
 113