THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/02/2007 at 08:26, xxxxxxxx wrote:
It can be done, but there are currently limitations of how this can be done. For instance, the VariableTag is no longer available so one must use CTrack::FillKey() with the object containing the track having had its points 'changed' to get the PLA data stored.
This code is not identical to the previous code - in that it is used to convert an animated, rigged figure into an animated Polygon object using PLA. So you'll have to make the changes to reflect the inputs and results desired.
#ifdef C4D_R10
// Fix Animation onto Polygon object as PLA track
//*---------------------------------------------------------------------------*
Bool FixPolygonAnimation(BaseDocument* doc, PointObject* orig, PointObject* root, LONG fixAnimSample, Real fixAnimBias, BOOL fixAnimSmooth, LONG* partial, LONG elements)
//*---------------------------------------------------------------------------*
{
// Get Destination point array
Vector* dpoint = root->GetPointW();
if (!dpoint) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_GENERAL_TEXT), "FixPolygonAnimation.root", "Has No Points");
// Check for Spla track, create if none
DescID descID = DescLevel(ID_ANIM_PLA,ID_ANIM_PLA,0);
CTrack* track = root->FindCTrack(descID);
if (!track)
{
track = CTrack::Alloc(root, descID);
if (!track) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "FixPolygonAnimation.track");
root->InsertTrackSorted(track);
doc->AddUndo(UNDO_NEW, track);
}
BaseTime stime = doc->GetMinTime();
BaseTime etime = doc->GetMaxTime();
CCurve* seq = track->GetCurve();
if (!seq) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "FixPolygonAnimation.seq");
seq->FlushKeys();
// Sample Animation at fixAnimSample intervals
ModelingCommandData mcd;
mcd.doc = doc;
mcd.op = orig;
BaseContainer mbc;
mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);
mbc.SetBool(MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, FALSE);
mcd.bc = &mbc;
mcd.flags = 0;
BaseObject* csto;
PointObject* defd;
CKey* key;
const Vector* spoint;
Vector* points;
Vector* lpoints;
DescID biasDID = DescLevel(CK_PLA_BIAS, DTYPE_REAL,0);
DescID cubicDID = DescLevel(CK_PLA_CUBIC, DTYPE_BOOL,0);
LONG pointCount = root->GetPointCount();
LONG pointSize = pointCount*sizeof(Vector);
Real fps = doc->GetFps();
LONG startf = stime.GetFrame(fps);
LONG endf = etime.GetFrame(fps);
StatusSetText("Fixing Animation for "+orig->GetName());
for (; startf <= endf; startf += fixAnimSample)
{
stime = BaseTime::BaseTime(startf, fps);
// - Animate Document to change the points of orig
doc->SetTime(stime);
doc->AnimateDocument(NULL, TRUE, TRUE);
//doc->AnimateObject(orig, stime, 0L);
EventAdd();
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MODELINGCOMMAND_TEXT), "FixPolygonAnimation");
csto = static_cast<BaseObject*>(mcd.result->GetIndex(0));
if (!csto) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MODELINGCOMMAND_TEXT), "FixPolygonAnimation.csto");
if (csto->IsInstanceOf(Onull))
{
defd = ToPoint(csto->GetDown());
if (!defd) return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MODELINGCOMMAND_TEXT), "FixPolygonAnimation.defd");
}
else defd = ToPoint(csto);
// - Add KeyFrame
key = seq->AddKey(stime);
if (!key)
{
BaseObject::Free(csto);
return ErrorException::Throw(EE_DIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "FixPolygonAnimation.key");
}
doc->AddUndo(UNDO_NEW, key);
// - Add PLA data
// + R10
spoint = defd->GetPointR();
if (!spoint)
{
GePrint("Source Obj has no Points");
BaseObject::Free(csto);
break;
}
// Apply parent animation to points
points = defd->GetPointW();
lpoints = points+pointCount;
for (; points != lpoints; ++points) (*points) *= orig->GetMg();
#ifdef WIN64
CopyMem(spoint, dpoint, static_cast<VLONG>(pointSize));
#else
CopyMem(spoint, dpoint, pointSize);
#endif
// - R10
if (!track->FillKey(doc,root,key))
{
BaseObject::Free(csto);
return ErrorException::Throw(EE_DIALOG, "FixPolygonAnimation.FillKey failed");
}
// Do these AFTER FillKey()!
key->SetParameter(biasDID, GeData(fixAnimBias), 0L);
key->SetParameter(cubicDID, GeData(fixAnimSmooth), 0L);
BaseObject::Free(csto);
// Update progress bar on each frame
StatusSetBar(((*partial)*100L)/elements);
(*partial)++;
}
// Clear global matrix
Matrix unit;
root->SetMg(unit);
return TRUE;
}
#else // Pre-R10 PLA
...
Take care,