2006-04-23 02:34:50 +00:00
|
|
|
# Blender.Modifier module and the Modifier PyType object
|
|
|
|
|
|
|
|
"""
|
|
|
|
The Blender.Modifier submodule
|
|
|
|
|
|
|
|
B{New}:
|
|
|
|
- provides access to Blender's modifier stack
|
|
|
|
|
|
|
|
This module provides access to the Modifier Data in Blender.
|
|
|
|
|
|
|
|
Example::
|
|
|
|
from Blender import *
|
|
|
|
|
|
|
|
ob = Object.Get('Cube') # retrieve an object
|
|
|
|
mods = ob.modifiers # get the object's modifiers
|
|
|
|
for mod in mods:
|
|
|
|
print mod,mod.name # print each modifier and its name
|
2006-04-25 13:01:19 +00:00
|
|
|
mod = mods.append(Modifier.Type.SUBSURF) # add a new subsurf modifier
|
|
|
|
mod[Modifier.Settings.LEVELS] = 3 # set subsurf subdivision levels to 3
|
2006-08-18 01:56:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
Example::
|
|
|
|
# Apply a lattice to an object and get the deformed object
|
2006-08-21 19:11:43 +00:00
|
|
|
# Uses an object called 'Cube' and a lattice called 'Lattice'
|
2006-08-18 01:56:18 +00:00
|
|
|
|
|
|
|
from Blender import *
|
|
|
|
ob_mesh= Object.Get('Cube')
|
|
|
|
ob_lattice= Object.Get('Lattice')
|
|
|
|
|
|
|
|
myMeshMod = ob_mesh.modifiers
|
|
|
|
mod = myMeshMod.append(Modifier.Type.LATTICE)
|
|
|
|
mod[Modifier.Settings.OBJECT] = ob_lattice
|
|
|
|
|
|
|
|
ob_mesh.makeDisplayList() # Needed to apply the modifier
|
|
|
|
|
|
|
|
Window.RedrawAll() # View the change
|
|
|
|
|
|
|
|
deformed_mesh= Mesh.New()
|
|
|
|
deformed_mesh.getFromObject(ob_mesh.name)
|
|
|
|
|
|
|
|
|
|
|
|
# Print the deformed locations
|
|
|
|
for v in deformed_mesh.verts:
|
|
|
|
print v.co
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-25 13:01:19 +00:00
|
|
|
@type Type: readonly dictionary
|
2006-06-14 04:41:31 +00:00
|
|
|
@var Type: Constant Modifier dict used for L{Modifiers.append()} to a
|
|
|
|
modifier sequence and comparing with L{Modifier.type}:
|
2006-04-23 17:01:04 +00:00
|
|
|
- ARMATURE - type value for Armature modifiers
|
|
|
|
- BOOLEAN - type value for Boolean modifiers
|
|
|
|
- BUILD - type value for Build modifiers
|
|
|
|
- CURVE - type value for Curve modifiers
|
|
|
|
- DECIMATE - type value for Decimate modifiers
|
|
|
|
- LATTICE - type value for Lattice modifiers
|
|
|
|
- SUBSURF - type value for Subsurf modifiers
|
|
|
|
- WAVE - type value for Wave modifiers
|
2006-04-23 02:34:50 +00:00
|
|
|
|
2006-04-25 13:01:19 +00:00
|
|
|
@type Settings: readonly dictionary
|
|
|
|
@var Settings: Constant Modifier dict used for changing modifier settings.
|
2006-04-29 14:24:30 +00:00
|
|
|
- RENDER - Used for all modifiers
|
|
|
|
- REALTIME - Used for all modifiers
|
|
|
|
- EDITMODE - Used for all modifiers
|
|
|
|
- ONCAGE - Used for all modifiers
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- OBJECT - Used for Armature, Lattice, Curve, Boolean and Array
|
|
|
|
- VERTGROUP - Used for Armature, Lattice and Curve
|
|
|
|
- LIMIT - Array and Mirror
|
|
|
|
- FLAG - Mirror and Wave
|
|
|
|
- COUNT - Decimator and Array
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- TYPES - Used for Subsurf only
|
|
|
|
- LEVELS - Used for Subsurf only
|
|
|
|
- RENDLEVELS - Used for Subsurf only
|
|
|
|
- OPTIMAL - Used for Subsurf only
|
|
|
|
- UV - Used for Subsurf only
|
2006-04-25 13:01:19 +00:00
|
|
|
|
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- ENVELOPES - Used for Armature only
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- START - Used for Build only
|
|
|
|
- LENGTH - Used for Build only
|
|
|
|
- SEED - Used for Build only
|
|
|
|
- RANDOMIZE - Used for Build only
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- AXIS - Used for Mirror only
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- RATIO - Used for Decimate only
|
2006-04-25 13:01:19 +00:00
|
|
|
|
2006-04-29 14:24:30 +00:00
|
|
|
- STARTX - Used for Wave only
|
|
|
|
- STARTY - Used for Wave only
|
|
|
|
- HEIGHT - Used for Wave only
|
|
|
|
- WIDTH - Used for Wave only
|
|
|
|
- NARROW - Used for Wave only
|
|
|
|
- SPEED - Used for Wave only
|
|
|
|
- DAMP - Used for Wave only
|
|
|
|
- LIFETIME - Used for Wave only
|
|
|
|
- TIMEOFFS - Used for Wave only
|
|
|
|
- OPERATION - Used for Wave only
|
2006-04-23 17:01:04 +00:00
|
|
|
"""
|
2006-04-23 02:34:50 +00:00
|
|
|
|
2006-06-14 04:41:31 +00:00
|
|
|
class Modifiers:
|
2006-04-23 02:34:50 +00:00
|
|
|
"""
|
2006-06-14 04:41:31 +00:00
|
|
|
The Modifiers object
|
|
|
|
====================
|
2006-04-25 13:01:19 +00:00
|
|
|
This object provides access to list of L{modifiers<Modifier.Modifier>} for a particular object.
|
|
|
|
Only accessed from L{Object.Object.modifiers}.
|
2006-04-23 02:34:50 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __getitem__(index):
|
|
|
|
"""
|
|
|
|
This operator returns one of the object's modifiers.
|
|
|
|
@type index: int
|
|
|
|
@return: an Modifier object
|
|
|
|
@rtype: Modifier
|
|
|
|
@raise KeyError: index was out of range
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __len__():
|
|
|
|
"""
|
|
|
|
Returns the number of modifiers in the object's modifier stack.
|
|
|
|
@return: number of Modifiers
|
|
|
|
@rtype: int
|
|
|
|
"""
|
|
|
|
|
|
|
|
def append(type):
|
|
|
|
"""
|
|
|
|
Appends a new modifier to the end of the object's modifier stack.
|
2006-04-25 13:01:19 +00:00
|
|
|
@type type: a constant specifying the type of modifier to create. as from L{Type}
|
2006-04-23 02:34:50 +00:00
|
|
|
@rtype: Modifier
|
|
|
|
@return: the new Modifier
|
|
|
|
"""
|
|
|
|
|
2006-04-25 13:01:19 +00:00
|
|
|
def remove(modifier):
|
|
|
|
"""
|
|
|
|
Remove a modifier from this objects modifier sequence.
|
|
|
|
@type modifier: a modifier from this sequence to remove.
|
|
|
|
@note: Accessing attributes of the modifier after removing will raise an error.
|
|
|
|
"""
|
|
|
|
|
2006-06-14 04:41:31 +00:00
|
|
|
def moveUp(modifier):
|
|
|
|
"""
|
|
|
|
Moves the modifier up in the object's modifier stack.
|
|
|
|
@type modifier: a modifier from this sequence to remove.
|
2006-07-12 14:27:13 +00:00
|
|
|
@rtype: None
|
2006-06-14 04:41:31 +00:00
|
|
|
@raise RuntimeError: request to move above another modifier requiring
|
|
|
|
original data
|
|
|
|
@note: Accessing attributes of the modifier after removing will raise an error.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def moveDown(modifier):
|
|
|
|
"""
|
|
|
|
Moves the modifier down in the object's modifier stack.
|
|
|
|
@type modifier: a modifier from this sequence to remove.
|
2006-07-12 14:27:13 +00:00
|
|
|
@rtype: None
|
2006-06-14 04:41:31 +00:00
|
|
|
@raise RuntimeError: request to move modifier beyond a non-deforming
|
|
|
|
modifier
|
|
|
|
@note: Accessing attributes of the modifier after removing will raise an error.
|
|
|
|
"""
|
|
|
|
|
2006-04-23 02:34:50 +00:00
|
|
|
class Modifier:
|
|
|
|
"""
|
|
|
|
The Modifier object
|
|
|
|
===================
|
2006-06-14 04:41:31 +00:00
|
|
|
This object provides access to a modifier for a particular object accessed
|
|
|
|
from L{Modifiers}.
|
2006-04-23 08:01:02 +00:00
|
|
|
@ivar name: The name of this modifier. 31 chars max.
|
2006-04-23 17:01:04 +00:00
|
|
|
@type name: string
|
|
|
|
@ivar type: The type of this modifier. Read-only. The returned value
|
2006-04-25 13:01:19 +00:00
|
|
|
matches the types in L{Type}.
|
2006-04-23 17:01:04 +00:00
|
|
|
@type type: int
|
2006-04-23 08:01:02 +00:00
|
|
|
"""
|
2006-04-23 02:34:50 +00:00
|
|
|
|
|
|
|
def __getitem__(key):
|
|
|
|
"""
|
|
|
|
This operator returns one of the modifier's data attributes.
|
2006-04-25 13:01:19 +00:00
|
|
|
@type key: value from modifier's L{Modifier.Settings} constant
|
2006-04-23 02:34:50 +00:00
|
|
|
@return: the requested data
|
|
|
|
@rtype: varies
|
|
|
|
@raise KeyError: the key does not exist for the modifier
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __setitem__(key):
|
|
|
|
"""
|
|
|
|
This operator modifiers one of the modifier's data attributes.
|
2006-04-25 13:01:19 +00:00
|
|
|
@type key: value from modifier's L{Modifier.Settings} constant
|
2006-04-23 02:34:50 +00:00
|
|
|
@raise KeyError: the key does not exist for the modifier
|
|
|
|
"""
|
|
|
|
|