Skip to content

Add methods to get chunked tile polygons #12612

Open
godotengine/godot
#107561
@tvenclovas96

Description

@tvenclovas96

Describe the project you are working on

2D top-down RTS-y game with a lot of custom logic, relying less on "canonical" Godot mechanisms.

Describe the problem or limitation you are having in your project

One of the aspects of the engine I appreciate is the level of access the user gets to individual components, and can use them as needed, as opposed to "the standard way". This provides a lot of freedom when authoring content using the editor, and then later using it in code.
An example: the ability to manually interpolate an animation resource to animate them according to a custom mechanism, instead of having them exclusively limited to animation players.

One element I'm using in my game is extracting the collision shape data from tilemaps ( in a somewhat ugly fashion of tile map -> tile set -> tile source -> tile data -> polygon ). This data is used for manual collision checks for certain visual elements, while the physics server is locked and inaccessible, allowing for more interactive visuals while still keeping a background physics step for main gameplay logic.

#12612 Added chunking of tilemap physics shapes, automatically merging the excessive number of small polygons into larger ones, which is a great optimization. Unfortunately, the merged polygons are inaccessible to the user, meaning the generated data is restricted solely for the physics server to use.

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

I would like to be able to set up a tile map layer with collision shapes in the editor, have the engine generate the optimized polygons, and then simply be able to retrieve the newly created polygon data and use as seen fit.

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

A PR is available
TLDR:

for i: int in tile_map_layer.get_physics_quadrant_count():
	var coord := tile_map_layer.get_physics_quadrant_coord(i)
	var pologons := tile_map_layer.get_physics_quadrant_polygons(coord)
	nefarious_polygon_activities(pologons)

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

It can be worked around, although with more than few lines of script:
Chunk the available tiles in the tilemap,
Collect the polygon data for each tile -> tile data,
Use Geometry2D functions to merge and decompose the polygons (although the specific Geometry2D functions used in the chunker implementation are also not exposed, so that also means extra legwork)

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

The data is right there just let me have it
The engine already does the work to chunk the shapes, it feels wasteful to re-implement a feature that already exists.
I also personally feel like "magic" data that the engine creates, shows you that it creates, and doesn't allow you to use except for the canonical use case goes against the engine's philosophy and strengths

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions