Vexercise 4 – break curves

//break the primitives into shorter lines
//each prim will only contain 2 vertices (option)  limitVerts

for (int i = 0; i<@numprim; i++) {
    int numVerticies = primvertexcount(0, i);
    int vtxPrim = i;
    int lastPrimVtxCount = 0;
    int lastPointNum = 0;
    for (int j = 0; j <numVerticies; j++) {
        //store vertex point & prim
        int vtxNum = primvertices(0, i)[j];
        int vtxPoint = vertexpoint(0, vtxNum);
          
        //remove the vertex
        removevertex(0, vtxNum);

        //check if we should start a new prim
        if(random(vtxNum) > ch('../breakRatio')) {
            vtxPrim = addprim(0, "polyline");
            if(lastPrimVtxCount == 1) removepoint(0, lastPointNum); // if the prim only has 1 vert then delete the point
            lastPrimVtxCount = 0;
        }
        
        //create new vertex for current prim with current point     
        addvertex(0, vtxPrim, vtxPoint);
        lastPointNum = vtxPoint;
        lastPrimVtxCount += 1;
    }
}