godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 92 forks source link

Support hexagon grids with GridMap #4337

Open octetdev2 opened 2 years ago

octetdev2 commented 2 years ago

Describe the project you are working on

Godot engine improvements.

Describe the problem or limitation you are having in your project

There is no built-in support for hexagonal tiling.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Support hexagon grids for the GridMap node.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

We'll add cell shape, layout and and offset enums to support non square grids the same way TileMap does.

Changes to GridMap

Add a cell shape enum:

enum CellShape {
  CELL_SHAPE_SQUARE,
  CELL_SHAPE_HEXAGON,
};

void set_cell_shape(CellShape p_shape);
CellShape get_cell_shape() const;

Add a cell layout enum:

enum CellLayout {
  CELL_LAYOUT_STACKED,
  CELL_LAYOUT_STACKED_OFFSET,
  CELL_LAYOUT_STAIRS_RIGHT,
  CELL_LAYOUT_STAIRS_DOWN,
  CELL_LAYOUT_DIAMOND_RIGHT,
  CELL_LAYOUT_DIAMOND_DOWN,
};

void set_cell_layout(CellLayout p_layout);
CellLayout get_cell_layout() const;

Add an offset axis enum:

enum CellOffsetAxis {
  CELL_SHAPE_SQUARE,
  CELL_SHAPE_HEXAGON,
};

void set_cell_offset_axis(CellOffsetAxis p_offset_axis);
CellOffsetAxis get_cell_offset_axis() const;

Semantics will pretty much be the same as TileMap except that we do it in the xz plane. There is a bit of duplication here, that is intentional. My intent is to reuse code where applicable when GridMap becomes TileMap3D.

Proof of Concept

I've already implemented this, the editor code needs some work. For example I am not drawing the floor plane with the correct shape. Wanted to raise this here before spending a bunch of time dotting the I's.

https://user-images.githubusercontent.com/102470155/161424657-47ec247d-1b84-40db-93c1-f59a8bef7094.mov

If this enhancement will not be used often, can it be worked around with a few lines of script?

This is a design limitation within the GridMap node.

Is there a reason why this should be core and not an add-on in the asset library?

This is about improving GridMap functionality out of the box.

Wasabi-Cheetah commented 2 years ago

I was about to request this as well, this would come in VERY handy. If it is possible, it would be a really awesome thing if it could wrap around spheres to make tileable planets.

Calinou commented 2 years ago

If it is possible, it would be a really awesome thing if it could wrap around spheres to make tileable planets.

This is generally best accomplished with a "world curvature" shader. This way, your game logic doesn't have to change to support this use case (and neither does the engine).

See the various Minecraft world curvature shaders out there for an example of this in practice.

Wasabi-Cheetah commented 2 years ago

Oh, thank you!

octetdev2 commented 2 years ago

Shaders only get you so far tho.

I'd be for having a projection option for determining what is the tiling plane. It is potentially quite complicated to do cleanly tho so not planning to do anything about it in the near immediate future.

Wasabi-Cheetah commented 2 years ago

yeah, I've learned a bit of what I was going for and as per my research into this, a curvature shader won't cut it, since I need to tile the mesh, fortunately I found this Stack Exchange post. https://stackoverflow.com/questions/46777626/mathematically-producing-sphere-shaped-hexagonal-grid Hope it helps others as well.

clayjohn commented 2 years ago

We discussed today in the proposals review meeting. In general we are supportive of adding a hexagon mode, but we need more information about the use-case for the alternative cell layouts and offset axis. Right now it is unclear whether all these options are useful for users or are even needed. Our primary concern is that they add significant complexity to the implementation, but may not be used by many users.

So, to move forward could someone clearly lay out the uses for the additional cell layouts and offset axis? The benefit of hexagon mode is much more obvious by contrast.

goosewoman commented 2 years ago

The 2D Tilemap implementation offers a half-offset option. Which I believe is meant to be used for hexagonal tilemaps. I'm not sure what other use-case it has.

Maybe both 2D and 3D tilemaps should have square, triangle and hexagon modes by default. (and add an isometric option under each in 2D?) Then a "custom" mode can have all the complex settings for the advanced user. Where instead of half-offset it just has a normal offset slider (for each axis)

That seems like the more user-friendly option without sacrificing functionality for the advanced users.

alazifk commented 2 years ago

Please consider combining hexagon and triangle and square and triangle modes.

Untitled

goosewoman commented 1 year ago

Has there been any word on any progress on this front?

AThousandShips commented 1 year ago

@goosewoman see https://github.com/godotengine/godot-proposals/issues/4337#issuecomment-1151334941

No one has really articulated any use cases clearly, so unless someone does this is unlikely to get core support

goosewoman commented 1 year ago

I'm a little confused about why it's not very obvious what the use-case for hexagonal gridmaps are. It's the same use case as hexagons in tilemaps. And those exist just fine.

Regardless, my own use-case is:

I want to build preset levels using hexagonal tiles for a tactical rpg in a 3d space.

Currently I can only use square tiles because hexagons do not work in gridmaps. Tilemaps have an offset feature, allowing me to make a hexagonal tile-based game in 2d. But gridmaps do not have this feature. Preventing me from using it for hexagonal grids in 3d.

I should mention I don't particularly know about use-cases beyond hexagons or half-offset squares (which are just the same layout as hexagon). But I think feature parity between tilemaps and gridmaps should be obvious.

AThousandShips commented 1 year ago

But I think feature parity between tilemaps and gridmaps should be obvious.

Only if it's useful, if people actually need it, there's a signficant difference between those two types, they are not the same and their uses are not the same

BSChad commented 10 months ago

Since octetdev seems inactive, I revived (rebased and cleaned up) https://github.com/godotengine/godot/pull/59842 because I am about to make a game that uses hex grids, and I'd love to be able to use the GridMap for this.

Behold, a GridMap based hex grid regenerating from the MeshLibrary on key press.

https://github.com/godotengine/godot-proposals/assets/167169/271f53a3-22ec-46f2-b3d3-ef771d030f1c

arjhun commented 10 months ago

wow @BSChad I was waiting for a long time on this one!! Build myself a little game without grid map (all in code) But this will be a live saver, also for people wanting to build boardgame style 3d games etc.

Malkverbena commented 5 months ago

Any update about this feature?

m21-cerutti commented 4 months ago

@Malkverbena The PR for that, https://github.com/godotengine/godot/pull/85890, you will have more updates about it there.