Hexagon Grid

calendar_today

03.04.2022

label

Modeling, VEX, Hard-surface

mouse

16.0

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.

// 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);
    }
}
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