This question’s been popping up fairly often…
Anyways, here’s the code that’ll handle child objects. Paste the script into a COFFEE tag attached to a Spline Object and it should work.
main(doc,op)
{
var i, j, k, pointcount;
i = 0;
var a = op->GetDown();//count number of children
while(a != NULL){
a = a->GetNext();
i++;
}
//allocate array for coordinates
pointcount = i;
var pointadr = new(array, pointcount);
a = op->GetDown();
pointadr[0] = a->GetPosition();
for(i = 1; i<pointcount; i++){//get coordinates of children
a = a->GetNext();
pointadr[i] = a->GetPosition();
}
k = 0;//count number of splines needed
for(i = 0; i<pointcount-1; i++){
for(j = i; j<pointcount-1; j++){
k++;
}
}
var vc = new(VariableChanged);
vc->Init(pointcount, k*2);//allocate points
op->Message(MSG_POINTS_CHANGED, vc);
vc->Init(op->GetSegmentCount(), k);//allocate segments
op->Message(MSG_SEGMENTS_CHANGED, vc);
print(k," ");
var gg = op->GetSegmentCount();
print(gg, " ");
var segmentcount = new(array, k);
for(i = 0; i < k; i++){
segmentcount[i] = 2;
}
print(segmentcount[3], " ");
print(op->SetSegments(segmentcount), " ");//assign 2 points per segment
println(op->GetSegmentCount());
k = 0;// generate point pairs
for(i = 0; i < pointcount; i++){
for(j = i; j < pointcount-1; j++){
op->SetPoint(k, pointadr[i]);
k++;
op->SetPoint(k, pointadr[j+1]);
k++;
}
}
op->Message(MSG_UPDATE);
}
Here’s a scene file that shows how it works.
I guess this can be further developed into a generator object much like the Mograph Tracer. Unfortunately I don’t have the time do make it, as I’m working on a few plugins at the moment.
Cheers!
-gene