how can one produce a hex grid in houdini ?

   26140   20   7
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
1731 posts
Joined: May 2006
Online
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 [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
4189 posts
Joined: June 2012
Offline
haha nice! I think the platonic soccer ball copied your idea
User Avatar
Member
670 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)

https://procegen.konstantinmagnus.de/ [procegen.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
171 posts
Joined: Oct. 2016
Offline
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 RyuKu - Nov. 22, 2017 06:06:35
User Avatar
Member
1731 posts
Joined: May 2006
Online
The 0.6 I just got by eyeballing it.
http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
171 posts
Joined: Oct. 2016
Offline
@mestela Thanks
User Avatar
Member
670 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)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
171 posts
Joined: Oct. 2016
Offline
@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
555 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
171 posts
Joined: Oct. 2016
Offline
@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
1755 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 anon_user_89151269 - Nov. 24, 2017 04:59:48
User Avatar
Member
555 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
171 posts
Joined: Oct. 2016
Offline
@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 RyuKu - Nov. 24, 2017 13:20:51
User Avatar
Member
21 posts
Joined: Aug. 2014
Offline
I tried to replicate the code of Konstantin Magnus and the hex was always squished a bit. What gave me an regular hex was this. Took me some time to figure out because I don´t know my way around math very well. Perhaps it can be of help to someone.


@Konstantin Magnus Thanks for the starting point and the wonderful Red Blob Games [www.redblobgames.com] link

int prim = addprim(0, "poly");
float size = 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 + size * cos(angle_rad), 0, @P.z + size * sin(angle_rad) );
    
    int pt = addpoint(0, pos);
    addvertex(0, prim, pt);
}
User Avatar
Member
2034 posts
Joined: Sept. 2015
Offline
Saw this post a while back and wanted to give it a whirl but didn't have the time…had time today.

I seperated the hexagons into two vex nodes - one for just creating the hexagons points (their hex “corners”).

And the second to make them into polylines or polygons.

The third node is an add node just to quickly create the polygons by attribute ( in this case the hex number ).

Both vex nodes have a folder tab with control paramters.

The first vex node name “Create Hexagon Points” has the following controls:

* Hexagon starting point
* Hexagon Radius
* Number of Hexagons per row
* Number of Rows

The second vex node has the parameter to switch back between polys or polylines.
Edited by BabaJ - May 4, 2018 21:37:47

Attachments:
Hexagons.hiplc (80.1 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
A non-mathematical approach would be
  • a grid with alternating triangles,
  • grouping its crossing points,
  • scaling it by ~1.7 along X,
  • and copying six sided circles on them.
  • A fuse will cover tiny imprecisions.

Attachments:
hex_grid.hipnc (72.3 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
1 posts
Joined: April 2015
Offline
Because there's always room for more methods?

Here's a super simple solution based on a tetrahedral Points From Volume SOP.

There used to be more here, until I realised that I didn't need most of what I'd put down. Delete delete delete…
Edited by Nick Wood - May 23, 2018 11:32:16

Attachments:
hex grid 2.hiplc (209.3 KB)

User Avatar
Member
1 posts
Joined: Sept. 2018
Offline
Thanks to everyone for your methods. I made my own super simple method, that converts the default grid to hexagonal grid using ‘pointsfromvolume’ node with Tetrahedral point configuration.
You can easily control grid size, hexagon size (Point separation in the ‘pointsfromvolume’ and hexagon offset (circle radius).

Attachments:
hex_grid_STEVLTH_edition.hipnc (110.8 KB)

  • Quick Links