Hi,
I've been wondering if anyone tried to recreate the polyextrude sop in vex? I'm particularly interested in the inset function of the sop, and how one would go about recreating this in vex.
Any ideas?
Thanks in advance.
PolyExtrude in VEX
6266 10 2- Shasha
- Member
- 18 posts
- Joined: 10月 2010
- Offline
- ouroboros1221
- Member
- 79 posts
- Joined: 2月 2016
- Offline
- Andr
- Member
- 899 posts
- Joined: 2月 2016
- Offline
- Shasha
- Member
- 18 posts
- Joined: 10月 2010
- Offline
Andr
following this thread.
I always wanted to try to build one in vex because the original one can't be compiled.
That's exactly why I'm asking hehe.
ouroboros1221
you just need to add points in the direction of a surface's normal, connect the dots and make a surface out of it
Thanks for your answer.I guess I'm looking for a bit more specific information on how to do that. Sorry my question wasn't clear enough.
- ouroboros1221
- Member
- 79 posts
- Joined: 2月 2016
- Offline
- Nicolas Longchamps
- Member
- 37 posts
- Joined: 8月 2015
- Offline
Simple VEX inset. Run over prims.
Ideally you also interpolate point and vertex attributes on the inset points.
vector centerPoint = v@P ; int pts[] = primpoints(0,@elemnum); int newPTS[] = {}; //generate inset points foreach( int pt ; pts ) { vector pos = point(0,'P',pt); vector insetPos = lerp(pos,centerPoint,ch('inset')); int newPt = addpoint(0,insetPos); append(newPTS,newPt); } //inset prim int prCenter = addprim(0,'poly',newPTS); //contour prims for(int i=0; i<len(pts); i++) { int pr = addprim(0,'poly'); addvertex(0,pr,pts[i-1]); addvertex(0,pr,pts[i]); addvertex(0,pr,newPTS[i]); addvertex(0,pr,newPTS[i-1]); } //remove original prim removeprim(0,@elemnum,0);
Ideally you also interpolate point and vertex attributes on the inset points.
- Shasha
- Member
- 18 posts
- Joined: 10月 2010
- Offline
ouroboros1221
Here I made a simple example, it's up to you to figure out how to procedurally organize the points so you don't have to type them in.
Thank you. Unfortunately, your file doesn't work properly, geometry is all messed up with open prims flying everywhere. But it's a starting point.
Nicolas Longchamps
Simple VEX inset. Run over prims.vector centerPoint = v@P ; int pts[] = primpoints(0,@elemnum); int newPTS[] = {}; //generate inset points foreach( int pt ; pts ) { vector pos = point(0,'P',pt); vector insetPos = lerp(pos,centerPoint,ch('inset')); int newPt = addpoint(0,insetPos); append(newPTS,newPt); } //inset prim int prCenter = addprim(0,'poly',newPTS); //contour prims for(int i=0; i<len(pts); i++) { int pr = addprim(0,'poly'); addvertex(0,pr,pts[i-1]); addvertex(0,pr,pts[i]); addvertex(0,pr,newPTS[i]); addvertex(0,pr,newPTS[i-1]); } //remove original prim removeprim(0,@elemnum,0);
Ideally you also interpolate point and vertex attributes on the inset points.
Thank you for your example. Simple indeed but very interesting.
- ouroboros1221
- Member
- 79 posts
- Joined: 2月 2016
- Offline
- ouroboros1221
- Member
- 79 posts
- Joined: 2月 2016
- Offline
v@extrude_distance = @N * chf("distance"); int @pts[]; int @ptsOnPrim[]; @ptsOnPrim = primpoints(0,chi("selection")); foreach(int pt; @ptsOnPrim) { vector pos = point(0,"P",pt); i@point = addpoint(0, pos + v@extrude_distance); append(@pts,@point); //setpointattrib(0,"pts",@primnum,@pts,"set"); } int i = 0; int j =0; addprim(0,"poly",@pts[i+2],@pts[i+1],@pts[i],@pts[i+3]); addprim(0,"poly",@ptsOnPrim[j+1],@ptsOnPrim[j],@pts[i],@pts[i+1]); addprim(0,"poly",@ptsOnPrim[j],@pts[i],@pts[i+3],@ptsOnPrim[j+3]); addprim(0,"poly",@ptsOnPrim[j+1],@pts[i+1],@pts[i+2],@ptsOnPrim[j+2]); addprim(0,"poly",@ptsOnPrim[j+2],@pts[i+2],@pts[i+3],@ptsOnPrim[j+3]); if(@primnum==chi("selection")) { removeprim(0,@primnum,1); }
only works with a grid and it has duplicated primitives, waiting for some more advanced user to improve the code
- juggler7
- Member
- 4 posts
- Joined: 9月 2021
- Offline
Here is my solution, works well, but only with quads, connect a grid into the 0 input of a primitive wrangle:
...well, it works...the tricky bit is creating the 'side' faces...if you know the extruded poly is a quad, you can 'cheat' by creating the faces in a predefined order:
However, the code will break if the extruded face has more or less than 4 points...
The code that works for any n-gon will be something like:
1)calculate how many new points were created, say 'total points'
2)for i in the range of newly created points:
3)create a polygon(@conn_pts,@newpt_list,@newpt_list,@conn_pts....
4)and then the 'exception': create a polygon(@newpt_list,@newpt_list,@conn_list,@conn_pts
//Vex 'extrude' function...Only works with 4 sided faces!!! //pick a polygon face/primitive int index = chi("Primitive_Index"); //this array will hold newly created points i[]@newpt_list; //let's extrude the selected primitive (using Primitive //Index we created above) if(@primnum == index){ //set selected prim color to white - just a visual aid @Cd = {1,1,1}; //primpoints function gives us all the connected //points, as index values i[]@conn_pts = primpoints(0,@primnum); //let's run through this points list, and then //create a new point above them foreach (int pt;@conn_pts) { //get the connected points position vector vector curr_pos = point(0,"P",pt); //create an offset vector, this will be our extrude amount vector offset = set(0,chf("offset"),0); //calculate the new position, adding old pos with offset vector new_pos = curr_pos + offset; //create a new point at this new position vector int newpt = addpoint(geoself(),new_pos); //add the new point index to an array, will need these indexes //to create the top and side faces append(@newpt_list,newpt); } //create the 'side' poly faces - this bit needs more 'elegance' addprim(0,"poly",@conn_pts[3],@newpt_list[3],@newpt_list[2],@conn_pts[2]); addprim(0,"poly",@conn_pts[2],@newpt_list[2],@newpt_list[1],@conn_pts[1]); addprim(0,"poly",@conn_pts[1],@newpt_list[1],@newpt_list[0],@conn_pts[0]); addprim(0,"poly",@newpt_list[0],@newpt_list[3],@conn_pts[3],@conn_pts[0]); //remove the original prim face removeprim(geoself(),@primnum,0); //create the new 'top' poly face addprim(0,"poly",@newpt_list); } //color non-selected prims blue, visual aid else{ @Cd = {0,0.5,1}; }
...well, it works...the tricky bit is creating the 'side' faces...if you know the extruded poly is a quad, you can 'cheat' by creating the faces in a predefined order:
//create the 'side' poly faces - this bit needs more 'elegance' addprim(0,"poly",@conn_pts[3],@newpt_list[3],@newpt_list[2],@conn_pts[2]); addprim(0,"poly",@conn_pts[2],@newpt_list[2],@newpt_list[1],@conn_pts[1]); addprim(0,"poly",@conn_pts[1],@newpt_list[1],@newpt_list[0],@conn_pts[0]); addprim(0,"poly",@newpt_list[0],@newpt_list[3],@conn_pts[3],@conn_pts[0]);
However, the code will break if the extruded face has more or less than 4 points...
The code that works for any n-gon will be something like:
1)calculate how many new points were created, say 'total points'
2)for i in the range of newly created points:
3)create a polygon(@conn_pts,@newpt_list,@newpt_list,@conn_pts....
4)and then the 'exception': create a polygon(@newpt_list,@newpt_list,@conn_list,@conn_pts
- juggler7
- Member
- 4 posts
- Joined: 9月 2021
- Offline
I have since improved my result to include polygons with any number of connected points, i.e. 3 or 5:
//pick a polygon face/primitive int index = chi("Primitive_Index"); //this array will hold newly created points i[]@newpt_list; //let's extrude the selected primitive (using Primitive //Index we created above) if(@primnum == index){ //set selected prim color to white - just a visual aid @Cd = {1,1,1}; //primpoints function gives us all the connected //points, as index values i[]@conn_pts = primpoints(0,@primnum); //let's run through this points list, and then //create a new point above them foreach (int pt;@conn_pts) { //get the connected points position vector vector curr_pos = point(0,"P",pt); //create an offset vector, this will be our extrude amount //vector offset = set(0,chf("offset"),0); vector offset = @N; //calculate the new position, adding old pos with offset vector new_pos = curr_pos + offset; //create a new point at this new position vector int newpt = addpoint(geoself(),new_pos); //add the new point index to an array, will need these indexes //to create the top and side faces append(@newpt_list,newpt); } int len_conn = len(@conn_pts); int len_newpt = len(@newpt_list); for (int i=0;i<len_newpt;i++) { addprim(0,"poly",@conn_pts[len_newpt-(i+1)],@newpt_list[len_newpt-(i+1)],@newpt_list[len_newpt-(i+2)],@conn_pts[len_newpt-(i+2)]); } //create the 'side' poly faces - this bit needs more 'elegance' //addprim(0,"poly",@conn_pts[3],@newpt_list[3],@newpt_list[2],@conn_pts[2]); //addprim(0,"poly",@conn_pts[2],@newpt_list[2],@newpt_list[1],@conn_pts[1]); //addprim(0,"poly",@conn_pts[1],@newpt_list[1],@newpt_list[0],@conn_pts[0]); //addprim(0,"poly",@newpt_list[0],@newpt_list[3],@conn_pts[3],@conn_pts[0]); //remove the original prim face removeprim(geoself(),@primnum,0); //create the new 'top' poly face addprim(0,"poly",@newpt_list); } //color non-selected prims blue, visual aid else{ @Cd = {0,0.5,1}; }
-
- Quick Links