THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/07/2011 at 16:07, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 11.5
Platform: Windows ;
Language(s) : C++ ;
---------
Hi again,
I'm working on a Spline IK system. Over all it works fine, but there's a one-frame lag with the splines it's reading. So far, the only way it calculates correctly is if I set the priority of my tag to Generator.
Here's the code I'm using:
#define ID_GSPLINEIK 1027376
#include "c4d.h"
#include "c4d_symbols.h"
#include "customgui_splinecontrol.h"//for spline thingies, range-mapped stuff
#include "c4d_customdatatype.h"
#include "lib_splinehelp.h"
#include "ogsplineik.h"
class GSplineIK : public TagData{
public:
virtual LONG Execute (PluginTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, LONG priority, LONG flags);
virtual Bool Message (GeListNode *node, LONG type, void *t_data);
virtual Bool GetDEnabling (GeListNode *node, const DescID &id, const GeData &t_data, LONG flags, const BaseContainer *itemdesc);
static NodeData *Alloc (void) { return gNew GSplineIK; }
};
//////////////////////////////////////////////////////////
LONG GSplineIK::Execute(PluginTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, LONG priority, LONG flags){
BaseContainer *data = tag->GetDataInstance();
BaseObject *rail = data->GetObjectLink(SPLIK_RAIL, doc),
*spl = data->GetObjectLink(SPLIK_SPLINE, doc);
if (!spl) return EXECUTION_RESULT_OK;//don't run without a spline
LONG i,
j,
jointcount = 0,
splseg = data->GetLong(SPLIK_SPLINESEG),
railseg = data->GetLong(SPLIK_RAILSEG);
spl->Message(MSG_POINTS_CHANGED);//doesn't seem to help...
SplineObject* splobj = spl->GetRealSpline();
splobj->InitLength(splseg);//used to get dimensions of spline
BaseObject *temp = (BaseObject* )data->GetLink(SPLIK_TIP, doc),
*tempnext;
AtomArray *list = AtomArray::Alloc();
while(temp != NULL){// get a list of objects in the chain
jointcount ++;
list->Append(temp);
if(temp == op) break;
temp = temp->GetUp();
}
if(jointcount < 2){// don't calculate unless there's at least two objects in the chain
list->Free(list);
return EXECUTION_RESULT_OK;
}
Matrix joint1Mg,
joint2Mg,
jointupMg,
railMg;
Vector jointrot;
Real *bonelen,
start,
end,
splinelen = splobj->GetLength();
SplineHelp *railh = SplineHelp::Alloc();//used to get matrixes/vectors from spline
railh->InitSpline(rail, 0.0, FALSE, TRUE, FALSE, FALSE);//rail spline
SplineHelp *splh = SplineHelp::Alloc();
if(rail != NULL){//use rail spline if it exists, ignore if it doesn't
splh->InitSpline(spl, 0.0, rail, TRUE, FALSE, FALSE);
}else{
splh->InitSpline(spl);
}
if(data->GetLong(SPLIK_LENGTHMODE) == SPLIK_USEPERCENT){
start = data->GetReal(SPLIK_PERCENTOFF),
end = data->GetReal(SPLIK_PERCENTLEN);
}else{
if(splinelen > 0.0){//catch division by zero
start = data->GetReal(SPLIK_METEROFF)/splinelen;
end = data->GetReal(SPLIK_METERLEN)/splinelen;
}else{
start = 0.0;
end = 1.0;
}
}
temp = (BaseObject* )list->GetIndex(jointcount - 1);//GET HIGHEST ITEM FROM CHAIN
temp->SetMg(splh->GetMatrix(start + 0.0/(jointcount - 1), splseg, TRUE, TRUE));//GET MATRIX FOR CALCULATIONS
///////////////////////////////////////////////////////////////
//
// matrix calculations here, change coordinates of hierarchy
//
///////////////////////////////////////////////////////////////
railh->Free(railh);
splh->Free(splh);
list->Free(list);
splobj->FreeLength();
return EXECUTION_RESULT_OK;
}
//////////////////////////////////////////////////////////
Bool GSplineIK::Message(GeListNode *node, LONG type, void *t_data){
if(type == MSG_DESCRIPTION_CHECKDRAGANDDROP){
DescriptionCheckDragAndDrop *dcu = static_cast<DescriptionCheckDragAndDrop*>(t_data);
switch (dcu->id[0].id){
case SPLIK_SPLINE:
case SPLIK_RAIL:
dcu->result = dcu->element->GetInfo() & OBJECT_ISSPLINE;
return TRUE;
}
}
return TRUE;
}
//////////////////////////////////////////////////////////
Bool GSplineIK::GetDEnabling(GeListNode *node, const DescID &id,const GeData &t_data,LONG flags,const BaseContainer *itemdesc)
{
itemdesc; flags; t_data;
BaseContainer &data = *((BaseObject* )node)->GetDataInstance();
switch (id[0].id){
case SPLIK_PERCENTOFF: return (data.GetLong(SPLIK_LENGTHMODE) == SPLIK_USEPERCENT);
case SPLIK_PERCENTLEN: return (data.GetLong(SPLIK_LENGTHMODE) == SPLIK_USEPERCENT);
case SPLIK_METEROFF: return (data.GetLong(SPLIK_LENGTHMODE) == SPLIK_USEMETER);
case SPLIK_METERLEN: return (data.GetLong(SPLIK_LENGTHMODE) == SPLIK_USEMETER); }
return TRUE;
}
//////////////////////////////////////////////////////////
Bool RegisterGSplineIK(void){
return RegisterTagPlugin(ID_GSPLINEIK,"GRig SplineIK",
TAG_EXPRESSION|TAG_VISIBLE|TAG_MULTIPLE,
GSplineIK::Alloc,"Ogsplineik",
"gsplineik_icon.tif", 0);
}
This is my first time using SplineHelp Class and I'm guessing it might be causing the issue, though I can't be sure.
Has anyone experienced something similar to my problem?
regards,
-gene