diff --git a/tiled_wall/tiled_wall_2d.cpp b/tiled_wall/tiled_wall_2d.cpp index de010ca..e6a51ba 100644 --- a/tiled_wall/tiled_wall_2d.cpp +++ b/tiled_wall/tiled_wall_2d.cpp @@ -26,6 +26,7 @@ #include "tiled_wall_2d_data.h" #include "../lights/prop_2d_light.h" +#include "core/math/geometry.h" int TiledWall2D::get_width() const { return _width; @@ -99,6 +100,14 @@ PoolVector TiledWall2D::get_faces(uint32_t p_usage_flags) const { } #ifdef TOOLS_ENABLED +bool TiledWall2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + if (_editor_selection_points.size() == 0) { + return false; + } + + return Geometry::is_point_in_polygon(p_point, _editor_selection_points); +} + bool TiledWall2D::_edit_use_rect() const { return true; } @@ -184,8 +193,15 @@ void TiledWall2D::generate_mesh() { l->set_color(Color(1, 0, 0, 1)); l->set_size(100); + //Vector2 x(1, 0); + //x = x.rotated(Math::deg2rad(45.0)); + //_mesh_transform = Transform2D(x.x, x.y, 0, 1, 0, 0); + + //t.rotate(Math::deg2rad(45.0)); + //t.scale_basis(Vector2(1, 0.5)); + _mesher->add_light(l); - _mesher->add_tiled_wall_simple(_width, _height, Transform2D(), _data, _cache); + _mesher->add_tiled_wall_simple(_width, _height, _mesh_transform, _data, _cache); _mesher->bake_colors(); _rect = _mesher->calculate_rect(); @@ -199,6 +215,17 @@ void TiledWall2D::generate_mesh() { PoolVector vertices = _mesh_array[Mesh::ARRAY_VERTEX]; +#ifdef TOOLS_ENABLED + Vector editor_point_vertices; + editor_point_vertices.resize(vertices.size()); + + for (int i = 0; i < vertices.size(); ++i) { + editor_point_vertices.set(i, vertices[i]); + } + + _editor_selection_points = Geometry::convex_hull_2d(editor_point_vertices); +#endif + if (vertices.size() == 0) { update(); return; diff --git a/tiled_wall/tiled_wall_2d.h b/tiled_wall/tiled_wall_2d.h index 6dc158c..cf6f1a3 100644 --- a/tiled_wall/tiled_wall_2d.h +++ b/tiled_wall/tiled_wall_2d.h @@ -55,6 +55,8 @@ public: PoolVector get_faces(uint32_t p_usage_flags) const; #ifdef TOOLS_ENABLED + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + virtual bool _edit_use_rect() const; virtual Rect2 _edit_get_rect() const; #endif @@ -88,6 +90,12 @@ private: Rect2 _rect; Array _mesh_array; + + Transform2D _mesh_transform; + +#ifdef TOOLS_ENABLED + Vector _editor_selection_points; +#endif }; #endif