Skip to content

Instantly share code, notes, and snippets.

@sortofsleepy
Created May 23, 2020 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sortofsleepy/b50f2879a318ea38981fec175d234260 to your computer and use it in GitHub Desktop.
Save sortofsleepy/b50f2879a318ea38981fec175d234260 to your computer and use it in GitHub Desktop.
Example of how to copy geometry with a VEX node in Houdini.
int numVerts = nvertices(1);
int numPoints = npoints(1);
int numPrim = nprimitives(1);
int ptTally = 0;
// copy all the primitives,vertex data, and indices.
for(int p = 0; p < numPrim; ++p){
int prim = addprim(0,"poly");
// get vertices for primitive
int primverts[] = primvertices(1,p);
for(int a = 0; a < len(primverts);++a){
int pt = vertexpoint(1,primverts[a]);
addpoint(0,pt);
addvertex(0,prim,pt);
ptTally += 1;
}
}
// the last process will create a glut of points that we need to trim.
// we will also need to give those points value.
for(int i = ptTally; i > numPoints - 1; --i){
removepoint(0,i);
}
// re-value the point positions on the output
for(int i = 0; i < npoints(1); ++i){
vector pos = point(1,"P",i);
setpointattrib(0,"P",i,pos);
}
@sortofsleepy
Copy link
Author

I am learning Houdini and I was trying to think of how to copy a piece of geometry completely in VEX. This is probably not something done often if at all but the problem bugged me enough that I spent far too much time working on it.

This assumes your node is set to Detail for the Run Over setting and that the geometry you want to copy is wired to input 1 with input 0 being free.

Hopefully this is helpful to someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment