Skip to content

Commit 7fddeea

Browse files
yuvaltassacopybara-github
authored andcommitted
Minor fixes to mj_multiRay
PiperOrigin-RevId: 847780959 Change-Id: I3588415f215bd5f1592bec6678a5bae45d5f0980
1 parent a3e66cd commit 7fddeea

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

doc/includes/references.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,7 @@ void mj_loadPluginLibrary(const char* path);
32363236
void mj_loadAllPluginLibraries(const char* directory, mjfPluginLibraryLoadCallback callback);
32373237
int mj_version(void);
32383238
const char* mj_versionString(void);
3239-
void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum vec[3],
3239+
void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum* vec,
32403240
const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude,
32413241
int* geomid, mjtNum* dist, int nray, mjtNum cutoff);
32423242
mjtNum mj_ray(const mjModel* m, const mjData* d, const mjtNum pnt[3], const mjtNum vec[3],

include/mujoco/mujoco.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ MJAPI const char* mj_versionString(void);
629629
// Intersect multiple rays emanating from a single point.
630630
// Similar semantics to mj_ray, but vec is an array of (nray x 3) directions.
631631
// Nullable: geomgroup
632-
MJAPI void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum vec[3],
632+
MJAPI void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum* vec,
633633
const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude,
634634
int* geomid, mjtNum* dist, int nray, mjtNum cutoff);
635635

python/mujoco/introspect/functions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,9 +3755,8 @@
37553755
),
37563756
FunctionParameterDecl(
37573757
name='vec',
3758-
type=ArrayType(
3758+
type=PointerType(
37593759
inner_type=ValueType(name='mjtNum', is_const=True),
3760-
extents=(3,),
37613760
),
37623761
),
37633762
FunctionParameterDecl(

src/engine/engine_ray.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,15 +1466,20 @@ void mju_multiRayPrepare(const mjModel* m, const mjData* d, const mjtNum pnt[3],
14661466
AABB[3] = mju_max(AABB[3], elevation);
14671467
}
14681468

1469+
// azimuth crosses discontinuity, fall back to no angular culling
14691470
if (AABB[2]-AABB[0] > mjPI) {
14701471
AABB[0] = -mjPI;
14711472
AABB[1] = 0;
14721473
AABB[2] = mjPI;
14731474
AABB[3] = mjPI;
14741475
}
14751476

1476-
if (AABB[3]-AABB[1] > mjPI) { // SHOULD NOT OCCUR
1477-
mjERROR("discontinuity in azimuth angle");
1477+
// elevation overflow, fall back to no angular culling
1478+
if (AABB[3]-AABB[1] > mjPI) {
1479+
AABB[0] = -mjPI;
1480+
AABB[1] = 0;
1481+
AABB[2] = mjPI;
1482+
AABB[3] = mjPI;
14781483
}
14791484

14801485
mju_copy(geom_ba+4*g, AABB, 4);
@@ -1488,11 +1493,6 @@ static mjtNum mju_singleRay(const mjModel* m, mjData* d, const mjtNum pnt[3], co
14881493
int* ray_eliminate, mjtNum* geom_ba, int geomid[1]) {
14891494
mjtNum dist, newdist;
14901495

1491-
// check vector length
1492-
if (mju_norm3(vec) < mjMINVAL) {
1493-
mjERROR("vector length is too small");
1494-
}
1495-
14961496
// clear result
14971497
dist = -1;
14981498
*geomid = -1;
@@ -1558,7 +1558,7 @@ static mjtNum mju_singleRay(const mjModel* m, mjData* d, const mjtNum pnt[3], co
15581558

15591559

15601560
// performs multiple ray intersections with the precomputed bv and flags
1561-
void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum vec[3],
1561+
void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum* vec,
15621562
const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude,
15631563
int* geomid, mjtNum* dist, int nray, mjtNum cutoff) {
15641564
mj_markStack(d);
@@ -1573,7 +1573,11 @@ void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum
15731573

15741574
// loop over rays
15751575
for (int i=0; i < nray; i++) {
1576-
dist[i] = mju_singleRay(m, d, pnt, vec+3*i, geom_eliminate, geom_ba, geomid+i);
1576+
if (mju_dot3(vec+3*i, vec+3*i) < mjMINVAL) {
1577+
dist[i] = -1;
1578+
} else {
1579+
dist[i] = mju_singleRay(m, d, pnt, vec+3*i, geom_eliminate, geom_ba, geomid+i);
1580+
}
15771581
}
15781582

15791583
mj_freeStack(d);

src/engine/engine_ray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ MJAPI void mju_multiRayPrepare(const mjModel* m, const mjData* d,
3131

3232
// intersect multiple rays emanating from a single source
3333
// similar semantics to mj_ray, but vec is an array of (nray x 3) directions.
34-
MJAPI void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum vec[3],
34+
MJAPI void mj_multiRay(const mjModel* m, mjData* d, const mjtNum pnt[3], const mjtNum* vec,
3535
const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude,
3636
int* geomid, mjtNum* dist, int nray, mjtNum cutoff);
3737

src/user/user_model.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,7 +4412,9 @@ mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m) {
44124412
} catch (mjCError err) {
44134413
// deallocate everything allocated in Compile
44144414
mj_deleteModel(model);
4415+
model = nullptr;
44154416
mj_deleteData(data);
4417+
data = nullptr;
44164418
Clear();
44174419

44184420
// save error info

0 commit comments

Comments
 (0)