Shorten curves

calendar_today

04.06.2022

label

VEX, Modeling

mouse

Houdini 19.0

1 Introduction

A few methods for shortening curves by absolute distances, unlike relative when using the carve node.

2 Shifting inwards

Instead of cutting curves and removing points, we can shift point positions of curves along themselves.

Linear interpolation while shifting points inwards along the curve:

float shorten = chf('shorten');

float perim = primintrinsic(0, 'measuredperimeter', i@primnum);
float inset = shorten / perim;

float u = vertexprimindex(0, i@vtxnum) / (primvertexcount(0, i@primnum) - 1.0);
u = fit01(u, inset, 1.0 - inset);
vector uvw = set(u, 0.0, 0.0);
vector pos = primuv(0, 'P', i@primnum, uvw);

v@P = pos;

Smooth interpolation while shifting points inwards along the curve:

float shorten = chf('shorten');

float perim = primintrinsic(0, 'measuredperimeter', i@primnum);
float inset = shorten / perim;

int pts[] = primpoints(0, i@primnum);
insert(pts, 0, pts[0]);
append(pts, pts[-1]);

vector poss[] = {};
foreach(int pt; pts){
    vector pos_pt = point(0, 'P', pt);
    append(poss, pos_pt);
}

float u = vertexprimindex(0, i@vtxnum) / (primvertexcount(0, i@primnum) - 1.0);
u = fit01(u, inset, 1.0 - inset);
vector pos = spline('cubic', u, poss);

v@P = pos;

3 Cutting with groom

In a primitive wrangle we can cut curves (internally removing points and moving the last point) using <groom.h>.

#include <groom.h>

float shorten = chf('shorten');

float perim = primintrinsic(0, 'measuredperimeter', i@primnum);
adjustPrimLength(0, i@primnum, perim, perim - shorten);
download

Downloads