setpointattrib not updating

   2162   1   2
User Avatar
Member
1 posts
Joined: June 2017
Offline
Hi,
I'm trying to constraint a curve to 90 degree by using attribute wrangle in DETAIL mode like as follow:

//read value from attribute:“edgedist” at index attrIndex
float ReadDistAttr(int arrIndex)
{
int suc;
float retDist= getattrib(0,“point”, “edgedist”,arrIndex,suc);
return retDist;
}

float ReadAngleAttr(int arrIndex)
{
int suc;
float retDist= getattrib(0,“point”, “fixedAng”,arrIndex,suc);
return retDist;
}


vector curPt,nextPt,crossV,targetPt;
for( int i=0;i<@numpt-1;i++)
{
curPt= point(0,“P”,i);
nextPt= point(0,“P”,i+1);
vector vecDiffNextCurNorm=normalize(nextPt-curPt);
float ang=ReadAngleAttr(i+1);

//addpoint(0,crossV+nextPt);
if( ang>0 && ang<=135 )
{
crossV=cross(vecDiffNextCurNorm,{0,1,0})*ReadDistAttr(i+1);
targetPt=crossV+nextPt;
setpointattrib(geoself(), “P”,i+2,targetPt);
//addpoint(0,targetPt);
}
else if( ang>225 && ang<=360 )
{
crossV=-cross(vecDiffNextCurNorm,{0,1,0})*ReadDistAttr(i+1);
targetPt=crossV+nextPt;
setpointattrib(geoself(), “P”,i+2,targetPt);
//addpoint(0,targetPt);
}
}

The problem is that the calculation always refer to the original points and not to the points that modified by setpointattrib function.

Help please
User Avatar
Member
1743 posts
Joined: March 2012
Offline
VEX only ever reads from the input geometry and writes to the output geometry, (with the caveat that attributes bound to VEX variables via the @ syntax can give the illusion of reading from the output, but it'll just be reading from a VEX variable, and that only gives access to the “current” element of that attribute). If you need to read from the output geometry, you either need a For Loop SOP block, or a separate Attribute Wrangle. In your case, however, that shouldn't be necessary, because your code only writes to positions two points ahead, so you can just keep track of the P values written using two vector variables, and you already have those variables, e.g.:

vector curPt= point(0,"P",0);
vector nextPt= point(0,"P",1);
for( int i=0;i<@numpt-1;i++)
{
    vector vecDiffNextCurNorm=normalize(nextPt-curPt);
    float ang=ReadAngleAttr(i+1);

    //addpoint(0,crossV+nextPt);
    vector targetPt;
    if( ang>0 && ang<=135 )
    {
        vector crossV=cross(vecDiffNextCurNorm,{0,1,0})*ReadDistAttr(i+1);
        targetPt=crossV+nextPt;
        setpointattrib(geoself(), "P",i+2,targetPt);
        //addpoint(0,targetPt);
    }
    else if( ang>225 && ang<=360 )
    {
        vector crossV=-cross(vecDiffNextCurNorm,{0,1,0})*ReadDistAttr(i+1);
        targetPt=crossV+nextPt;
        setpointattrib(geoself(), "P",i+2,targetPt);
        //addpoint(0,targetPt);
    }
    else if( i<@numpt-2 )
    {
        targetPt = point(0,"P",i+2);
    }

    // Shift back the point position variables for the next iteration
    curPt = nextPt;
    nextPt = targetPt;
}
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
  • Quick Links