Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable distance sensing with SDF geoms #2218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/engine/engine_collision_sdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ static int isknown(const mjtNum* points, const mjtNum x[3], int cnt) {
// adds candidate point to result
static int addContact(mjtNum* points, mjContact* con, const mjtNum x[3],
const mjtNum pos2[3], const mjtNum quat2[4], mjtNum dist,
int cnt, const mjModel* m, const mjSDF* s, mjData* d) {
int cnt, const mjModel* m, const mjSDF* s, mjData* d, mjtNum margin) {
// check if there is a collision
if (dist > 0 || isknown(points, x, cnt)) {
if (dist > margin || isknown(points, x, cnt)) {
return cnt;
} else {
mju_copy3(points+3*cnt, x);
Expand Down Expand Up @@ -652,7 +652,7 @@ int mjc_MeshSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g
// add only the first mjMAXCONPAIR pairs
for (int i=0; i < mju_min(ncandidate, mjMAXCONPAIR); i++) {
cnt = addContact(points, con, candidate + 3*index[i], pos2true, sdf_quat,
dist[index[i]], cnt, m, &sdf, (mjData*)d);
dist[index[i]], cnt, m, &sdf, (mjData*)d, margin);
}

return cnt;
Expand Down Expand Up @@ -717,7 +717,7 @@ int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, m
}

// no intersection if max < min
if (aabb[3] < aabb[0] || aabb[4] < aabb[1] || aabb[5] < aabb[2]) {
if (aabb[3] + margin < aabb[0] || aabb[4] + margin < aabb[1] || aabb[5] + margin < aabb[2]) {
return cnt;
}

Expand Down Expand Up @@ -783,7 +783,7 @@ int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, m

// contact point and normal - we use the midsurface where SDF1=SDF2 as zero level set
sdf.type = mjSDFTYPE_MIDSURFACE;
cnt = addContact(contacts, con, x, pos2true, squat2, dist, cnt, m, &sdf, (mjData*)d);
cnt = addContact(contacts, con, x, pos2true, squat2, dist, cnt, m, &sdf, (mjData*)d, margin);

// SHOULD NOT OCCUR
if (cnt > mjMAXCONPAIR) {
Expand Down