Module Metaball
[hide private]
[frames] | no frames]

Source Code for Module Metaball

  1  # Blender.Metaball module and the Metaball PyType metaball 
  2   
  3  """ 
  4  The Blender.Metaball submodule 
  5   
  6  This module provides access to B{Metaball} data in Blender and the elements they contain. 
  7   
  8   
  9  Example:: 
 10   import Blender 
 11   mb = Blender.Metaball.New() 
 12   for i in xrange(20): 
 13     element= mb.elements.add() 
 14     element.co = Blender.Mathutils.Vector(i, 0, 0)  
 15   sce = Blender.Scene.GetCurrent() 
 16   sce.objects.new(mb) 
 17   
 18   
 19   
 20  Example:: 
 21      # Converts the active armature into metaballs 
 22      from Blender import * 
 23      def main(): 
 24   
 25              scn= Scene.GetCurrent() 
 26              ob_arm= scn.objects.active 
 27              if not ob_arm or ob_arm.type!='Armature': 
 28                      Draw.PupMenu('No Armature Selected') 
 29                      return 
 30              arm= ob_arm.data 
 31   
 32              res= Draw.PupFloatInput('res:', 0.2, 0.05, 2.0) 
 33              if not res: 
 34                      return 
 35   
 36              # Make a metaball 
 37              mb= Metaball.New() 
 38              mb.wiresize= res 
 39   
 40              # Link to the Scene 
 41              ob_mb = scn.objects.new(ob_mb) 
 42              ob_arm.sel= 0 
 43              ob_mb.setMatrix(ob_arm.matrixWorld) 
 44   
 45   
 46              meta_type= 0 # all elemts are ball type 
 47              meta_stiffness= 2.0 # Volume 
 48   
 49              for bone in arm.bones.values(): 
 50                      print bone 
 51   
 52                      # Find out how many metaballs to add based on bone length, 4 min 
 53                      length= bone.length 
 54                      if length < res: 
 55                              mballs= 4 
 56                      else: 
 57                              mballs= int(length/res) 
 58                              if mballs < 4: 
 59                                      mballs = 4 
 60   
 61                      print 'metaball count', mballs 
 62   
 63                      # get the bone properties 
 64                      head_rad= bone.headRadius 
 65                      tail_rad= bone.tailRadius 
 66   
 67                      head_loc= bone.head['ARMATURESPACE'] 
 68                      tail_loc= bone.tail['ARMATURESPACE'] 
 69   
 70   
 71                      for i in range(mballs): 
 72                              f= float(i) 
 73   
 74                              w1= f/mballs # weighting of this position on the bone for rad and loc 
 75                              w2= 1-w1 
 76   
 77                              loc= head_loc*w1 + tail_loc*w2 
 78                              rad= (head_rad*w1 + tail_rad*w2) * 1.3 
 79   
 80                              # Add the metaball 
 81                              ml= mb.elements.add() 
 82                              ml.co= loc 
 83                              ml.radius= rad 
 84                              ml.stiffness= meta_stiffness 
 85   
 86   
 87              Window.RedrawAll() 
 88   
 89      main() 
 90   
 91  @type Types: readonly dictionary 
 92  @var Types: MeteElement types. 
 93      - BALL 
 94      - TUBE 
 95      - PLANE 
 96      - ELIPSOID 
 97      - CUBE 
 98   
 99  @type Update: readonly dictionary 
100  @var Update: MeteElement types. 
101      - ALWAYS 
102      - HALFRES 
103      - FAST 
104      - NEVER 
105   
106  """ 
107   
108   
109 -def New (name):
110 """ 111 Creates a new Metaball. 112 @type name: string 113 @param name: The name of the metaball. If this parameter is not given (or not valid) blender will assign a name to the metaball. 114 @rtype: Blender Metaball 115 @return: The created Metaball. 116 """
117
118 -def Get (name):
119 """ 120 Get the Metaball from Blender. 121 @type name: string 122 @param name: The name of the requested Metaball. 123 @rtype: Blender Metaball or a list of Blender Metaballs 124 @return: It depends on the 'name' parameter: 125 - (name): The Metaball with the given name; 126 - (): A list with all Metaballs in the current scene. 127 """
128
129 -class Metaball:
130 """ 131 The Metaball object 132 =================== 133 This metaball gives access to generic data from all metaballs in Blender. 134 @ivar elements: Element iterator of MetaElemSeq type. 135 @type elements: MetaElemSeq 136 @ivar wiresize: display resolution. 137 Value clamped between 0.05 and 1.0. 138 139 A lower value results in more polygons. 140 @type wiresize: float 141 @ivar rendersize: render resolution. 142 Value clamped between 0.05 and 1.0. 143 144 A lower value results in more polygons. 145 @type rendersize: float 146 @ivar thresh: Threshold setting for this metaball. 147 Value clamped between 0.0 and 5.0. 148 @type thresh: float 149 @ivar materials: List of up to 16 Materials or None types 150 Only the first material of the mother-ball used at the moment. 151 @type materials: list 152 @ivar update: The update method to use for this metaball. 153 @type update: int 154 """ 155
156 - def __copy__():
157 """ 158 Return a copy of this metaball object data. 159 @rtype: Metaball 160 @return: Metaball 161 """
162 163 import id_generics 164 Metaball.__doc__ += id_generics.attributes 165 166
167 -class MetaElemSeq:
168 """ 169 The MetaElemSeq object 170 ====================== 171 This object provides sequence and iterator access to the metaballs elements. 172 The elements accessed within this iterator "wraps" the actual metaball elements; changing any 173 of the elements's attributes will immediately change the data in the metaball. 174 175 This iterator is most like pythons 'set' type. 176 """ 177
178 - def add():
179 """ 180 Append a new element to the metaball. 181 no arguments are taken, instead a new metaelement is 182 added to the metaball data and returned. 183 This new element can then be modified. 184 185 @return: a new meta element. 186 @rtype: Metaelement 187 """
188
189 - def remove(element):
190 """ 191 remove an element from the metaball data. 192 193 if the element is not a part of the metaball data, an error will be raised. 194 195 @return: None 196 @rtype: None 197 """
198
199 - def __iter__():
200 """ 201 Iterate over elements in this metaball. 202 203 @return: One of the metaelem in this metaball. 204 @rtype: Metaelem 205 """
206
207 - def __len__():
208 """ 209 Iterate over elements in this metaball. 210 211 @return: The number of elements in this metaball 212 @rtype: int 213 """
214
215 -class Metaelem:
216 """ 217 The Metaelem object 218 =================== 219 This gives direct access to meta element data within a metaball. 220 @ivar type: The type of the metaball. 221 Values must be from L{Types} 222 223 Example:: 224 from Blender import Metaball 225 mb= Metaball.Get('mb') 226 for el in mb.elements: 227 el.type= Metaball.Types.CUBE 228 @type type: int 229 @ivar co: The location of this element. 230 @type co: Vector 231 @ivar dims: Element dimensions. 232 Values clamped between 0 and 20 on all axies. 233 @type dims: Vector 234 @ivar quat: Element rotation. 235 @type quat: Quaternion 236 @ivar stiffness: Element stiffness. 237 Value clamped between 0 and 10. 238 @type stiffness: float 239 @ivar radius: Element radius. 240 Value clamped between 0 and 5000. 241 @type radius: float 242 @ivar negative: Element negative volume status. 243 @type negative: bool 244 @ivar hide: Element hidden status. 245 @type hide: bool 246 """
247