mirror of
https://github.com/Relintai/props_2d.git
synced 2025-02-10 16:40:11 +01:00
Added a mesh transform property to TiledWall2D. It's not bound yet, as I'm thinking about how to do it. It can be used to create isometric meshes. Also reworked editor click selection, now that the meshes are not just the same size as the rect.
This commit is contained in:
parent
06cd0a9a9e
commit
35c0e33df2
@ -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<Face3> 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<Vector2> vertices = _mesh_array[Mesh::ARRAY_VERTEX];
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Vector<Vector2> 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;
|
||||
|
@ -55,6 +55,8 @@ public:
|
||||
PoolVector<Face3> 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<Point2> _editor_selection_points;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user