CAWeightMgr Manual

About

The CAWeightMgr class represents the Weight Manager dialog and its functionality. It gives access to the displayed tags (of type CAWeightTag) and joints.

Settings

The settings presented by the Weight Manager dialog are stored with the BaseDocument. They can be safely accessed with these functions:

The setting IDs are defined in oweightmgr.h.

// This example changes the settings that are displayed in the Weight Manager dialog.
// enable "Display Weighting"
// enable "Draw All Joints"
// enable "Points"

Update

The CAWeightMgr class accesses an internal cache. This internal cache is automatically updated if the Weight Manger window is opened or the weight tool is active. If this is not the case the internal cache must be updated manually to handle scene changes.

// This example creates and adds a weight tag and a skin object
// to the given polygon object. The joints stored in the given BaseArray
// are linked in the weight tag. The weight manager is updated
// and used to create auto-weights.
// add weight tag and skin object
if (!wTag || !sObject)
return false;
CAWeightTag* weightTag = wTag.Release();
BaseObject* skinObject = sObject.Release();
polyObject->InsertTag(weightTag);
doc->InsertObject(skinObject, polyObject, nullptr);
// add joints from a BaseArray
const Int jointCount = joints.GetCount();
for (Int i = 0; i < jointCount; ++i)
{
BaseObject* joint = joints[i];
weightTag->AddJoint(joint);
}
// select tag
doc->SetActiveTag(weightTag, SELECTION_NEW);
// update weight manager
// select all joints
// auto weight

Weight Tags

The Weight Manager dialog displays the joints of multiple (selected) weight tags.

// This example loops through all Weight Tags
// displayed in the Weight Manager window.
// get tag count
const Int32 tagCount = CAWeightMgr::GetTagCount(doc);
if (tagCount == 0)
return false;
// loop through all tags
for (Int32 tagIndex = 0; tagIndex < tagCount; ++tagIndex)
{
// print tag name
CAWeightTag* tag = CAWeightMgr::GetWeightTag(doc, tagIndex);
if (tag)
GePrint("Weight Tag: " + tag->GetName());
// print host object name
BaseObject* hostObject = CAWeightMgr::GetMeshObject(doc, tagIndex);
if (hostObject)
GePrint("Host Object: " + hostObject->GetName());
}

Joints

Each CAWeightTag stores weights for joints. These joints are displayed in the Weight Manager dialog.

// This example loops through all joints (influences)
// handled in the weight tag at the given index.
// get count
const Int32 jointCount = CAWeightMgr::GetJointCount(doc, tagIndex);
// loop through all joints
for (Int32 i = 0; i < jointCount; ++i)
{
const BaseObject* joint = CAWeightMgr::GetJointObject(doc, tagIndex, i);
// print joint name
if (joint)
{
GePrint("Joint: " + joint->GetName());
}
}

Selection

It is possible to select joint objects in the Weight Manager. Several operations only apply to such selected objects.

The selection state of all joint objects can easily be managed with:

// This example loops through all selected objects. If the object
// is a joint it will also be selected in the weight manager.
// get all selected objects
if (!objects)
return false;
// deselect all influences
// loop through all objects
for (Int32 i = 0; i < objects->GetCount(); ++i)
{
// get object
C4DAtom* atom = objects->GetIndex(i);
BaseObject* joint = static_cast<BaseObject*>(atom);
// check if joint
if (joint && joint->IsInstanceOf(Ojoint))
{
// get id
const UInt64 id = CAWeightMgr::GetJointId(doc, weightTag, joint);
{
// check if selected
if (joint->GetBit(BIT_ACTIVE))
}
}
}

Locked

The Weight Manager can lock a joint object to prevent unintended changes.

The lock state of all joint objects can be managed with:

// This example inverts the lock state of all influences
// in the weight tag with the given index.
// deselect all
// get count
const Int32 jointCount = CAWeightMgr::GetJointCount(doc, tagIndex);
// loop through all joints
for (Int32 i = 0; i < jointCount; ++i)
{
// check if locked
if (CAWeightMgr::IsJointLocked(doc, tagIndex, i) == false)
{
// select unlocked
CAWeightMgr::SelectJoint(doc, tagIndex, i);
}
}
// unlock all
// lock selected

Functions

Several weight tools of the Weight Manager can be invoked with dedicated functions. These functions add an undo step.

Note
The following functions take the selection state of a joint object into account.

Copy and paste functions are:

// This example configures the Weight Manager settings and applies the "Auto Weight" function.
// set settings for "Auto Weight"
// auto weight

Further Reading