CAWeightTag Manual
The
CAWeightTag
class represents a weight tag. A weight tag stores weights that define the influence a joint object has on a deformed mesh. The class is defined in the
lib_ca.h
header file.
CAWeightTag
objects are an instance of
Tweights
.
A CAWeightTag tag can be accessed like any other tag, see BaseTag and VariableTag Manual .
// This example accesses the selected weight tag // and prints the names of weighted joints.// get weight tag
// loop through all joints const Int32 jointCount = weightTag-> GetJointCount (); for ( Int32 i = 0; i < jointCount; ++i) { const BaseObject * const joint = weightTag-> GetJoint (i, doc); if (joint == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); ApplicationOutput ( "Joint: " + joint-> GetName ()); }
CAWeightTag instances are created with the usual tools, see Entity Creation and Destruction Manual (Classic) .
Standard parameters on a
CAWeightTag
can be edited with
C4DAtom::GetParameter()
and
C4DAtom::SetParameter()
. The parameter IDs are defined in
tcaweight.h
.
A CAWeightTag manages a list of references to various joint objects.
// get selected objects doc-> GetActiveObjects (objects, GETACTIVEOBJECTFLAGS::CHILDREN );
// loop through all objects const Int32 objectCount = objects-> GetCount (); for ( Int32 i = 0; i < objectCount; ++i) { C4DAtom * const atom = objects-> GetIndex (i); BaseObject * const baseObject = static_cast< BaseObject * > (atom); if (baseObject == nullptr ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );
// only add joint objects if (baseObject-> IsInstanceOf ( Ojoint )) { weightTag-> AddJoint (baseObject); } }
For each joint the reset (or rest) state is stored:
The JointRestState structure has these members:
// loop through all joints const Int32 jointCount = weightTag-> GetJointCount (); for ( Int32 i = 0; i < jointCount; ++i) { const JointRestState state = weightTag-> GetJointRestState (i); const Float length = state. m_Len ; ApplicationOutput ( "Rest Length: " + String::FloatToString (length)); }
A CAWeightTag stores weights for each point and joint.
// check if any weights are stored const Int32 weightCount = weightTag-> GetWeightCount (jointIndex); if (weightCount == 0) continue ; const Int32 pointCount = polyObject-> GetPointCount ();
// allocate memory maxon::BaseArray<Float32> weights; weights. Resize (pointCount) iferr_return ;
// load weights Float32 * const handle = weights. GetFirst (); weightTag-> GetWeightMap (jointIndex, handle, pointCount);
// print weights
for ( Int32 weightIndex = 0; weightIndex < pointCount; ++weightIndex) { const Float32 weight = weights[weightIndex]; ApplicationOutput ( "Weight: " + String::FloatToString (weight)); }// loop through all points const Int32 pointCount = polyObject-> GetPointCount (); for ( Int32 pointIndex = 0; pointIndex < pointCount; ++pointIndex) { const Float weight = weightTag-> GetWeight (jointIndex, pointIndex); ApplicationOutput ( "Point " + String::IntToString (pointIndex) + " : " + String::FloatToString (weight)); }
CAWeightTag offers these functions:
// update rest state JointRestState state = weightTag-> GetJointRestState (1); state. m_oMg . off = state. m_oMg . off + 向量 (0, 100.0, 0); state. m_oMi = ~state. m_oMg ; weightTag-> SetJointRestState (1, state);
// update joint object position BaseObject * const joint = weightTag-> GetJoint (1, doc); if (joint) joint-> SetMg (state. m_oMg );
// calculate states weightTag-> CalculateBoneStates ( NOTOK );