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

Module Metaball

source code

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 [hide private]
  Metaball
This metaball gives access to generic data from all metaballs in Blender.
  MetaElemSeq
This object provides sequence and iterator access to the metaballs elements.
  Metaelem
This gives direct access to meta element data within a metaball.
Functions [hide private]
Blender Metaball
New(name)
Creates a new Metaball.
source code
Blender Metaball or a list of Blender Metaballs
Get(name)
Get the Metaball from Blender.
source code
Variables [hide private]
readonly dictionary Types
MeteElement types.
readonly dictionary Update
MeteElement types.
  __package__ = None
Function Details [hide private]

New(name)

source code 

Creates a new Metaball.

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

Get(name)

source code 

Get the Metaball from Blender.

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

Variables Details [hide private]

Types

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

Update

MeteElement types.
  • ALWAYS
  • HALFRES
  • FAST
  • NEVER
Type:
readonly dictionary