Merge pull request #108010 from DexterFstone/add-scene-tile-rotation

Add support for rotating scene tiles in TileMapLayer
This commit is contained in:
Thaddeus Crews 2025-11-14 14:23:13 -06:00
commit d1a90109b4
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
4 changed files with 50 additions and 15 deletions

View file

@ -1638,6 +1638,7 @@ void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) {
Transform2D xform;
xform.set_origin(tile_set->map_to_local(r_cell_data.coords));
scene_as_node2d->set_transform(xform * scene_as_node2d->get_transform());
_set_scene_transformed_alternative(c.alternative_tile, scene_as_node2d);
}
#ifdef TOOLS_ENABLED
RenderingServer *rs = RenderingServer::get_singleton();
@ -1705,6 +1706,49 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto
}
#endif // DEBUG_ENABLED
void TileMapLayer::_set_scene_transformed_alternative(const int p_alternative_id, Node2D *p_scene) {
// Determine the transformations based on the alternative ID.
bool transform_flip_h = p_alternative_id & TileSetAtlasSource::TRANSFORM_FLIP_H;
bool transform_flip_v = p_alternative_id & TileSetAtlasSource::TRANSFORM_FLIP_V;
bool transform_transpose = p_alternative_id & TileSetAtlasSource::TRANSFORM_TRANSPOSE;
double scene_rotation = 0.0;
Vector2 scene_scale = p_scene->get_scale();
// Determine the scene rotation and scale based on the transformation flags.
if (!transform_flip_h && !transform_flip_v && !transform_transpose) {
scene_rotation = 0.0;
scene_scale.x = 1;
} else if (transform_flip_h && !transform_flip_v && transform_transpose) {
scene_rotation = 90.0;
scene_scale.x = 1;
} else if (transform_flip_h && transform_flip_v && !transform_transpose) {
scene_rotation = 180.0;
scene_scale.x = 1;
} else if (!transform_flip_h && transform_flip_v && transform_transpose) {
scene_rotation = 270.0;
scene_scale.x = 1;
} else if (transform_flip_h && !transform_flip_v && !transform_transpose) {
scene_rotation = 0.0;
scene_scale.x = -1;
} else if (transform_flip_h && transform_flip_v && transform_transpose) {
scene_rotation = 90.0;
scene_scale.x = -1;
} else if (!transform_flip_h && transform_flip_v && !transform_transpose) {
scene_rotation = 180.0;
scene_scale.x = -1;
} else if (!transform_flip_h && !transform_flip_v && transform_transpose) {
scene_rotation = 270.0;
scene_scale.x = -1;
}
// Apply the transformations to the scene.
double current_rotation = p_scene->get_rotation_degrees() + scene_rotation;
Vector2 current_scale = p_scene->get_scale() + scene_scale;
p_scene->set_rotation_degrees(current_rotation);
p_scene->set_scale(current_scale);
}
/////////////////////////////////////////////////////////////////////
void TileMapLayer::_build_runtime_update_tile_data(bool p_force_cleanup) {

View file

@ -492,6 +492,7 @@ private:
#ifdef DEBUG_ENABLED
void _scenes_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data);
#endif // DEBUG_ENABLED
void _set_scene_transformed_alternative(const int p_alternative_id, Node2D *p_scene);
// Terrains.
TileSet::TerrainsPattern _get_best_terrain_pattern_for_constraints(int p_terrain_set, const Vector2i &p_position, const RBSet<TerrainConstraint> &p_constraints, TileSet::TerrainsPattern p_current_pattern) const;