summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/basis.cpp2
-rw-r--r--core/math/convex_hull.cpp17
-rw-r--r--core/math/convex_hull.h2
-rw-r--r--core/math/dynamic_bvh.h2
-rw-r--r--core/math/triangle_mesh.h6
5 files changed, 21 insertions, 8 deletions
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 5c42213e61..eec9caf149 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -775,7 +775,7 @@ Basis::operator String() const {
Quaternion Basis::get_quaternion() const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V_MSG(!is_rotation(), Quaternion(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quaternion() or call orthonormalized() instead.");
+ ERR_FAIL_COND_V_MSG(!is_rotation(), Quaternion(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quaternion() or call orthonormalized() if the Basis contains linearly independent vectors.");
#endif
/* Allow getting a quaternion from an unnormalized transform */
Basis m = *this;
diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp
index 21cb0efe20..f67035c803 100644
--- a/core/math/convex_hull.cpp
+++ b/core/math/convex_hull.cpp
@@ -2260,10 +2260,21 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3
r_mesh.vertices = ch.vertices;
- r_mesh.edges.resize(ch.edges.size());
+ // Copy the edges over. There's two "half-edges" for every edge, so we pick only one of them.
+ r_mesh.edges.resize(ch.edges.size() / 2);
+ uint32_t edges_copied = 0;
for (uint32_t i = 0; i < ch.edges.size(); i++) {
- r_mesh.edges.write[i].a = (&ch.edges[i])->get_source_vertex();
- r_mesh.edges.write[i].b = (&ch.edges[i])->get_target_vertex();
+ uint32_t a = (&ch.edges[i])->get_source_vertex();
+ uint32_t b = (&ch.edges[i])->get_target_vertex();
+ if (a < b) { // Copy only the "canonical" edge. For the reverse edge, this will be false.
+ ERR_BREAK(edges_copied >= (uint32_t)r_mesh.edges.size());
+ r_mesh.edges.write[edges_copied].a = a;
+ r_mesh.edges.write[edges_copied].b = b;
+ edges_copied++;
+ }
+ }
+ if (edges_copied != (uint32_t)r_mesh.edges.size()) {
+ ERR_PRINT("Invalid edge count.");
}
r_mesh.faces.resize(ch.faces.size());
diff --git a/core/math/convex_hull.h b/core/math/convex_hull.h
index a860d60b02..806c6cc3fb 100644
--- a/core/math/convex_hull.h
+++ b/core/math/convex_hull.h
@@ -49,7 +49,7 @@ subject to the following restrictions:
#include "core/templates/vector.h"
/// Convex hull implementation based on Preparata and Hong
-/// See https://code.google.com/p/bullet/issues/detail?id=275
+/// See https://code.google.com/archive/p/bullet/issues/275
/// Ole Kniemeyer, MAXON Computer GmbH
class ConvexHullComputer {
public:
diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h
index d63132b4da..0b6286cd9d 100644
--- a/core/math/dynamic_bvh.h
+++ b/core/math/dynamic_bvh.h
@@ -41,7 +41,7 @@
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2013 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index 463b0dd5c8..2d3b4db4bb 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -37,11 +37,13 @@
class TriangleMesh : public RefCounted {
GDCLASS(TriangleMesh, RefCounted);
+public:
struct Triangle {
Vector3 normal;
int indices[3];
};
+private:
Vector<Triangle> triangles;
Vector<Vector3> vertices;
@@ -86,8 +88,8 @@ public:
Vector3 get_area_normal(const AABB &p_aabb) const;
Vector<Face3> get_faces() const;
- Vector<Triangle> get_triangles() const { return triangles; }
- Vector<Vector3> get_vertices() const { return vertices; }
+ const Vector<Triangle> &get_triangles() const { return triangles; }
+ const Vector<Vector3> &get_vertices() const { return vertices; }
void get_indices(Vector<int> *r_triangles_indices) const;
void create(const Vector<Vector3> &p_faces);