HDK local variables and updating the Viewport

   171   0   0
User Avatar
Member
7 posts
Joined: Jan. 2023
Offline
Hello, I have been trying to implement a resampling function with the hdk. I used the SOP/SOP_Flatten.C example as a reference which has a helpful comment about using local variables and the viewport. However, I still cannot get the viewport to update when deleting points, i.e, updating my parameter. I can see the geometry spreadsheet update, but when the display flag is on the C++ node, the viewport does not update, I was wondering if anyone has encountered this issue and has any suggestions. Any help?

OP_ERROR MapResample::cookMySop(OP_Context& context)
{
    OP_AutoLockInputs inputs(this);
    if (inputs.lock(context)>= UT_ERROR_ABORT)
        return error();

    fpreal now = context.getTime();
    duplicateSource(0, context);
    setVariableOrder(3,2,0,1);
    setCurGdh(0, myGdpHandle);

    setupLocalVars();

    fpreal target = evalFloat("target", 0, now);
    target /= gdp->getNumPoints();
    

    GA_RWHandleV3 pos_h(gdp->getP());
    if (!pos_h.isValid())
        return error();
    
    UT_Array<GA_Offset> pointsToDelete;

    GA_Range pts_range = gdp->getPointRange();
    GA_Size numPoints = pts_range.getMaxEntries();

    for (GA_Iterator it(pts_range); !it.atEnd(); ++it)
    {
        GA_Offset ptoff = *it;
        GA_Index idx = gdp->pointIndex(ptoff);

        myCurPtOff[0] = ptoff;

        if (idx ==0 || idx == numPoints-1)
            continue;

        UT_Vector3 curPos = pos_h.get(ptoff);

        if (idx + 2 >=numPoints)
            continue;

        GA_Offset nextOffset = gdp->pointOffset(idx+1);
        UT_Vector3 nextPos = pos_h.get(nextOffset);

        GA_Offset secondNextOffset = gdp->pointOffset(idx+2);
        UT_Vector3 secondNextPos = pos_h.get(secondNextOffset);

        UT_Vector3 edge1 = curPos - nextPos;
        UT_Vector3 edge2 = curPos - secondNextPos;

        UT_Vector3 crossVector = cross(edge1, edge2);
        fpreal area = crossVector.length() /2.0f;

        if (area< target)
        {
            pointsToDelete.append(ptoff);
        }
        
    }
    
    for (GA_Offset i = 0; i < pointsToDelete.size(); i++)
    {
        gdp->destroyPointOffset(pointsToDelete(i));
        
    }
    resetLocalVarRefs();
    triggerOutputChanged();
    return error();
}
Edited by getuffassassin11 - yesterday 03:44:35
  • Quick Links