Module Metaball
[frames | no frames]

Module Metaball

The Blender.Metaball submodule

This module provides access to Metaball data in Blender and the elements they contain.

Example:
import Blender
mb = Blender.Metaball.New()
for i in xrange(20):
  element= mb.elements.add()
  element.co = Blender.Mathutils.Vector(i, 0, 0) 
sce = Blender.Scene.GetCurrent()
sce.objects.new(mb)
Example:
   # Converts the active armature into metaballs
   from Blender import *
   def main():

           scn= Scene.GetCurrent()
           ob_arm= scn.objects.active
           if not ob_arm or ob_arm.type!='Armature':
                   Draw.PupMenu('No Armature Selected')
                   return
           arm= ob_arm.data

           res= Draw.PupFloatInput('res:', 0.2, 0.05, 2.0)
           if not res:
                   return

           # Make a metaball
           mb= Metaball.New()
           mb.wiresize= res

           # Link to the Scene
           ob_mb = scn.objects.new(ob_mb)
           ob_arm.sel= 0
           ob_mb.setMatrix(ob_arm.matrixWorld)


           meta_type= 0 # all elemts are ball type
           meta_stiffness= 2.0 # Volume

           for bone in arm.bones.values():
                   print bone

                   # Find out how many metaballs to add based on bone length, 4 min
                   length= bone.length
                   if length < res:
                           mballs= 4
                   else:
                           mballs= int(length/res)
                           if mballs < 4:
                                   mballs = 4

                   print 'metaball count', mballs

                   # get the bone properties
                   head_rad= bone.headRadius
                   tail_rad= bone.tailRadius

                   head_loc= bone.head['ARMATURESPACE']
                   tail_loc= bone.tail['ARMATURESPACE']


                   for i in range(mballs):
                           f= float(i)

                           w1= f/mballs # weighting of this position on the bone for rad and loc
                           w2= 1-w1

                           loc= head_loc*w1 + tail_loc*w2
                           rad= (head_rad*w1 + tail_rad*w2) * 1.3

                           # Add the metaball
                           ml= mb.elements.add()
                           ml.co= loc
                           ml.radius= rad
                           ml.stiffness= meta_stiffness


           Window.RedrawAll()

   main()

Classes
Metaball This metaball gives access to generic data from all metaballs in Blender.
Metaelem This gives direct access to meta element data within a metaball.
MetaElemSeq This object provides sequence and iterator access to the metaballs elements.

Function Summary
Blender Metaball or a list of Blender Metaballs Get(name)
Get the Metaball from Blender.
Blender Metaball New(name)
Creates a new Metaball.

Variable Summary
readonly dictionary Types: MeteElement types.

Function Details

Get(name)

Get the Metaball from Blender.
Parameters:
name - The name of the requested Metaball.
           (type=string)
Returns:
It depends on the 'name' parameter:
  • (name): The Metaball with the given name;
  • (): A list with all Metaballs in the current scene.

           (type=Blender Metaball or a list of Blender Metaballs)

New(name)

Creates a new Metaball.
Parameters:
name - The name of the metaball. If this parameter is not given (or not valid) blender will assign a name to the metaball.
           (type=string)
Returns:
The created Metaball.
           (type=Blender Metaball)

Variable Details

Types

MeteElement types.
  • BALL
  • TUBE
  • PLANE
  • ELIPSOID
  • CUBE
Type:
readonly dictionary

Generated by Epydoc 2.1 on Sun Feb 11 13:30:19 2007 http://epydoc.sf.net