Skip to content

Commit

Permalink
Update V-HACD library to version 4.1 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaOrtner authored Nov 27, 2023
2 parents 751d316 + 81d26f3 commit 5fd5a51
Show file tree
Hide file tree
Showing 43 changed files with 8,429 additions and 18,525 deletions.
22 changes: 1 addition & 21 deletions modules/vhacd/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,7 @@ thirdparty_obj = []

thirdparty_dir = "#thirdparty/vhacd/"

thirdparty_sources = [
"src/vhacdManifoldMesh.cpp",
"src/FloatMath.cpp",
"src/vhacdMesh.cpp",
"src/vhacdICHull.cpp",
"src/vhacdVolume.cpp",
"src/VHACD-ASYNC.cpp",
"src/btAlignedAllocator.cpp",
"src/vhacdRaycastMesh.cpp",
"src/VHACD.cpp",
"src/btConvexHullComputer.cpp",
]

thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

env_vhacd.Prepend(CPPPATH=[thirdparty_dir + "inc"])

env_thirdparty = env_vhacd.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env.modules_sources += thirdparty_obj
env_vhacd.Prepend(CPPPATH=[thirdparty_dir + "include"])

# Godot source files

Expand Down
24 changes: 14 additions & 10 deletions modules/vhacd/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#define ENABLE_VHACD_IMPLEMENTATION 1

#include "register_types.h"
#include "scene/resources/mesh.h"
#include "thirdparty/vhacd/public/VHACD.h"
#include "thirdparty/vhacd/include/VHACD.h"

static Vector<PoolVector<Vector3>> convex_decompose(const real_t *p_vertices, int p_vertex_count, const uint32_t *p_triangles, int p_triangle_count, int p_max_convex_hulls = -1, Vector<PoolVector<uint32_t>> *r_convex_indices = nullptr) {
VHACD::IVHACD::Parameters params;
Expand All @@ -55,20 +57,22 @@ static Vector<PoolVector<Vector3>> convex_decompose(const real_t *p_vertices, in
decomposer->GetConvexHull(i, hull);

PoolVector<Vector3> &points = ret.write[i];
points.resize(hull.m_nPoints);
points.resize(hull.m_points.size());

PoolVector<Vector3>::Write w = points.write();
for (uint32_t j = 0; j < hull.m_nPoints; ++j) {
for (int k = 0; k < 3; k++) {
w[j][k] = hull.m_points[j * 3 + k];
}
PoolVector<Vector3>::Write write_points = points.write();
for (uint32_t j = 0; j < hull.m_points.size(); ++j) {
write_points[j] = Vector3(hull.m_points[j].mX, hull.m_points[j].mY, hull.m_points[j].mZ);
}

if (r_convex_indices) {
PoolVector<uint32_t> &indices = r_convex_indices->write[i];
indices.resize(hull.m_nTriangles * 3);

memcpy(indices.write().ptr(), hull.m_triangles, hull.m_nTriangles * 3 * sizeof(uint32_t));
PoolVector<uint32_t>::Write write_indices = indices.write();
indices.resize(hull.m_triangles.size() * 3);
for (uint32_t j = 0; j < hull.m_triangles.size(); ++j) {
write_indices[j * 3 + 0] = hull.m_triangles[j].mI0;
write_indices[j * 3 + 1] = hull.m_triangles[j].mI1;
write_indices[j * 3 + 2] = hull.m_triangles[j].mI2;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,12 @@ Files extracted from upstream source:
## vhacd

- Upstream: https://github.com/kmammou/v-hacd
- Version: git (b07958e18e01d504e3af80eeaeb9f033226533d7, 2019)
- Version: 4.1
- License: BSD-3-Clause

Files extracted from upstream source:

- From `src/VHACD_Lib/`: `inc`, `public` and `src`
- `include`
- `LICENSE`

Some downstream changes have been made and are identified by
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/thirdparty/vhacd/include/VHACD.h b/thirdparty/vhacd/include/VHACD.h
index 6c8b8691..1c387d93 100644
--- a/thirdparty/vhacd/include/VHACD.h
+++ b/thirdparty/vhacd/include/VHACD.h
@@ -5695,7 +5695,6 @@ class ThreadPool {
std::mutex task_mutex;
std::condition_variable cv;
bool closed;
- int count;
};

ThreadPool::ThreadPool()
@@ -5705,7 +5704,6 @@ ThreadPool::ThreadPool()

ThreadPool::ThreadPool(int worker)
: closed(false)
- , count(0)
{
workers.reserve(worker);
for(int i=0; i<worker; i++)
213 changes: 0 additions & 213 deletions thirdparty/vhacd/0001-bullet-namespace.patch

This file was deleted.

27 changes: 27 additions & 0 deletions thirdparty/vhacd/0002-Fix-CostTask-t-shadowing-Timer-t.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/thirdparty/vhacd/include/VHACD.h b/thirdparty/vhacd/include/VHACD.h
index 6c8b8691..6db229e4 100644
--- a/thirdparty/vhacd/include/VHACD.h
+++ b/thirdparty/vhacd/include/VHACD.h
@@ -7609,16 +7609,16 @@ void VHACDImpl::PerformConvexDecomposition()
break;
}
ConvexHull* secondHull = i.second;
- CostTask t;
- t.m_hullA = combinedHull;
- t.m_hullB = secondHull;
- t.m_this = this;
- if ( DoFastCost(t) )
+ CostTask ct;
+ ct.m_hullA = combinedHull;
+ ct.m_hullB = secondHull;
+ ct.m_this = this;
+ if ( DoFastCost(ct) )
{
}
else
{
- tasks.push_back(std::move(t));
+ tasks.push_back(std::move(ct));
}
}
m_hulls[combinedHull->m_meshId] = combinedHull;
Loading

0 comments on commit 5fd5a51

Please sign in to comment.