Curves
Create frame for one segment in a poly curve
Section titled “Create frame for one segment in a poly curve”The polyframe sop doesn’t work with curves primitives with only one segment (2 points) this is a solution to build a frame with only two points
//run over pointsvector up = {0,1,0};vector bitangent = cross(up, v@tangentu); // generated from resample nodev@tangentv = bitangent;v@N = cross(v@tangentu, bitangent);
Cardioids
Section titled “Cardioids”// I dislike this one because the curve does not start at the origin// Check the half cardiod comment in the next snippetint numiter = 100;
vector pos = {0,0,0};float segm_angle = 2*M_PI/numiter;float angle = 0;
for (int i = 0; i < numiter; ++i){ float r = 1 - sin(angle); pos.x = r*cos(angle); pos.z = -r*sin(angle); addpoint(0, pos); angle = angle + segm_angle;}
Half Cardioid
int numiter = chi("num_points");
vector pos = {0,0,0};//float segm_angle = 2*M_PI/numiter;// full cardioidfloat segm_angle = M_PI/numiter;float angle = 0;
for (int i = 0; i < numiter; ++i){ pos.z = -cos(angle)*(1-cos(angle)); pos.x = sin(angle)*(1-cos(angle)); int id = addpoint(0, pos); setpointattrib(0, "id", id, id, "set"); angle = angle + segm_angle;}
pos.x = 0;//force last point to axissetpointattrib(0, "P", numiter-1, pos, "set");
Curves misc
Section titled “Curves misc”The following curves code was obtained from vex --- John Svensson
-
Curve U Map
Curve U Map - Runs over several primitives
Creates two point attributes. One 0 - 1 and one 0 - 1 - 0 along each curve, based on point number / vertex order for each primitive.
Run in a Wrangle SOP (Run over - Primitives)
vex float umap, umap_half;addattrib(geoself(), "point", "umap", 0.0);addattrib(geoself(), "point", "umap_half", 0.0);prim_points = primpoints(geoself(), @primnum);for ( int i = 0; i < len(prim_points); i++ ){umap = float(i) / (len(prim_points) - 1);umap_half = clamp(umap, 0, 0.5) * clamp(umap * -1 + 1, 0, 0.5) * 4;setattrib(geoself(), "point", "umap", prim_points[i], 0, umap, "set");setattrib(geoself(), "point", "umap_half", prim_points[i], 0, umap_half, "set");} -
Curve Normals
Curve Normals - Runs over a single primitive
Creates a normal along a single curve, two point based, un normalized
Run in a Wrangle SOP (Run over - Points)
vex vector pos, nor_a, nor_b;if ( @ptnum == 0) {getattribute(@OpInput1, pos, "point", "P", @ptnum + 1, 0);@N = @P - pos;} else if ( @ptnum == (npoints(@OpInput1) - 1) ) {getattribute(@OpInput1, pos, "point", "P", @ptnum - 1, 0);@N = pos - @P;} else {getattribute(@OpInput1, pos, "point", "P", @ptnum - 1, 0);nor_a = pos - @P;getattribute(@OpInput1, pos, "point", "P", @ptnum + 1, 0);nor_b = @P - pos;@N = (nor_a + nor_b) / 2;} -
Filter the first and last point of a curve
Used to group points in a group expression or in a smooth points nodes
vex // vex expression@ptnum==@numpt-1||@ptnum==0