diff options
author | kobewi <kobewi4e@gmail.com> | 2022-11-05 17:09:16 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2023-01-19 13:02:18 +0100 |
commit | c0083e431bb7bf66987f396cf9a62fa372d92fe9 (patch) | |
tree | 5fec252ab1c4b5f0f400ab78cd758ebe88213ebf /core/math | |
parent | cd0a9ccdfde05963d1b544b773662149f585da0d (diff) |
Cleanup unused engine code v2
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/basis.cpp | 25 | ||||
-rw-r--r-- | core/math/basis.h | 4 | ||||
-rw-r--r-- | core/math/face3.cpp | 40 | ||||
-rw-r--r-- | core/math/face3.h | 5 | ||||
-rw-r--r-- | core/math/geometry_2d.cpp | 35 | ||||
-rw-r--r-- | core/math/geometry_2d.h | 1 | ||||
-rw-r--r-- | core/math/geometry_3d.cpp | 143 | ||||
-rw-r--r-- | core/math/geometry_3d.h | 2 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 6 | ||||
-rw-r--r-- | core/math/transform_2d.h | 1 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 196 | ||||
-rw-r--r-- | core/math/triangle_mesh.h | 2 |
12 files changed, 0 insertions, 460 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 39e383fb49..234a4ddb79 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -36,23 +36,6 @@ #define cofac(row1, col1, row2, col2) \ (rows[row1][col1] * rows[row2][col2] - rows[row1][col2] * rows[row2][col1]) -void Basis::from_z(const Vector3 &p_z) { - if (Math::abs(p_z.z) > (real_t)Math_SQRT12) { - // choose p in y-z plane - real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; - real_t k = 1.0f / Math::sqrt(a); - rows[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); - rows[1] = Vector3(a * k, -p_z[0] * rows[0][2], p_z[0] * rows[0][1]); - } else { - // choose p in x-y plane - real_t a = p_z.x * p_z.x + p_z.y * p_z.y; - real_t k = 1.0f / Math::sqrt(a); - rows[0] = Vector3(-p_z.y * k, p_z.x * k, 0); - rows[1] = Vector3(-p_z.z * rows[0].y, p_z.z * rows[0].x, a * k); - } - rows[2] = p_z; -} - void Basis::invert() { real_t co[3] = { cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) @@ -271,14 +254,6 @@ float Basis::get_uniform_scale() const { return (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f; } -void Basis::make_scale_uniform() { - float l = (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f; - for (int i = 0; i < 3; i++) { - rows[i].normalize(); - rows[i] *= l; - } -} - Basis Basis::scaled_local(const Vector3 &p_scale) const { return (*this) * Basis::from_scale(p_scale); } diff --git a/core/math/basis.h b/core/math/basis.h index b3197dbc84..bbc1d40469 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -56,8 +56,6 @@ struct _NO_DISCARD_ Basis { _FORCE_INLINE_ real_t determinant() const; - void from_z(const Vector3 &p_z); - void rotate(const Vector3 &p_axis, real_t p_angle); Basis rotated(const Vector3 &p_axis, real_t p_angle) const; @@ -101,8 +99,6 @@ struct _NO_DISCARD_ Basis { void scale_orthogonal(const Vector3 &p_scale); Basis scaled_orthogonal(const Vector3 &p_scale) const; - - void make_scale_uniform(); float get_uniform_scale() const; Vector3 get_scale() const; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index e53bbf872b..1dff0ee4a6 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -120,36 +120,6 @@ bool Face3::is_degenerate() const { return (normal.length_squared() < (real_t)CMP_EPSILON2); } -Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const { - int over = 0, under = 0; - - Plane plane = get_plane(p_clock_dir); - - for (int i = 0; i < 3; i++) { - const Vector3 &v = p_face.vertex[i]; - - if (plane.has_point(v)) { //coplanar, don't bother - continue; - } - - if (plane.is_point_over(v)) { - over++; - } else { - under++; - } - } - - if (over > 0 && under == 0) { - return SIDE_OVER; - } else if (under > 0 && over == 0) { - return SIDE_UNDER; - } else if (under == 0 && over == 0) { - return SIDE_COPLANAR; - } else { - return SIDE_SPANNING; - } -} - Vector3 Face3::get_random_point_inside() const { real_t a = Math::random(0.0, 1.0); real_t b = Math::random(0.0, 1.0); @@ -164,20 +134,10 @@ Plane Face3::get_plane(ClockDirection p_dir) const { return Plane(vertex[0], vertex[1], vertex[2], p_dir); } -Vector3 Face3::get_median_point() const { - return (vertex[0] + vertex[1] + vertex[2]) / 3.0f; -} - real_t Face3::get_area() const { return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length() * 0.5f; } -ClockDirection Face3::get_clock_dir() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); - //printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) ); - return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE; -} - bool Face3::intersects_aabb(const AABB &p_aabb) const { /** TEST PLANE **/ if (!p_aabb.intersects_plane(get_plane())) { diff --git a/core/math/face3.h b/core/math/face3.h index 3d87de03dc..3dd47d0226 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -57,19 +57,14 @@ struct _NO_DISCARD_ Face3 { Plane get_plane(ClockDirection p_dir = CLOCKWISE) const; Vector3 get_random_point_inside() const; - Side get_side_of(const Face3 &p_face, ClockDirection p_clock_dir = CLOCKWISE) const; - bool is_degenerate() const; real_t get_area() const; - Vector3 get_median_point() const; Vector3 get_closest_point_to(const Vector3 &p_point) const; bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const; bool intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const; - ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity - void get_support(const Vector3 &p_normal, const Transform3D &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const; void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const; diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index a0b76d31cb..74cb92539a 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -320,41 +320,6 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly return polypaths; } -Vector<Point2i> Geometry2D::pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size) { - Vector<stbrp_node> nodes; - nodes.resize(p_atlas_size.width); - - stbrp_context context; - stbrp_init_target(&context, p_atlas_size.width, p_atlas_size.height, nodes.ptrw(), p_atlas_size.width); - - Vector<stbrp_rect> rects; - rects.resize(p_sizes.size()); - - for (int i = 0; i < p_sizes.size(); i++) { - rects.write[i].id = 0; - rects.write[i].w = p_sizes[i].width; - rects.write[i].h = p_sizes[i].height; - rects.write[i].x = 0; - rects.write[i].y = 0; - rects.write[i].was_packed = 0; - } - - int res = stbrp_pack_rects(&context, rects.ptrw(), rects.size()); - if (res == 0) { //pack failed - return Vector<Point2i>(); - } - - Vector<Point2i> ret; - ret.resize(p_sizes.size()); - - for (int i = 0; i < p_sizes.size(); i++) { - Point2i r(rects[i].x, rects[i].y); - ret.write[i] = r; - } - - return ret; -} - Vector<Vector3i> Geometry2D::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) { Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index b55aecf85e..0e5702e0af 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -464,7 +464,6 @@ public: static Vector<Vector<Vector2>> decompose_polygon_in_convex(Vector<Point2> polygon); static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size); - static Vector<Point2i> pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size); static Vector<Vector3i> partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size); private: diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index c04fe7320d..51523ea296 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -198,149 +198,6 @@ struct _FaceClassify { _FaceClassify() {} }; -static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { - // Connect faces, error will occur if an edge is shared between more than 2 faces. - // Clear connections. - - bool error = false; - - for (int i = 0; i < len; i++) { - for (int j = 0; j < 3; j++) { - p_faces[i].links[j].clear(); - } - } - - for (int i = 0; i < len; i++) { - if (p_faces[i].group != p_group) { - continue; - } - for (int j = i + 1; j < len; j++) { - if (p_faces[j].group != p_group) { - continue; - } - - for (int k = 0; k < 3; k++) { - Vector3 vi1 = p_faces[i].face.vertex[k]; - Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3]; - - for (int l = 0; l < 3; l++) { - Vector3 vj2 = p_faces[j].face.vertex[l]; - Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3]; - - if (vi1.distance_to(vj1) < 0.00001f && - vi2.distance_to(vj2) < 0.00001f) { - if (p_faces[i].links[k].face != -1) { - ERR_PRINT("already linked\n"); - error = true; - break; - } - if (p_faces[j].links[l].face != -1) { - ERR_PRINT("already linked\n"); - error = true; - break; - } - - p_faces[i].links[k].face = j; - p_faces[i].links[k].edge = l; - p_faces[j].links[l].face = i; - p_faces[j].links[l].edge = k; - } - } - if (error) { - break; - } - } - if (error) { - break; - } - } - if (error) { - break; - } - } - - for (int i = 0; i < len; i++) { - p_faces[i].valid = true; - for (int j = 0; j < 3; j++) { - if (p_faces[i].links[j].face == -1) { - p_faces[i].valid = false; - } - } - } - return error; -} - -static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) { - if (p_faces[p_index].group >= 0) { - return false; - } - - p_faces[p_index].group = p_group; - - for (int i = 0; i < 3; i++) { - ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true); - _group_face(p_faces, len, p_faces[p_index].links[i].face, p_group); - } - - return true; -} - -Vector<Vector<Face3>> Geometry3D::separate_objects(Vector<Face3> p_array) { - Vector<Vector<Face3>> objects; - - int len = p_array.size(); - - const Face3 *arrayptr = p_array.ptr(); - - Vector<_FaceClassify> fc; - - fc.resize(len); - - _FaceClassify *_fcptr = fc.ptrw(); - - for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; - } - - bool error = _connect_faces(_fcptr, len, -1); - - ERR_FAIL_COND_V_MSG(error, Vector<Vector<Face3>>(), "Invalid geometry."); - - // Group connected faces in separate objects. - - int group = 0; - for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) { - continue; - } - if (_group_face(_fcptr, len, i, group)) { - group++; - } - } - - // Group connected faces in separate objects. - - for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; - } - - if (group >= 0) { - objects.resize(group); - Vector<Face3> *group_faces = objects.ptrw(); - - for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) { - continue; - } - if (_fcptr[i].group >= 0 && _fcptr[i].group < group) { - group_faces[_fcptr[i].group].push_back(_fcptr[i].face); - } - } - } - - return objects; -} - /*** GEOMETRY WRAPPER ***/ enum _CellFlags { diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index 6759db5766..99c554fe05 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -532,8 +532,6 @@ public: return clipped; } - static Vector<Vector<Face3>> separate_objects(Vector<Face3> p_array); - // Create a "wrap" that encloses the given geometry. static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr); diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 6a7ee32230..910995d717 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -221,12 +221,6 @@ Transform2D Transform2D::operator*(const Transform2D &p_transform) const { return t; } -Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const { - Transform2D copy = *this; - copy.scale_basis(p_scale); - return copy; -} - Transform2D Transform2D::scaled(const Size2 &p_scale) const { // Equivalent to left multiplication Transform2D copy = *this; diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 2a0917c63f..4a17a9db37 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -85,7 +85,6 @@ struct _NO_DISCARD_ Transform2D { _FORCE_INLINE_ const Vector2 &get_origin() const { return columns[2]; } _FORCE_INLINE_ void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; } - Transform2D basis_scaled(const Size2 &p_scale) const; Transform2D scaled(const Size2 &p_scale) const; Transform2D scaled_local(const Size2 &p_scale) const; Transform2D translated(const Vector2 &p_offset) const; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 4b6921d38b..0da1b8c7ad 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -182,90 +182,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces, const Vector<int32_t> valid = true; } -Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); - - enum { - TEST_AABB_BIT = 0, - VISIT_LEFT_BIT = 1, - VISIT_RIGHT_BIT = 2, - VISIT_DONE_BIT = 3, - VISITED_BIT_SHIFT = 29, - NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1, - VISITED_BIT_MASK = ~NODE_IDX_MASK, - - }; - - int n_count = 0; - Vector3 n; - - int level = 0; - - const Triangle *triangleptr = triangles.ptr(); - // const Vector3 *verticesr = vertices.ptr(); - const BVH *bvhptr = bvh.ptr(); - - int pos = bvh.size() - 1; - - stack[0] = pos; - while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; - const BVH &b = bvhptr[node]; - bool done = false; - - switch (stack[level] >> VISITED_BIT_SHIFT) { - case TEST_AABB_BIT: { - if (!b.aabb.intersects(p_aabb)) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; - n += s.normal; - n_count++; - - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - - } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; - } - } - continue; - } - case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.left | TEST_AABB_BIT; - continue; - } - case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.right | TEST_AABB_BIT; - continue; - } - case VISIT_DONE_BIT: { - if (level == 0) { - done = true; - break; - } else { - level--; - } - continue; - } - } - - if (done) { - break; - } - } - - if (n_count > 0) { - n /= n_count; - } - - return n; -} - bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index) const { uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); @@ -468,118 +384,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V return inters; } -bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); - - //p_fully_inside = true; - - enum { - TEST_AABB_BIT = 0, - VISIT_LEFT_BIT = 1, - VISIT_RIGHT_BIT = 2, - VISIT_DONE_BIT = 3, - VISITED_BIT_SHIFT = 29, - NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1, - VISITED_BIT_MASK = ~NODE_IDX_MASK, - - }; - - int level = 0; - - const Triangle *triangleptr = triangles.ptr(); - const Vector3 *vertexptr = vertices.ptr(); - const BVH *bvhptr = bvh.ptr(); - - int pos = bvh.size() - 1; - - stack[0] = pos; - while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; - const BVH &b = bvhptr[node]; - bool done = false; - - switch (stack[level] >> VISITED_BIT_SHIFT) { - case TEST_AABB_BIT: { - if (!b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count)) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; - - for (int j = 0; j < 3; ++j) { - const Vector3 &point = vertexptr[s.indices[j]]; - const Vector3 &next_point = vertexptr[s.indices[(j + 1) % 3]]; - Vector3 res; - bool over = true; - for (int i = 0; i < p_plane_count; i++) { - const Plane &p = p_planes[i]; - - if (p.intersects_segment(point, next_point, &res)) { - bool inisde = true; - for (int k = 0; k < p_plane_count; k++) { - if (k == i) { - continue; - } - const Plane &pp = p_planes[k]; - if (pp.is_point_over(res)) { - inisde = false; - break; - } - } - if (inisde) { - return true; - } - } - - if (p.is_point_over(point)) { - over = false; - break; - } - } - if (over) { - return true; - } - } - - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - - } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; - } - } - continue; - } - case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.left | TEST_AABB_BIT; - continue; - } - case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.right | TEST_AABB_BIT; - continue; - } - case VISIT_DONE_BIT: { - if (level == 0) { - done = true; - break; - } else { - level--; - } - continue; - } - } - - if (done) { - break; - } - } - - return false; -} - bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale) const { uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 728fd600d5..24fc12dda9 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -84,9 +84,7 @@ public: bool is_valid() const; bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const; bool intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const; - bool intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const; bool inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale = Vector3(1, 1, 1)) const; - Vector3 get_area_normal(const AABB &p_aabb) const; Vector<Face3> get_faces() const; const Vector<Triangle> &get_triangles() const { return triangles; } |