how can one produce a hex grid in houdini ?

   2076   14   2
User Avatar
Member
11 posts
Joined: Sept. 2016
Offline
silly question but is there any quick or easy way to make a hexagonal grid in houdini ? would like to make a map based off a system using said grid in order to make a procedural map with more polished peaces to puzzle together.
User Avatar
Member
417 posts
Joined: May 2006
Offline
there's probably a sweet mathematical way, and my idiot way;

-put down a grid
-divide sop, enable ‘compute dual’
-transform sop rotate 45 degrees around Y
-another transform to scale it along x so the hexagons are symmetrical
-delete in bounds mode to trim it back to a square of hexagons

Attachments:
hexagons.gif (105.7 KB)
hexagons.hipnc (55.5 KB)

http://www.tokeru.com/cgwiki [tokeru.com]
User Avatar
Member
3713 posts
Joined: June 2012
Offline
haha nice! I think the platonic soccer ball copied your idea
2+2=4-1=3
User Avatar
Member
274 posts
Joined: Sept. 2013
Offline
A rough implementation of a hexgrid algorithm would be 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);
    }
}

// Draws hexagonal polygons on the grid
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(@P.x + width * cos(angle_rad), 0, @P.z + height * sin(angle_rad) );
    
    int pt = addpoint(0, pos);
    addvertex(0, prim, pt);
}

If you want to dig a tiny little deeper, here is the source:
http://www.redblobgames.com/grids/hexagons/ [redblobgames.com]
http://www.redblobgames.com/grids/hexagons/implementation.html [redblobgames.com]

Attachments:
hexgrid.jpg (28.5 KB)

www.konstantinmagnus.de
User Avatar
Member
11 posts
Joined: Sept. 2016
Offline
thank you all for the help. was stuck at work last few days. will be trying some of these methods out tonight.
User Avatar
Member
95 posts
Joined: Oct. 2016
Online
Hey!
Thanks for the examples shown.

@mestela
How you understood that we need to put 0.6 in second transform's x Scale to make polygons symmetrical? Is there a kind of logic in it or you've found that it works by tweaking scale?

@Konstantin Magnus
You have four nodes for this (grid + attribute wrangle + attribute wrangle + null)? I have source grid visible after hexagons are created, you've added some anoter node to delete it, or I did a mistake in code retyping and something there delete grid? Yours hexagons look the same sized on the image uploaded, but how do you know that they are? Is there something in written shows you that it is so? Using what in code you adjust spacing between hexagons?

Thanks for possible replies and advices
Edited by Ryu Ku - Nov. 22, 2017 06:06:35
User Avatar
Member
417 posts
Joined: May 2006
Offline
The 0.6 I just got by eyeballing it.
http://www.tokeru.com/cgwiki [tokeru.com]
User Avatar
Member
95 posts
Joined: Oct. 2016
Online
@mestela Thanks
User Avatar
Member
274 posts
Joined: Sept. 2013
Offline
Hi Ryu,

Ryu Ku
You have four nodes for this (grid + attribute wrangle + attribute wrangle + null)?

No, just two wrangles (see attachment).

Ryu Ku
Using what in code you adjust spacing between hexagons?

Multiply the same value on height and width.

Attachments:
hexagons.hipnc (70.9 KB)

www.konstantinmagnus.de
User Avatar
Member
95 posts
Joined: Oct. 2016
Online
@Konstantin Magnus
Couldn't imagine that we don't need grid object for this. Now it's clear. With width and height too. Thanks
User Avatar
Member
70 posts
Joined: Feb. 2017
Offline
so here's my way…it boils down to divide and conquer…or translated to: create a unit of something, clone it, offset it, radial clone it…whatever….it's just cloning…

I'm not a coder so cannot cram things into one wrangle…but for other non-programming ppl out there..you can look at my files here:

https://www.facebook.com/groups/HoudiniArtists/permalink/1467625033353296/ [www.facebook.com]

step-by-step are pretty easy to understand…it's just cloning, offsetting…

(oh yes…mine produces points…so technically not a grid)
Edited by vusta - Nov. 24, 2017 02:37:16
User Avatar
Member
95 posts
Joined: Oct. 2016
Online
@vusta If you're talking about hex grid example, would be nice if you'll upload it here, interested to look in , but I don't have Facebook account
User Avatar
Member
1307 posts
Joined: March 2014
Offline
Cool!
Mestela's approach shows how a bit of node-fu and creativity can quickly take you out of a ditch.
Konstantin's vex method is the preferable one if you want your hexagons to be “perfect”.
Thanks for sharing these guys!
Edited by McNistor - Nov. 24, 2017 04:59:48
https://www.artstation.com/artist/mcnistor [www.artstation.com]
McNistor OS running brain.
User Avatar
Member
70 posts
Joined: Feb. 2017
Offline
Ryu Ku
@vusta If you're talking about hex grid example, would be nice if you'll upload it here, interested to look in , but I don't have Facebook account
Edited by vusta - Nov. 24, 2017 06:03:18

Attachments:
vu_honeycomb_02.hipnc (105.5 KB)

User Avatar
Member
95 posts
Joined: Oct. 2016
Online
@vusta
Very interesting approach to create hexagon, you've reminded me that I need to find out how to work with For-Each Loops still don't know it Changed you packing tube to six Columns, like the effect it gives and like how you've called the file, didn't think about miel before it relatively to hexagons Thanks for the example
Edited by Ryu Ku - Nov. 24, 2017 13:20:51
  • Quick Links