tips mainly for Houdini

Run over "Detail"

Attributes are not interporated in this code

string in0 = @OpInput1;
int nprims = nprimitives(in0);

int op;
string operation = chs("keep");
if(operation == "above")op= 1;
if(operation == "below")op= 2;
else op= 0;

vector cutDir = normalize(chv("cutDir"));
vector cutOrigin = chv("cutOrigin");
float dist = ch("dist");

//////////////////////////////////////////////////////////////////

for(int primnum = 0; primnum < nprims; primnum++)
{
    int vers[] = primvertices(0, primnum);
    int length = len(vers);
    
    int border=0;
    int prim0pts[];
    int prim1pts[];
    int numNewPts = 0;
    
    // check if this mesh is split
    for(int i = 0; i< length; i++)
    {
        int srcPoint = vertexpoint(in0, vers[i]);
        vector srcP = point(in0, "P", srcPoint);
        vector srcPDir = normalize(srcP - cutOrigin);
        
        float dot = dot(cutDir, srcPDir);
        
        if(dot<=0)border += 1;
    }
    
    // if it is not cut, maybe remove and done.
    if(border == 0)
    {
        if(op == 2)removeprim(geoself(),primnum,1);
        //        continue;continue;
    }
    else if(border == length)
    {
        if(op == 1)removeprim(geoself(),primnum,1);
        //continue;
    }
    
    else
    {
        // cut mesh
        int srcPoint;
        float srcDot;
        
        for(int i = 0; i< length; i++)
        {
            int hedge = vertexhedge(in0, vers[i]);
            
            //int primary = hedge_isprimary(in0, hedge);
            //if(primary == 0)continue;
            
            int destVtx = hedge_dstvertex(in0, hedge);
                    
            srcPoint = vertexpoint(in0, vers[i]);
            int destPoint = vertexpoint(in0, destVtx);
            vector srcP = point(in0, "P", srcPoint);
            vector destP = point(in0, "P", destPoint);
            
            vector srcPDir = normalize(srcP - cutOrigin);
            vector destPDir = normalize(destP - cutOrigin);
            srcDot = dot(cutDir, srcPDir);
            float destDot = dot(cutDir, destPDir);
            
            if(srcDot > 0)
            {
                push(prim0pts, srcPoint);
            }
            else if(srcDot == 0)
            {
                push(prim0pts, srcPoint);
                push(prim1pts, srcPoint);
            }
            else if(srcDot < 0)
            {
                push(prim1pts, srcPoint);
            }
            
            
            if((sign(srcDot) != sign(destDot)) && srcDot != 0 && destDot != 0)
            {
                //@Cd=set(float(i)/length, float(border)/length, 0);
                float bias = -destDot/(srcDot - destDot);
                int newPt = addpoint(geoself(), lerp(destP, srcP, bias));
                push(prim0pts, newPt);
                push(prim1pts, newPt);
        
                numNewPts += 1;
            }
        }
        
        
        
        // remove original mesh, and add 2 meshes which cover original
        
        removeprim(geoself(),primnum,1);
        if(op != 2)
        {
            int newPrim = addprim(geoself(), "poly");
            foreach(int pt; prim0pts)
            {
                addvertex(geoself(), newPrim, pt);
            }
        }
        if(op != 1)
        {
            int newPrim = addprim(geoself(), "poly");
            foreach(int pt; prim1pts)
            {
                addvertex(geoself(), newPrim, pt);
            }
        }
    }
}
タグ

Wiki内検索

管理人/副管理人のみ編集できます