Can't stop redraw calls recalculate splines



  • On 02/08/2013 at 19:21, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   r14 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    I am writing a plugin, which generates splines between the points of two children of my plugin, and cannot stop the splines from being recalculated on each draw call in Cinema 4d, because the dirty flag always returns true. I tried to add some objects to the dependency list, but so far it did not help. I see no information or solid examples (I looked at the code in triangulate.cpp and others, and tried to mimic it), that would work in my case. Since my objects can have thousand of points, with the recalcuation, which happens on each redraw call, the plugin is not usable at all. I would appreciate pointing me in the right direction.

    Thanks.

    --8

    Here is my code (it is based on the maze_trace open source plugin) :

    > BaseObject *TSPData::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
    >
    > {
    >
    >     
    >
    > BaseObject *orig = op->GetDown();
    >
    >     
    >
    > if (!orig) return NULL;    
    >
    >     BaseObject *origSibling = orig->GetNext();
    >
    >     if (!origSibling) return NULL;    
    >
    >     // start new list
    >
    > op->NewDependenceList();
    >
    >
    >
    >
    > Bool dirty=FALSE;
    >
    > Matrix ml;
    >
    > BaseObject *child = op->GetAndCheckHierarchyClone(hh,orig,HIERARCHYCLONEFLAGS_ASPOLY,&dirty,NULL,FALSE);
    >
    >     BaseObject *sibling = op->GetAndCheckHierarchyClone(hh,origSibling,HIERARCHYCLONEFLAGS_ASPOLY,&dirty,NULL,FALSE);    
    >
    > BaseThread    *bt=hh->GetThread();
    >
    > BaseContainer *data = op->GetDataInstance();
    >
    > Real maxSeg = data->GetReal(CTTSPOBJECT_MAXSEG,3.);
    >
    > Bool relativeMaxSeg  = data->GetBool(CTTSPOBJECT_REL,TRUE);
    >
    > if (!dirty) dirty = op->CheckCache(hh);
    >
    > if (!dirty) dirty = op->IsDirty(DIRTYFLAGS_DATA);
    >
    >     // mark child objects as processed
    >
    > op->TouchDependenceList();
    >
    > if (!dirty) return op->GetCache(hh);
    >
    >  BaseObject    *main = BaseObject::Alloc(Onull);
    >
    > GeDynamicArray<Vector> childPoints;
    >
    > GeDynamicArray<Vector> siblingPoints;
    >
    > StatusSetBar(0);
    >
    > StatusSetText("Collecting Points");
    >
    > DoRecursion(op,child,childPoints, ml);
    >
    > DoRecursion(op,sibling,siblingPoints, ml);
    >
    > StatusSetBar(5);
    >
    > rng.Init(1244);
    >
    > KDNode *kdTree;
    >
    > buildKDTree(childPoints, &kdTree, rng);
    >
    > LONG pcnt = siblingPoints.GetCount();
    >
    > if(pcnt > 0){
    >
    > GeDynamicArray<LONG> pointList(pcnt);
    >
    > LONG currentPoint = 0;
    >
    > for(LONG i=0;i<pcnt;i++){
    >
    > pointList[i] = 1;
    >
    > }
    >
    > pointList[0] = 0;
    >
    > StatusSetText("Connecting Points");
    >
    > Real dist;
    >
    > for(LONG i=0;i<pcnt;i++){
    >
    > dist = -1.;
    >
    > LONG closestPoint = kdTree->getNearestNeighbor(childPoints,siblingPoints[i],pointList, dist, 0);
    >
    > if(closestPoint == -1){
    >
    > GePrint("error finding neighbor");
    >
    > pcnt = i-1;
    >
    > break;
    >
    > }
    >
    >  pointList[closestPoint] = 0;           
    >
    >             Vector *padr;
    >
    >             SplineObject *spline=SplineObject::Alloc(2,SPLINETYPE_LINEAR); //http://www.microbion.co.uk/graphics/c4d/create_plugins4b.htm
    >
    >             if (!spline) continue;
    >
    >             spline->GetDataInstance()->SetBool(SPLINEOBJECT_CLOSED, FALSE);
    >
    >             padr = spline->GetPointW();
    >
    >             Vector p2 = childPoints[closestPoint];
    >
    >             padr[0] = siblingPoints[i];
    >
    >             padr[1] = p2;
    >
    > spline->Message(MSG_UPDATE);
    >
    >             spline->SetName(child->GetName());
    >
    >             spline->InsertUnder(main);
    >
    >             if(i % 20 == 0){
    >
    > StatusSetBar(10 + (90*i)/pcnt);
    >
    > if (bt && bt->TestBreak()){
    >
    > pcnt = i;
    >
    > break;
    >
    > }
    >
    > }
    >
    > }
    >
    > }
    >
    > GeFree(kdTree);
    >
    > StatusClear();
    >
    > return main;
    >
    > Error:
    >
    > BaseObject::Free(child);
    >
    >     BaseObject::Free(child);
    >
    > return NULL;
    >
    > }


Log in to reply