CAWeightMgr Manual
The CAWeightMgr class represents the Weight Manager dialog window and its functionality. It gives access to the displayed tags (of type CAWeightTag ) and joints.
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
.
// enable "Display Weighting" CAWeightMgr::SetParameter (doc, ID_CA_WEIGHT_MGR_ENABLE_DISPLAY , true ); // enable "Draw All Joints" CAWeightMgr::SetParameter (doc, ID_CA_WEIGHT_MGR_DISPLAY_ALL_WEIGHTS , true ); // enable "Points" CAWeightMgr::SetParameter (doc, ID_CA_WEIGHT_MGR_DISPLAY_POINTS , true );
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.
// add weight tag and skin object
// add joints from a BaseArray const Int jointCount = joints.GetCount(); for ( Int i = 0; i < jointCount; ++i) { BaseObject * const joint = joints[i]; weightTag-> AddJoint (joint); }
// select tag doc-> SetActiveTag (weightTag, SELECTION_NEW );
// update weight manager CAWeightMgr::Update (doc);
// select all joints CAWeightMgr::SelectAllJoints (doc);
// auto weight CAWeightMgr::AutoWeight (doc);
The Weight Manager dialog displays the joints of multiple (selected) weight tags.
// get tag count const Int32 tagCount = CAWeightMgr::GetTagCount (doc); if (tagCount == 0) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION );
// loop through all tags for ( Int32 tagIndex = 0; tagIndex < tagCount; ++tagIndex) { // print tag name const CAWeightTag * const tag = CAWeightMgr::GetWeightTag (doc, tagIndex); if (tag == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); ApplicationOutput ( "Weight Tag: " + tag-> GetName ());
// print host object name const BaseObject * const hostObject = CAWeightMgr::GetMeshObject (doc, tagIndex); if (hostObject == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); ApplicationOutput ( "Host Object: " + hostObject-> GetName ()); }
每个 CAWeightTag stores weights for joints. These joints are displayed in the Weight Manager dialog.
// get count const Int32 jointCount = CAWeightMgr::GetJointCount (doc, tagIndex);
// loop through all joints for ( Int32 i = 0; i < jointCount; ++i) { const BaseObject * const joint = CAWeightMgr::GetJointObject (doc, tagIndex, i); if (joint == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// print joint name ApplicationOutput ( "Joint: " + joint-> GetName ()); }
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:
// get all selected objects AutoAlloc<AtomArray> objects; if (objects == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); doc-> GetActiveObjects (objects, GETACTIVEOBJECTFLAGS::CHILDREN );
// deselect all influences CAWeightMgr::UnselectAllJoints (doc);
// loop through all objects for ( Int32 i = 0; i < objects-> GetCount (); ++i) { // get object C4DAtom * const atom = objects-> GetIndex (i); BaseObject * const joint = static_cast< BaseObject * > (atom); if (joint == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// check if joint if (joint-> IsInstanceOf ( Ojoint )) { // get id const UInt64 id = CAWeightMgr::GetJointId (doc, weightTag, joint); if ( id != maxon::LIMIT<UInt64>::MAX ) { // check if selected if (joint-> GetBit ( BIT_ACTIVE )) CAWeightMgr::SelectJoint (doc, id ); } } }
The Weight Manager can lock a joint object to prevent unintended changes.
The lock state of all joint objects can be managed with:
// deselect all CAWeightMgr::UnselectAllJoints (doc);
// 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 CAWeightMgr::UnlockAllJoints (doc);
// lock selected CAWeightMgr::LockSelectedJoints (doc);
The weight algorithms are edited with these static functions:
Several weight tools of the Weight Manager can be invoked with dedicated functions. These functions add an undo step.
Copy and paste functions are:
// get modes const maxon::Id targetMode = maxon::AutoWeightAlgos::BoneglowClass().GetId(); const maxon::Int64 index = CAWeightMgr::GetAutoWeightAlgoIndex (doc, targetMode) iferr_return ;
// set mode GeData geData; geData. SetInt64 (index); CAWeightMgr::SetParameter (doc, ID_CA_WEIGHT_MGR_AUTOWEIGHT_MODE , geData);
// get settings maxon::DataDictionary data = CAWeightMgr::GetAutoWeightDictionary (doc, targetMode) iferr_return ;
// set settings data.Set(maxon::ANIMATION::AUTOWEIGHT::BONEGLOW::USEVISIBILITY, true ) iferr_return ; data.Set(maxon::ANIMATION::AUTOWEIGHT::BONEGLOW::VISIBILITYRATIO, 0.3_f) iferr_return ; CAWeightMgr::SetAutoWeightDictionary (doc, data, targetMode) iferr_return ;
// apply CAWeightMgr::AutoWeight (doc);