From 378561af4dcac9d3e0a49fe6f509e6dafaed4e0c Mon Sep 17 00:00:00 2001 From: Ian Su Date: Tue, 9 Dec 2025 10:43:07 -0500 Subject: [PATCH 1/3] fix vertex id assignment --- .../broad_phase/sweep_and_tiniest_queue.cu | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu index 1fad63548..6a1a9ceed 100644 --- a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu +++ b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu @@ -2,6 +2,7 @@ #ifdef IPC_TOOLKIT_WITH_CUDA +#include #include namespace ipc { @@ -78,6 +79,7 @@ void SweepAndTiniestQueue::build( // Convert from ipc::AABB to scalable_ccd::cuda::AABB boxes->vertices.resize(vertex_boxes.size()); + int unused_vert_id = std::numeric_limits::min(); for (int i = 0; i < vertex_boxes.size(); ++i) { boxes->vertices[i].min.x = vertex_boxes[i].min.x(); boxes->vertices[i].min.y = vertex_boxes[i].min.y(); @@ -89,9 +91,27 @@ void SweepAndTiniestQueue::build( boxes->vertices[i].max.z = vertex_boxes[i].max.size() > 2 ? vertex_boxes[i].max.z() : 0; - boxes->vertices[i].min.x = vertex_boxes[i].vertex_ids[0]; - boxes->vertices[i].min.y = vertex_boxes[i].vertex_ids[1]; - boxes->vertices[i].min.z = vertex_boxes[i].vertex_ids[2]; + // If vertex id == -1 it means this slot is not used. + // But Scalable CCD does not have this kind of special value so we map + // it to unique negative id. + if (vertex_boxes[i].vertex_ids[0] == -1) { + boxes->vertices[i].vertex_ids.x = unused_vert_id; + ++unused_vert_id; + } else { + boxes->vertices[i].vertex_ids.x = vertex_boxes[i].vertex_ids[0]; + } + if (vertex_boxes[i].vertex_ids[1] == -1) { + boxes->vertices[i].vertex_ids.y = unused_vert_id; + ++unused_vert_id; + } else { + boxes->vertices[i].vertex_ids.y = vertex_boxes[i].vertex_ids[1]; + } + if (vertex_boxes[i].vertex_ids[2] == -1) { + boxes->vertices[i].vertex_ids.z = unused_vert_id; + ++unused_vert_id; + } else { + boxes->vertices[i].vertex_ids.z = vertex_boxes[i].vertex_ids[2]; + } boxes->vertices[i].element_id = i; } @@ -271,4 +291,4 @@ bool SweepAndTiniestQueue::can_faces_collide(size_t fai, size_t fbi) const } // namespace ipc -#endif \ No newline at end of file +#endif From 3fa63219d49823502de7ec76e3f3a9df3b556ce3 Mon Sep 17 00:00:00 2001 From: Ian Su Date: Tue, 9 Dec 2025 12:29:48 -0500 Subject: [PATCH 2/3] follow scalable ccd convention --- .../broad_phase/sweep_and_tiniest_queue.cu | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu index 6a1a9ceed..044df886a 100644 --- a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu +++ b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu @@ -79,7 +79,6 @@ void SweepAndTiniestQueue::build( // Convert from ipc::AABB to scalable_ccd::cuda::AABB boxes->vertices.resize(vertex_boxes.size()); - int unused_vert_id = std::numeric_limits::min(); for (int i = 0; i < vertex_boxes.size(); ++i) { boxes->vertices[i].min.x = vertex_boxes[i].min.x(); boxes->vertices[i].min.y = vertex_boxes[i].min.y(); @@ -94,24 +93,11 @@ void SweepAndTiniestQueue::build( // If vertex id == -1 it means this slot is not used. // But Scalable CCD does not have this kind of special value so we map // it to unique negative id. - if (vertex_boxes[i].vertex_ids[0] == -1) { - boxes->vertices[i].vertex_ids.x = unused_vert_id; - ++unused_vert_id; - } else { - boxes->vertices[i].vertex_ids.x = vertex_boxes[i].vertex_ids[0]; - } - if (vertex_boxes[i].vertex_ids[1] == -1) { - boxes->vertices[i].vertex_ids.y = unused_vert_id; - ++unused_vert_id; - } else { - boxes->vertices[i].vertex_ids.y = vertex_boxes[i].vertex_ids[1]; - } - if (vertex_boxes[i].vertex_ids[2] == -1) { - boxes->vertices[i].vertex_ids.z = unused_vert_id; - ++unused_vert_id; - } else { - boxes->vertices[i].vertex_ids.z = vertex_boxes[i].vertex_ids[2]; - } + const auto [vi, vj, vk] = vertex_boxes[i].vertex_ids; + assert(vi >= 0); + boxes->vertices[i].vertex_ids.x = vi; + boxes->vertices[i].vertex_ids.y = vj >= 0 ? vj : (-vi - 1); + boxes->vertices[i].vertex_ids.z = vk >= 0 ? vk : (-vi - 1); boxes->vertices[i].element_id = i; } From 87ab7059344b11b3b46cf92ec1d06a015aad9220 Mon Sep 17 00:00:00 2001 From: Ian Su Date: Tue, 9 Dec 2025 12:30:59 -0500 Subject: [PATCH 3/3] remove unused include --- src/ipc/broad_phase/sweep_and_tiniest_queue.cu | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu index 044df886a..a2cf67bfe 100644 --- a/src/ipc/broad_phase/sweep_and_tiniest_queue.cu +++ b/src/ipc/broad_phase/sweep_and_tiniest_queue.cu @@ -2,7 +2,6 @@ #ifdef IPC_TOOLKIT_WITH_CUDA -#include #include namespace ipc {