Hexagon Grid

calendar_today

03.04.2022

label

Modeling, VEX, Hard-surface

mouse

16.0

Description

Setting up a hexagonal grid in SideFX Houdini.

1 Code

An implementation of a hexgrid algorithm can be done by connecting two attribwrangles: Set the first one to detail and the second one to run over points.

C
        // Creates a point grid in detail mode
for(int j = 0; j < 10; j++){
    float shift_x = ( (j + 1) % 2 ) * 0.5;
    float shift_z = j * 0.75;
    for(int i = 0; i < 10; i++) {
        vector pos = set(i + shift_x, 0, shift_z);
        addpoint(0, pos);
    }
}
    
C
        int prim = addprim(0, "poly");
float height = (sqrt(3)/2) * 0.5;
float width  = 0.5;
for(int i = 0; i < 6; i++) {
    float angle_deg = 60 * i + 30;
    float angle_rad = $PI / 180 * angle_deg;
    vector pos      = set(v@P.x + width * cos(angle_rad), 0, v@P.z + height * sin(angle_rad) );
    
    int pt = addpoint(0, pos);
    addvertex(0, prim, pt);
}

removepoint(0, i@ptnum);
    

Source: http://www.redblobgames.com/grids/hexagons/

download

Downloads

link

Related articles

favorite

174

label

Modeling

Adaptive Resampling of Curves

favorite

321

label

Modeling

Applying Scales to Mesh Surfaces

favorite

279

label

Modeling

Approximating subdivision surfaces

favorite

220

label

Modeling

Blending COPs SDFs into 3D Volume

favorite

312

label

Modeling

Branching Subdivision Curves

favorite

166

label

Modeling

Circuit Networks