About
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
.
Access
A CAWeightTag tag can be accessed like any other tag, see BaseTag and VariableTag Manual.
BaseTag* const tag = doc->GetActiveTag();
if (tag ==
nullptr || !tag->IsInstanceOf(
Tweights))
CAWeightTag* const weightTag = static_cast<CAWeightTag*>(tag);
const Int32 jointCount = weightTag->GetJointCount();
for (
Int32 i = 0; i < jointCount; ++i)
{
const BaseObject* const joint = weightTag->GetJoint(i, doc);
if (joint == nullptr)
}
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
#define Tweights
Weights.
Definition: ge_prepass.h:1463
maxon::Int32 Int32
Definition: ge_sys_math.h:51
Allocation/Deallocation
CAWeightTag instances are created with the usual tools, see Entity Creation and Destruction Manual (Cinema API).
- CAWeightTag::Alloc(): Creates a new CAWeightTag.
- CAWeightTag::Free(): Deletes the given CAWeightTag.
CAWeightTag* const weightTag = CAWeightTag::Alloc();
if (weightTag == nullptr)
polygonObject->InsertTag(weightTag);
Properties
Standard parameters on a CAWeightTag can be edited with C4DAtom::GetParameter() and C4DAtom::SetParameter(). The parameter IDs are defined in tcaweight.h
.
Joints
A CAWeightTag manages a list of references to various joint objects.
- CAWeightTag::AddJoint(): Adds a joint to the list.
- CAWeightTag::RemoveJoint(): Removes the given joint from the list.
- CAWeightTag::GetJointCount(): Returns the number of joints in the list.
- CAWeightTag::GetJoint(): Returns the joint at the given index.
- CAWeightTag::FindJoint(): Returns the index of the given joint object.
AutoAlloc<AtomArray> objects;
if (objects == nullptr)
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)
if (baseObject->IsInstanceOf(
Ojoint))
{
weightTag->AddJoint(baseObject);
}
}
CHILDREN
Check if the children are dirty.
Definition: ge_prepass.h:5
#define Ojoint
Joint.
Definition: ge_prepass.h:1098
For each joint the reset (or rest) state is stored:
- CAWeightTag::GetJointRestState(): Returns the JointRestState for the joint at the given index.
- CAWeightTag::SetJointRestState(): Sets the JointRestState for the joint at the given index.
The JointRestState structure has these members:
- JointRestState::m_bMg: The global matrix of the bone between two joints.
- JointRestState::m_bMi: The inverse matrix of m_bMg.
- JointRestState::m_oMg: The global matrix of the joint object.
- JointRestState::m_oMi: The inverse matrix of m_oMg.
- JointRestState::m_Len: The bone rest length.
const Int32 jointCount = weightTag->GetJointCount();
for (
Int32 i = 0; i < jointCount; ++i)
{
const JointRestState state = weightTag->GetJointRestState(i);
const Float length = state.m_Len;
}
maxon::Float Float
Definition: ge_sys_math.h:57
Weights
A CAWeightTag stores weights for each point and joint.
- CAWeightTag::GetWeightCount(): Returns the total number of stored weights for the given joint index.
- CAWeightTag::GetWeightMap(): Fills the given map with weights for the given joint index.
- CAWeightTag::SetWeightMap(): Sets the weights for the given joint index.
- Note
- The order of weight values does not correspond to the point order.
const Int32 weightCount = weightTag->GetWeightCount(jointIndex);
if (weightCount == 0)
continue;
const Int32 pointCount = polyObject->GetPointCount();
weightTag->GetWeightMap(jointIndex, handle, pointCount);
for (
Int32 weightIndex = 0; weightIndex < pointCount; ++weightIndex)
{
const Float32 weight = weights[weightIndex];
}
Definition: basearray.h:414
MAXON_ATTRIBUTE_FORCE_INLINE const T * GetFirst() const
Returns the first element of the array. For the BaseArray this is a pointer to a continuous block of ...
Definition: basearray.h:1188
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Resizes the array to contain newCnt elements. If newCnt is smaller than GetCount() all extra elements...
Definition: basearray.h:1231
maxon::Float32 Float32
Definition: ge_sys_math.h:59
#define iferr_return
Definition: resultbase.h:1531
- CAWeightTag::GetIndexWeight(): Retrieves the point index and weight value for the given joint index and weight index.
- CAWeightTag::GetWeight(): Returns the weight value for the given joint and point index.
- CAWeightTag::SetWeight(): Sets the weight value for the given joint and point index.
- CAWeightTag::GetWeightDirty(): Returns the dirty state of weights.
- CAWeightTag::WeightDirty(): Sets the dirty state for weights. Call this to update the weights after any change.
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));
}
Matrix
- CAWeightTag::GetGeomMg(): Returns the global matrix for the bind geometry.
- CAWeightTag::SetGeomMg(): Sets the global matrix for the bind geometry.
Functions
CAWeightTag offers these functions:
- CAWeightTag::ResetBindPose(): Resets the bind pose.
- CAWeightTag::SetBindPose(): Sets the bind pose.
- CAWeightTag::CalculateBoneStates(): Initializes the joint at the given index (or NOTOK for all).
- CAWeightTag::TransferWeightMap(): Transfers the weights to the given target tag.
JointRestState state = weightTag->GetJointRestState(1);
state.m_oMg.off = state.m_oMg.off +
Vector(0, 100.0, 0);
state.m_oMi = ~state.m_oMg;
weightTag->SetJointRestState(1, state);
BaseObject* const joint = weightTag->GetJoint(1, doc);
if (joint)
joint->SetMg(state.m_oMg);
weightTag->CalculateBoneStates(
NOTOK);
#define NOTOK
Definition: ge_sys_math.h:258
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
Further Reading