Copying one-unit Lego bricks to a grid of points that are oriented to perpendicular volume gradients.
Sampling gradients from volume:
v@grad = normalize(volumegradient(1, 'surface', v@P));
Perpendicular point normals based on gradient vectors:
v@N = v@grad;
int side = abs(v@N.x) > abs(v@N.z);
v@N.y = 0.0;
v@N.x = side ? sign(v@N.x) : 0;
v@N.z = side ? 0 : sign(v@N.z);
v@up = {0,1,0};
Assigning variant numbers (0 or 1) based on the longest gradient vector component:
float angle = chf('angle');
i@variant = max(abs(v@grad)) < angle;