| 44 | uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF; |
| 45 | |
| 46 | Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_mesh) { |
| 47 | /* CREATE AABB VOLUME */ |
| 48 | |
| 49 | AABB aabb; |
| 50 | for (int i = 0; i < p_points.size(); i++) { |
| 51 | if (i == 0) { |
| 52 | aabb.position = p_points[i]; |
| 53 | } else { |
| 54 | aabb.expand_to(p_points[i]); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if (aabb.size == Vector3()) { |
| 59 | return ERR_CANT_CREATE; |
| 60 | } |
| 61 | |
| 62 | Vector<bool> valid_points; |
| 63 | valid_points.resize(p_points.size()); |
| 64 | HashSet<Vector3> valid_cache; |
| 65 | |
| 66 | for (int i = 0; i < p_points.size(); i++) { |
| 67 | Vector3 sp = p_points[i].snappedf(0.0001); |
| 68 | if (valid_cache.has(sp)) { |
| 69 | valid_points.write[i] = false; |
| 70 | } else { |
| 71 | valid_points.write[i] = true; |
| 72 | valid_cache.insert(sp); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /* CREATE INITIAL SIMPLEX */ |
| 77 | |
| 78 | int longest_axis = aabb.get_longest_axis_index(); |
| 79 | |
| 80 | //first two vertices are the most distant |
| 81 | int simplex[4] = { 0 }; |
| 82 | |
| 83 | { |
| 84 | real_t max = 0, min = 0; |
| 85 | |
| 86 | for (int i = 0; i < p_points.size(); i++) { |
| 87 | if (!valid_points[i]) { |
| 88 | continue; |
| 89 | } |
| 90 | real_t d = p_points[i][longest_axis]; |
| 91 | if (i == 0 || d < min) { |
| 92 | simplex[0] = i; |
| 93 | min = d; |
| 94 | } |
| 95 | |
| 96 | if (i == 0 || d > max) { |
| 97 | simplex[1] = i; |
| 98 | max = d; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | //third vertex is one most further away from the line |
nothing calls this directly
no test coverage detected