Skip to content

Functions

Match a name to point id

Port 1: Voronoi fracture with named primites Port 2: Found centroid of each voronoi cell -> each centroid has a distance attribute Transfer the centroid attribute to each named primitive points

vex
// run over primitives
string piece_name = s@name;
//findattribval(1, "point", "name", piece_name,
int anc_ptnum = nametopoint(1, piece_name);
if (anc_ptnum == -1) return;
float dist = point(1, "dist", anc_ptnum);
f@dist = dist;

Source file: monolith

I was using findattrival BUT: The most common use cases (finding an point/primitive by its name or id attribute) have easier-to-use dedicated wrapper functions: nametopoint, nametoprim, idtopoint, and idtoprim. (vex reference)

Set attribute metadata type info

VEX reference : Attribute type metadata

vex
setattribtypeinfo

To equirectangular

Not the same as using ‘topolar’ and ‘frompolar’ in a VOP

vex
//to spherical first
float theta = atan2(@P.z, @P.x);
float phi = acos(@P.y);
float rho = length(@P); // if radius == 1 then rho = 1
//rad to deg
float long = degrees(theta);
float lat = degrees(phi);
//fit
float x = fit(long, -180.0, 180, 0, 1);
float z = fit(lat, 0, 180, 0, 1);
// x by 2
@P = set(x*2, 0, z);

From cartesian to spherical and back

vex
//to spherical
//sphere of radius 1
float theta = atan2(@P.z, @P.x);
float phi = acos(@P.y);
//float rho = length(@P); // rad == 1
float rho = 1;
//to cartesian
float x = rho * sin(phi) * cos(theta);
float z = rho * sin(phi) * sin (theta);
float y = rho * cos (phi);
@P = set(x, y, z);