Skip to content

Instantly share code, notes, and snippets.

@yone80
Last active December 2, 2020 03:41
Show Gist options
  • Save yone80/bf2c85bb73dea35c5d6a to your computer and use it in GitHub Desktop.
Save yone80/bf2c85bb73dea35c5d6a to your computer and use it in GitHub Desktop.
VEXpression
/* Initialize */
float curvelength = primintrinsic(1, 'arclength', 0);
if( curvelength == 0 )
curvelength = primintrinsic(1, 'measuredperimeter', 0);
float dist = @P.z / curvelength + ch('offset');
vector2 uv = set(dist, 0);
// PRIMUV_UNITLEN_TO_UNIT = 7
vector2 posuv = primuvconvert(@OpInput2, uv, 0, 7);
/* Point on Curve */
vector curvepos;
float epsilon = 1e-5;
if(dist < 0)
{
posuv = {0, 0};
vector p1 = primuv(1, 'P', 0, posuv);
vector p2 = primuv(1, 'P', 0, set(epsilon, 0, 1));
vector v1 = normalize(p2 - p1) * curvelength;
curvepos = p1 + v1 * dist;
}
else if(dist > 1)
{
posuv = {1, 0};
vector p1 = primuv(1, 'P', 0, set(1 - epsilon, 0, 1));
vector p2 = primuv(1, 'P', 0, posuv);
vector v1 = normalize(p2 - p1) * curvelength;
curvepos = p2 + v1 * (dist - 1);
}
else
{
curvepos = primuv(1, 'P', 0, posuv);
}
/* Transform */
vector N = primuv(1, 'N', 0, posuv);
vector up = primuv(1, 'up', 0, posuv);
matrix m = maketransform(N, up, curvepos);
@P.z = 0.0;
@P *= m;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment