Skip to content

Primitives

Add point in middle of prim and transfer attrib

Section titled “Add point in middle of prim and transfer attrib”
vex
string attribute_name = chs("attribute_name");
int attrib_val = prim(0, attribute_name, @primnum);
int ptn = addpoint(0,@P);
setpointattrib(0, attribute_name, ptn, attrib_val, "set");
removeprim(0, @primnum, 1);
vex
// over primitives
int vertices[] = primvertices(0, @primnum);
vector zero = {0,0,0};
foreach(int vtx ; vertices){
setvertexattrib(0, "uv", vtx, -1, zero, "set");
}

Why a -1, and the vertex num as the primnum? In this example the vertices are LINEAR vertices. To use the setvertexattrib function take into account:

To use a linear vertex index, set the prim_num to the linear vertex number and set vertex_num to -1. Note that this is different from how most other vertex functions work. setvertexattrib docs

vex
// run over prims
// input 0, a geo with initialized uvs at 0,0,0
// input 1, a geo with identical topology
int prim_verts[] = primvertices(1, @primnum);
// Just to test
if (@primnum==293){
printf("prim: %g vertices %g\n", @primnum,len(prim_verts));
foreach(int i; prim_verts){
printf("linear vert: %g , ", i);
}
}
foreach(int i; prim_verts){
vector uv = vertex(1, "uv", i);
setvertexattrib(0, "uv", i, -1, uv, "set"); // -1 because linear vertices
}