stassius

Primitive Join - Houdini VEX

Aug 3rd, 2017
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. // FUNCTIONS
  2. void removedups(int pts[])
  3. {
  4. int end=len(pts);
  5. int ct1=0, ct2;
  6.     while(ct1<end)
  7.     {
  8.         ct2=ct1+1;
  9.             while(ct2<end)
  10.                 {
  11.                     if (pts[ct2]==pts[ct1])
  12.                         {
  13.                             removeindex(pts,ct2);
  14.                             end--;
  15.                             }
  16.                     ct2++;
  17.                 }
  18.        ct1++;                
  19.     }
  20. }
  21.  
  22. // START
  23. int pts[];
  24. int prims=nprimitives(0);
  25. int pt=0;
  26. for(int i=0;i<npoints(0);i++)
  27.     if (neighbourcount(0,i)==1) pt=i;
  28.  
  29. int temp[]=pointprims(0,pt);
  30. int prim=temp[0];
  31. push(pts,pt);
  32.  
  33. // Create an array of points
  34. for (int j=0;j<prims;j++)
  35. {
  36.     int nepts[]=primpoints(0,prim);
  37.     removedups(nepts);
  38.     if (pt!=nepts[0]) nepts=reverse(nepts);
  39.     removeindex(nepts,0);
  40.     append(pts,nepts);      
  41.     pt=nepts[len(nepts)-1];      
  42.     int prs[]=pointprims(0,pt);
  43.     int is=1;
  44.     while (is)
  45.         is=removevalue(prs,prim);
  46.     prim=prs[0]; // Next primitive to use
  47. }
  48.  
  49. //Delete all geo except points
  50. for (int i=0;i<prims;i++)
  51.     removeprim(geoself(),i,0);
  52.  
  53. // Create new polygon and wire points
  54. int newprim=addprim(geoself(),"polyline");
  55. for (int i=0;i<len(pts);i++)
  56. {
  57.        addvertex(geoself(),newprim,pts[i]);      
  58. }
Advertisement
Add Comment
Please, Sign In to add comment