Fitting UV Islands into a Grid

calendar_today

22.11.2023

label

VEX, Texturing

mouse

Houdini 20

Description

Proportionally scaling and positioning each UV island into a unique grid cell based on UV connectivity and per-primitive bounding boxes.

The polygons of the grid can potentially be scaled and moved individually to assign varying cell sizes for the UV islands, enable facet1 and primitive1 nodes to see this.

1 Code

C
        float pad = chf('padding');
int class = prim(0, 'class', i@primnum);

// GRID
string geo_tile = geounwrap(1, 'uv');
vector tile_min = getbbox_min(geo_tile, itoa(class));
vector tile_max = getbbox_max(geo_tile, itoa(class));
vector size_tile = getbbox_size(geo_tile, itoa(class));

// MESH
string geo_mesh = geounwrap(0, 'uv');
string grp_mesh = '@class==' + itoa(class);
vector size_mesh = getbbox_size(geo_mesh, '@class==' + itoa(class));

// ASPECT
vector aspect_tile = size_tile / min(size_tile.x, size_tile.y);
vector aspect_mesh = size_mesh / max(size_mesh.x, size_mesh.y);
vector aspect = aspect_mesh / aspect_tile;

// FIT
vector bb = relbbox(geo_mesh, grp_mesh, v@uv) * aspect;
bb = fit01(bb, pad, 1.0 - pad);
vector uv = fit01(bb, tile_min, tile_max);

v@uv = uv;
    
download

Downloads

link

Related articles

favorite

354

label

VEX

Attribute to match across inputs

favorite

238

label

VEX

Sphere Packing / Dart Throwing Algorithm

favorite

265

label

VEX

Deintersecting spheres with Voronoi

favorite

298

label

VEX

Fitting Planes to Point Clouds

favorite

307

label

VEX

How to Analyze VEX Code

favorite

143

label

VEX

Monte Carlo Geometry Processing