Skip to content

Add Bresenham Line Algorithm to GridMap Drawing - #105292

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
mchlopecki:gridmap-bresenham-line
Nov 13, 2025
Merged

Repiteo merged 1 commit into
godotengine:masterfrom
mchlopecki:gridmap-bresenham-line

Conversation

@mchlopecki

Copy link
Copy Markdown
Contributor

Implements #11995 for painting and erasing in GridMap.

Before:
gridmap-no-line

This PR:
gridmap-bresenham-line

@mchlopecki
mchlopecki requested a review from a team as a code owner April 11, 2025 20:48
@fire

fire commented Apr 12, 2025 •

Copy link
Copy Markdown
Member

Cool. I want to say this is a great enhancement. Will see if I can expedite review somehow.

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fails to compile when rebased on top of master:

Compiling modules/gridmap/editor/grid_map_editor_plugin.cpp ...
Compiling editor/scene/3d/gizmos/.scu/scu_editor_scene_3d_gizmos.gen.cpp ...
modules/gridmap/editor/grid_map_editor_plugin.cpp: In member function 'bool GridMapEditor::do_input_action(Camera3D*, const Point2&, bool)':
modules/gridmap/editor/grid_map_editor_plugin.cpp:442:54: error: 'class LocalVector<GridMapEditor::SetItem>' has no member named 'back'
  442 |                         Vector3i last_si = set_items.back()->get().position;
      |                                                      ^~~~
Generating core/version_hash.gen.cpp ...
scons: *** [bin/obj/modules/gridmap/editor/grid_map_editor_plugin.linuxbsd.editor.x86_64.o] Error 1
scons: building terminated because of errors.

This is due to set_items now being a LocalVector since https://docs.godotengine.org/en/stable/contributing/workflow/pr_workflow.html#the-interactive-rebase was merged. LocalVector does not have a back() method (see #99955), so you need to replace it with something else.

See this page for instructions on rebasing the PR.

@mchlopecki
mchlopecki force-pushed the gridmap-bresenham-line branch 3 times, most recently from 569291f to b261acd Compare July 18, 2025 21:22
@mchlopecki
mchlopecki requested a review from Calinou July 19, 2025 00:25

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on all edit axes, it works as expected. Code looks good to me.

Top is drawn without this PR, bottom is drawn with this PR (at a similar mouse speed for each). The editor is capped at 30 FPS for this demonstration, which will make the issue more noticeable (the lower the FPS, the more likely your cursor will be missing tiles).

image

Note that visible polygon edges will occur at low FPS, given your mouse cursor position is only sampled once per rendered frame. A more extensive solution could disable input accumulation when drawing in the GridMap editor, then using all the input positions recorded in a single frame to draw the tiles at the mouse's real position, which should lead to smoother curves. That said, this is not essential for an initial implementation, as it already helps a lot, especially when drawing straight (or mostly straight) lines.

@mchlopecki
mchlopecki force-pushed the gridmap-bresenham-line branch from b261acd to 42d61ce Compare July 28, 2025 20:14
@mchlopecki

Copy link
Copy Markdown
Contributor Author

I've implemented changes, rebased on master and tested for general functionally one more time. Unless there are any other notes/changes, it should be ready for merging once it passes CI/CD.

@Repiteo

Repiteo commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Could you rebase your PR? See our pull request guidelines for more information

@Chaosus
Chaosus force-pushed the gridmap-bresenham-line branch from 42d61ce to 56af7b6 Compare October 26, 2025 08:34
@Chaosus

Chaosus commented Oct 26, 2025 •

Copy link
Copy Markdown
Member

@Repiteo I've rebased it ^^ seems to work fine

@Chaosus
Chaosus force-pushed the gridmap-bresenham-line branch from 56af7b6 to 3ee7bf4 Compare October 26, 2025 08:40
@Repiteo Repiteo modified the milestones: 4.x, 4.6 Nov 13, 2025
@Repiteo
Repiteo merged commit e75336e into godotengine:master Nov 13, 2025
@Repiteo

Repiteo commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Thanks! Congratulations on your first merged contribution! 🎉

BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
…am-line

Add Bresenham Line Algorithm to GridMap Drawing
wangshucheng pushed a commit to wangshucheng/godot that referenced this pull request Aug 27, 2026
…am-line

Add Bresenham Line Algorithm to GridMap Drawing
Shane-Gadsby pushed a commit to Shane-Gadsby/godotwebgpu that referenced this pull request Sep 21, 2026
…am-line

Add Bresenham Line Algorithm to GridMap Drawing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GridMap Enhancement: Make use of Bresenham's line algorithm for drawing

6 participants