Public Types | Public Member Functions | Protected Member Functions

MFnBlendShapeDeformer Class Reference

Search for all occurrences

Detailed Description

blend shape deformer function set

MFnBlendShapeDeformer is the function set for blend shape deformers. A blend shape deformer takes a base shape (polygonal surface, curve, surface, or lattice) and blends it with other target shapes based on weight values.

The blend shape deformer is actually a small network of dependency nodes in the dependency graph. This function set is provided to make manipulation of the network easier. The main deformer node should be given to this function set as its object.

There are three parts to a blend shape deformer. There are the base objects, the target objects, and the weight values.

The base objects are the shapes that are to be deformed. There must be at least one base object. The base objects will change form as the targets and deformation parameters are modified.

Each base object has a list of target objects that affect its shape. Each target is associated with one of the the deformer's weight values. When the weight value increases, the target has more influence on the base shape.

There is just one array of weight values between all of the base objects and targets. So, it is possible for targets of different base objects to share the same weight index. When the weight value changes, it will affect all of the base objects that have targets using that weight value.

It is also possible to chain together target shapes so that a base object will deform through each shape one at a time as the weight value increases. This is done by adding multiple targets to a base shape using the same weight index for all of them. When each target is added, a weight value is specified at which that target will be in full effect. Give each target a different full weight value.

For example, one could take a sphere and make it blend into a cone and then into a cylinder. One way to do this is to make sphere the base shape. Then, add the cone as a target for the sphere at weight index 0 with a full effect weight of 0.5. Next, add the cylinder as a second target for the sphere also at weight index 0, but with a full effect weight of 1.0. Now, as the weight goes from 0 to 1, the base shape will start as a sphere, morph into a cone, and then into a cylinder.

It is not necessary for the base shape and its targets to have identical vertex/CV counts, but the blend will be more effective if they do.

#include <MFnBlendShapeDeformer.h>

Inheritance diagram for MFnBlendShapeDeformer:
Inheritance graph
[legend]

List of all members.

Public Types

enum  Origin { kLocalOrigin, kWorldOrigin }
 

Specifies the space to use for the deformation origin.

More...
enum  HistoryLocation { kFrontOfChain, kNormal }
 

Specifies where in the shape's history to place the deformer.

More...

Public Member Functions

virtual MFn::Type type () const
 Function set type.
virtual ~MFnBlendShapeDeformer ()
 Destructor.
 MFnBlendShapeDeformer ()
 Default constructor.
 MFnBlendShapeDeformer (MObject &object, MStatus *ReturnStatus=NULL)
 Constructor.
MObject create (MObject baseObject, Origin originSpace=kLocalOrigin, MStatus *ReturnStatus=NULL)
 Creates a new blend shape deformer in the dependency graph with the specified shape as the baseObject.
MObject create (const MObjectArray &baseObjects, Origin originSpace=kLocalOrigin, HistoryLocation=kNormal, MStatus *ReturnStatus=NULL)
 Creates a new blend shape deformer in the dependency graph.
MStatus addBaseObject (MObject &object)
 Adds a new base object to the deformer.
MStatus getBaseObjects (MObjectArray &objects) const
 Get a list of all of the base objects for this deformer.
MStatus addTarget (const MObject &baseObject, int weightIndex, const MObject &newTarget, double fullWeight)
 Adds a new target object for the given base object.
MStatus removeTarget (const MObject &baseObject, int weightIndex, const MObject &target, double fullWeight)
 Remove a target object for the given base object.
MStatus getTargets (MObject baseObject, int weightIndex, MObjectArray &targetObjects) const
 Get a list of all of the target objects for the given base object that affect it based on the given weight index.
unsigned int numWeights (MStatus *ReturnStatus=NULL) const
 Return the number of weight values that this blend shape deformer has.
MStatus weightIndexList (MIntArray &indexList) const
 Return the array index numbers corresponding to the targets.
MStatus targetItemIndexList (unsigned int weightIndex, MObject baseObject, MIntArray &targetItemIndices) const
 A base object may have more than one target using the same element of the blendShape's 'weights' array.
float weight (unsigned int index, MStatus *ReturnStatus=NULL) const
 Get the weight value at the given index.
MStatus setWeight (unsigned int index, float weight)
 Set the weight value at the given index.
float envelope (MStatus *ReturnStatus=NULL) const
 Gets the envelope value of the deformer.
