Skip to content

Commit 2444def

Browse files
kbayescopybara-github
authored andcommitted
Support arbitrary large meshes in multiccd by reusing EPA memory.
PiperOrigin-RevId: 947709621 Change-Id: Idc4f168434b9d0a8555c0bed989adb0e99770a78
1 parent 0afafac commit 2444def

18 files changed

Lines changed: 680 additions & 87 deletions

File tree

‎doc/changelog.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ General
2121
so assets contained in it failed to load. Failures in the ``mjz`` decoder now emit a warning with the underlying
2222
error instead of the generic "could not decode content" message.
2323
- Added support for resource writing via :ref:`mju_writeResource` and the ``write`` callback in :ref:`mjpResourceProvider`.
24+
- Added support for :ref:`multiccd <coMultiCCD>` with arbitrarily large meshes.
2425

2526
.. admonition:: Breaking API changes
2627
:class: attention

‎doc/includes/references.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ typedef struct mjModel_ {
643643
mjtSize nemax; // number of potential equality-constraint rows
644644
mjtSize njmax; // number of available rows in constraint Jacobian (legacy)
645645
mjtSize nconmax; // number of potential contacts in contact list (legacy)
646+
mjtSize npolygonmax; // maximum number of vertices in a mesh polygon
647+
mjtSize nmeshdegmax; // maximum number of edges adjacent to a mesh vertex
646648
mjtSize nuserdata; // number of mjtNums reserved for the user
647649
mjtSize nsensordata; // number of mjtNums in sensor data vector
648650
mjtSize npluginstate; // number of mjtNums in plugin state vector

‎include/mujoco/mjmodel.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ typedef struct mjModel_ {
331331
mjtSize nemax; // number of potential equality-constraint rows
332332
mjtSize njmax; // number of available rows in constraint Jacobian (legacy)
333333
mjtSize nconmax; // number of potential contacts in contact list (legacy)
334+
mjtSize npolygonmax; // maximum number of vertices in a mesh polygon
335+
mjtSize nmeshdegmax; // maximum number of edges adjacent to a mesh vertex
334336
mjtSize nuserdata; // number of mjtNums reserved for the user
335337
mjtSize nsensordata; // number of mjtNums in sensor data vector
336338
mjtSize npluginstate; // number of mjtNums in plugin state vector

‎include/mujoco/mjxmacro.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
X( nemax ) \
247247
X( njmax ) \
248248
X( nconmax ) \
249+
X( npolygonmax ) \
250+
X( nmeshdegmax ) \
249251
X( nuserdata ) \
250252
X( nsensordata ) \
251253
X( npluginstate ) \

‎python/mujoco/introspect/structs.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,16 @@
13631363
type=ValueType(name='mjtSize'),
13641364
doc='number of potential contacts in contact list (legacy)',
13651365
),
1366+
StructFieldDecl(
1367+
name='npolygonmax',
1368+
type=ValueType(name='mjtSize'),
1369+
doc='maximum number of vertices in a mesh polygon',
1370+
),
1371+
StructFieldDecl(
1372+
name='nmeshdegmax',
1373+
type=ValueType(name='mjtSize'),
1374+
doc='maximum number of edges adjacent to a mesh vertex',
1375+
),
13661376
StructFieldDecl(
13671377
name='nuserdata',
13681378
type=ValueType(name='mjtSize'),

‎src/engine/engine_collision_convex.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ static int mjc_penetration(const mjModel* m, mjData* d, mjCCDObj* obj1, mjCCDObj
102102
config.tolerance = m->opt.ccd_tolerance;
103103
config.max_contacts = ncon;
104104
config.dist_cutoff = 0; // no geom distances needed
105+
config.npolygonmax = m->npolygonmax;
106+
config.nmeshdegmax = m->nmeshdegmax;
105107
if (buffer) {
106108
config.buffer = buffer;
107109
} else {
108110
mj_markStack(d);
109-
config.buffer = mj_stackAllocByte(d, mjc_ccdSize(config.max_iterations), sizeof(mjtNum));
111+
int npolygonmax = mjDISABLED(mjDSBL_MULTICCD) ? 0 : m->npolygonmax;
112+
int nmeshdegmax = mjDISABLED(mjDSBL_MULTICCD) ? 0 : m->nmeshdegmax;
113+
config.buffer = mj_stackAllocByte(d, mjc_ccdSize(npolygonmax, nmeshdegmax,
114+
config.max_iterations), sizeof(mjtNum));
110115
}
111116

112117
if ((dist = mjc_ccd(&config, &status, obj1, obj2)) < 0) {

‎src/engine/engine_collision_driver.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,9 @@ static void collisionTask(const mjModel* m, mjData* d, void* arg, int thread_id,
18871887
static void mj_narrowphase(const mjModel* m, mjData* d, const mjcPair* buffer, int npair,
18881888
size_t parena) {
18891889
int nthread = mju_numThread(d);
1890-
int ccd_size = mjc_ccdSize(m->opt.ccd_iterations);
1890+
int npolygonmax = mjDISABLED(mjDSBL_MULTICCD) ? 0 : m->npolygonmax;
1891+
int nmeshdegmax = mjDISABLED(mjDSBL_MULTICCD) ? 0 : m->nmeshdegmax;
1892+
int ccd_size = mjc_ccdSize(npolygonmax, nmeshdegmax, m->opt.ccd_iterations);
18911893
mjtNum margin, gap;
18921894

18931895
// try to balance load of 5 chunks per thread (chunksize should be divisible by 16)

0 commit comments

Comments
 (0)
⌂ 换网址