how can one produce a hex grid in houdini ?
28541 20 8- pheryel
- Member
- 11 posts
- Joined: Sept. 2016
- Offline
- mestela
- Member
- 1798 posts
- Joined: May 2006
- Offline
- anon_user_37409885
- Member
- 4189 posts
- Joined: June 2012
- Offline
- Konstantin Magnus
- Member
- 682 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.
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]
// 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]
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
- pheryel
- Member
- 11 posts
- Joined: Sept. 2016
- Offline
- RyuKu
- 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
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
- mestela
- Member
- 1798 posts
- Joined: May 2006
- Offline
- RyuKu
- Member
- 171 posts
- Joined: Oct. 2016
- Offline
- Konstantin Magnus
- Member
- 682 posts
- Joined: Sept. 2013
- Offline
Hi Ryu,
No, just two wrangles (see attachment).
Multiply the same value on height and width.
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.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
- RyuKu
- Member
- 171 posts
- Joined: Oct. 2016
- Offline
- vusta
- 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)
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
- RyuKu
- Member
- 171 posts
- Joined: Oct. 2016
- Offline
- anon_user_89151269
- Member
- 1755 posts
- Joined: March 2014
- Offline
- vusta
- Member
- 555 posts
- Joined: Feb. 2017
- Offline
- RyuKu
- 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
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
- Schmauch
- 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
@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); }
- BabaJ
- Member
- 2127 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.
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
- Konstantin Magnus
- Member
- 682 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.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
- Nick Wood
- Member
- 1 posts
- Joined: April 2015
- Offline
- STEVLTH
- 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).
You can easily control grid size, hexagon size (Point separation in the ‘pointsfromvolume’ and hexagon offset (circle radius).
-
- Quick Links