mirror of
https://github.com/Relintai/props_2d.git
synced 2025-02-04 16:15:57 +01:00
Now tiled wall is editable in the editor with the rect selection thing.
This commit is contained in:
parent
11ead96592
commit
06cd0a9a9e
@ -784,6 +784,24 @@ PoolVector<Vector2> Prop2DMesher::build_collider() const {
|
|||||||
return face_points;
|
return face_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect2 Prop2DMesher::calculate_rect() {
|
||||||
|
int size = _vertices.size();
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
return Rect2();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect2 rect;
|
||||||
|
|
||||||
|
rect.position = _vertices[0].vertex;
|
||||||
|
|
||||||
|
for (int i = 1; i < size; ++i) {
|
||||||
|
rect.expand_to(_vertices[i].vertex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
void Prop2DMesher::bake_colors() {
|
void Prop2DMesher::bake_colors() {
|
||||||
if ((get_build_flags() & Prop2DMesher::BUILD_FLAG_USE_LIGHTING) == 0) {
|
if ((get_build_flags() & Prop2DMesher::BUILD_FLAG_USE_LIGHTING) == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -157,6 +157,8 @@ public:
|
|||||||
|
|
||||||
PoolVector<Vector2> build_collider() const;
|
PoolVector<Vector2> build_collider() const;
|
||||||
|
|
||||||
|
Rect2 calculate_rect();
|
||||||
|
|
||||||
void bake_colors();
|
void bake_colors();
|
||||||
void bake_colors_rao();
|
void bake_colors_rao();
|
||||||
void bake_colors_lights_rao();
|
void bake_colors_lights_rao();
|
||||||
|
@ -64,8 +64,8 @@ void TiledWall2D::set_data(const Ref<TiledWall2DData> &data) {
|
|||||||
call_deferred("refresh");
|
call_deferred("refresh");
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB TiledWall2D::get_aabb() const {
|
Rect2 TiledWall2D::get_rect() const {
|
||||||
return AABB();
|
return _rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector<Face3> TiledWall2D::get_faces(uint32_t p_usage_flags) const {
|
PoolVector<Face3> TiledWall2D::get_faces(uint32_t p_usage_flags) const {
|
||||||
@ -98,6 +98,17 @@ PoolVector<Face3> TiledWall2D::get_faces(uint32_t p_usage_flags) const {
|
|||||||
return faces;
|
return faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
bool TiledWall2D::_edit_use_rect() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect2 TiledWall2D::_edit_get_rect() const {
|
||||||
|
return get_rect();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void TiledWall2D::refresh() {
|
void TiledWall2D::refresh() {
|
||||||
if (!is_inside_tree()) {
|
if (!is_inside_tree()) {
|
||||||
return;
|
return;
|
||||||
@ -177,6 +188,8 @@ void TiledWall2D::generate_mesh() {
|
|||||||
_mesher->add_tiled_wall_simple(_width, _height, Transform2D(), _data, _cache);
|
_mesher->add_tiled_wall_simple(_width, _height, Transform2D(), _data, _cache);
|
||||||
_mesher->bake_colors();
|
_mesher->bake_colors();
|
||||||
|
|
||||||
|
_rect = _mesher->calculate_rect();
|
||||||
|
|
||||||
_mesh_array = _mesher->build_mesh();
|
_mesh_array = _mesher->build_mesh();
|
||||||
|
|
||||||
if (_mesh_array.size() != Mesh::ARRAY_MAX) {
|
if (_mesh_array.size() != Mesh::ARRAY_MAX) {
|
||||||
|
@ -51,9 +51,14 @@ public:
|
|||||||
Ref<TiledWall2DData> get_data();
|
Ref<TiledWall2DData> get_data();
|
||||||
void set_data(const Ref<TiledWall2DData> &data);
|
void set_data(const Ref<TiledWall2DData> &data);
|
||||||
|
|
||||||
AABB get_aabb() const;
|
Rect2 get_rect() const;
|
||||||
PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
virtual bool _edit_use_rect() const;
|
||||||
|
virtual Rect2 _edit_get_rect() const;
|
||||||
|
#endif
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
void generate_mesh();
|
void generate_mesh();
|
||||||
void clear_mesh();
|
void clear_mesh();
|
||||||
@ -80,6 +85,8 @@ private:
|
|||||||
RID _mesh_rid;
|
RID _mesh_rid;
|
||||||
RID _texture_rid;
|
RID _texture_rid;
|
||||||
|
|
||||||
|
Rect2 _rect;
|
||||||
|
|
||||||
Array _mesh_array;
|
Array _mesh_array;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user