MStatus setEnvelope (float envelope)
 Sets the envelope value of the deformer.
Origin origin (MStatus *ReturnStatus=NULL) const
 Gets the origin space.
MStatus setOrigin (Origin space)
 Sets the origin space.
 MFnBlendShapeDeformer (const MObject &object, MStatus *ReturnStatus=NULL)
 Constructor.

Protected Member Functions

virtual const char * className () const
 Class name.

Member Enumeration Documentation

enum Origin

Specifies the space to use for the deformation origin.

Enumerator:
kLocalOrigin 

 

kWorldOrigin 

 

Specifies where in the shape's history to place the deformer.

Enumerator:
kFrontOfChain 

 

kNormal 

 


Constructor & Destructor Documentation

MFnBlendShapeDeformer ( MObject object,
MStatus ReturnStatus = NULL 
)

Constructor.

Class constructor that initializes the function set to the given MObject.

Parameters:
[in]objectThe MObject to attach the function set to
[out]ReturnStatusthe return status
Status Codes:
MFnBlendShapeDeformer ( const MObject object,
MStatus ReturnStatus = NULL 
)

Constructor.

Class constructor that initializes the function set to the given MObject.

Parameters:
[in]objectThe MObject to attach the function set to
[out]ReturnStatusthe return status
Status Codes:

Member Function Documentation

MFn::Type type ( ) const [virtual]

Function set type.

Return the class type : MFn::kBlendShape.

Reimplemented from MFnDependencyNode.

MObject create ( MObject  baseObject,
Origin  originSpace = kLocalOrigin,
MStatus ReturnStatus = NULL 
)

Creates a new blend shape deformer in the dependency graph with the specified shape as the baseObject.

Parameters:
[in]baseObjecta base object for the deformer
[in]originSpaceorigin about which to deform
[out]ReturnStatusreturn status
Returns:
A handle to the new deformer
Status Codes:
MObject create ( const MObjectArray baseObjects,
Origin  originSpace = kLocalOrigin,
HistoryLocation  historyLoc = kNormal,
MStatus ReturnStatus = NULL 
)

Creates a new blend shape deformer in the dependency graph.

This method differs from the other MFnBlendShapeDeformer::create in that it allows multiple base shapes to be supplied at create time and it allows the use of the front-of-chain history location, which puts the blendShape ahead of other deformers such as skinning deformers.

Parameters:
[in]baseObjectsbase object(s) for the deformer
[in]originSpaceorigin about which to deform
[in]historyLocwhere in the shape's history to place the deformer
[out]ReturnStatusreturn status
Returns:
A handle to the new deformer
Status Codes:
MStatus addBaseObject ( MObject object)

Adds a new base object to the deformer.

This object will be deformed as targets are added for it and the deformation parameters change.

Parameters:
[in]objectnew base object
Returns:
Return status
Status Codes:
MStatus getBaseObjects ( MObjectArray objects) const

Get a list of all of the base objects for this deformer.

The objects returned will be the deformed versions of the base objects.

Parameters:
[out]objectsstorage for the array of base objects
Returns:
Return status
Status Codes:
MStatus addTarget ( const MObject baseObject,
int  weightIndex,
const MObject newTarget,
double  fullWeight 
)

Adds a new target object for the given base object.

The weight index says which of the deformer's weight values will control this target's affects on the base object. The full weight argument determines at what weight the target is in full effect. If a base object has no other targets and the weight is set to the 'full weight', then the base object will look just like the target object.

Parameters:
[in]baseObjectbase object for the target
[in]weightIndexweight index to use for target's effect
[in]newTargetnew target object for the given base
[in]fullWeightweight value at which the target is in full effect
Returns:
Return status
Status Codes:
MStatus removeTarget ( const MObject baseObject,
int  weightIndex,
const MObject target,
double  fullWeight 
)

Remove a target object for the given base object.

The weight index specifies the index at which target is connected. The full weight argument specifies at what weight the target is in full effect.

Parameters:
[in]baseObjectbase object for the target
[in]weightIndexweight index corresponding to the target
[in]targettarget object for the given base to be removed
[in]fullWeightweight value at which the target is in full effect
Returns:
Return status
Status Codes:
MStatus getTargets ( MObject  baseObject,
int  weightIndex,
MObjectArray targetObjects 
) const

Get a list of all of the target objects for the given base object that affect it based on the given weight index.

