Add OccluderShapePolygon

Add OccluderShapePolygon, glue to Occluder and gizmos etc.
This commit is contained in:
lawnjelly
2021-08-17 13:40:39 +01:00
parent b5eef640e1
commit 8ea20f5fdd
32 changed files with 2065 additions and 84 deletions

View File

@@ -30,6 +30,7 @@
#include "geometry.h"
#include "core/local_vector.h"
#include "core/print_string.h"
#include "thirdparty/misc/clipper.hpp"
@@ -53,6 +54,17 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2>
}
*/
void Geometry::OccluderMeshData::clear() {
faces.clear();
vertices.clear();
}
void Geometry::MeshData::clear() {
faces.clear();
edges.clear();
vertices.clear();
}
void Geometry::MeshData::optimize_vertices() {
Map<int, int> vtx_remap;
@@ -1363,6 +1375,28 @@ Vector<Geometry::PackRectsResult> Geometry::partial_pack_rects(const Vector<Vect
return ret;
}
// Expects polygon as a triangle fan
real_t Geometry::find_polygon_area(const Vector3 *p_verts, int p_num_verts) {
if (!p_verts || (p_num_verts < 3)) {
return 0.0;
}
Face3 f;
f.vertex[0] = p_verts[0];
f.vertex[1] = p_verts[1];
f.vertex[2] = p_verts[1];
real_t area = 0.0;
for (int n = 2; n < p_num_verts; n++) {
f.vertex[1] = f.vertex[2];
f.vertex[2] = p_verts[n];
area += Math::sqrt(f.get_twice_area_squared());
}
return area * 0.5;
}
// adapted from:
// https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order
void Geometry::sort_polygon_winding(Vector<Vector2> &r_verts, bool p_clockwise) {