Parameters:
[in]baseObjectThe base shape of interest.
[in]weightIndexThe index of the weight attribute. Since the weight indices may be sparse, the weightIndexList method should be used to find the weight indices used by a given blendShape.
[out]targetObjectsStorage for the returned array of target objects.
Returns:
Return status
Status Codes:
unsigned int numWeights ( MStatus ReturnStatus = NULL) const

Return the number of weight values that this blend shape deformer has.

The number of weight values is equal to the number of targets. Targets are either shapes in the dag or baked data on the blendShape node (when a target shape is deleted).

Parameters:
[out]ReturnStatusreturn status
Returns:
The number of weight indices
Status Codes:
MStatus weightIndexList ( MIntArray indexList) const

Return the array index numbers corresponding to the targets.

The resulting index list will be the length of MFnBlendShape::numWeights. This method exists because the indices of the targets can be sparse. For example, if a target has been removed using Deform -> Edit BlendShape -> Remove.

Parameters:
[out]indexListthe array index numbers for the blendShape targets
Returns:
The return status
Status Codes:
MStatus targetItemIndexList ( unsigned int  weightIndex,
MObject  baseObject,
MIntArray targetItemIndices 
) const

A base object may have more than one target using the same element of the blendShape's 'weights' array.

We refer to these as the base object's "target items" for that weight index.

Each target item should have a different 'fullWeight' value at which it takes full effect. As the value of the weights array element approaches the lowest of those 'fullWeight' values the associated target item has an increasing effect on the shape of the base object. As the value of the weights array element passes that first 'fullWeight' value and starts to approach the next higher 'fullWeight' value, the next target item starts to gain influence and the influence of the previous one drops off.

In this way, as the weight value increases, influence passes from one target item to another, allowing the target object to morph through a sequence of different target shapes.

Each target item is connected to an element of the blendShape deformer's 'inputTargetItem' array for that base object and weights array index. The inputTargetItem array index is calculated as follows: index = fullWeight * 1000 + 5000.

For example, if a base object has three different targetItems for a given weights array element, having fullWeight values of 0.5, 1.0 and 2.0, they will be connected to inputTargetItem array indices 5500, 6000 and 7000, respectively.

This method returns an array containing the inputTargetItem array indices of all the target items of a given base object which use the specified weight index.

Parameters:
[in]weightIndex'weights' array index.
[in]baseObjectThe deformed object of interest
[out]targetItemIndices'inputTargetItem' array indices of the requested target items.
Returns:
Return status
Status Codes:
  • MS::kSuccess operation successful
  • MS::kFailure function set does not have a valid object
  • MS::kInvalidIndex no target exists at the specified target index
float weight ( unsigned int  index,
MStatus ReturnStatus = NULL 
) const

Get the weight value at the given index.

To be valid, a weight value should only be requested at index values returned by MFnBlendShapeDeformer::weightIndexList.

Parameters:
[in]indexindex of weight value
[out]ReturnStatusreturn status
Returns:
The weight value
Status Codes:
MStatus setWeight ( unsigned int  index,
float  weight 
)

Set the weight value at the given index.

Parameters:
[in]indexindex of weight value
[in]weightnew weight value
Returns:
Return status
Status Codes:
float envelope ( MStatus ReturnStatus = NULL) const

Gets the envelope value of the deformer.

The envelope is a global scale factor that is applied to all of the weight values in the deformer. The envelope can be used increase or decrease the effects of all of the targets at the same time.

Parameters:
[out]ReturnStatusreturn status
Returns:
Envelope value
Status Codes:
MStatus setEnvelope ( float  envelope)

Sets the envelope value of the deformer.

The envelope is a global scale factor that is applied to all of the weight values in the deformer. The envelope can be used increase or decrease the effects of all of the targets at the same time.

Parameters:
[in]envelopeenvelope value
Returns:
Return status
Status Codes:
MFnBlendShapeDeformer::Origin origin ( MStatus ReturnStatus = NULL) const

Gets the origin space.

It defines the point around which the differences in the geometry are calculated.

Parameters:
[out]ReturnStatusreturn status
Returns:
The origin space
Status Codes:
MStatus setOrigin ( Origin  space)

Sets the origin space.

It defines the point around which the differences in the geometry are calculated.

Parameters:
[in]spaceorigin space
Returns:
The origin space
Status Codes:

MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer
MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer MFnBlendShapeDeformer