Skip to content

Commit 89253d9

Browse files
powertjcopybara-github
authored andcommitted
Changes to inertia inference from meshes.
PiperOrigin-RevId: 726051033 Change-Id: I6edfc118280d103a2dd9d07f29f0094858769761
1 parent e39a5df commit 89253d9

21 files changed

+426
-287
lines changed

doc/XMLreference.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,18 +1246,21 @@ The full list of processing steps applied by the compiler to each mesh is as fol
12461246

12471247
.. _asset-mesh-inertia:
12481248

1249-
:at:`inertia`: :at-val:`[convex, exact, legacy], "legacy"`
1249+
:at:`inertia`: :at-val:`[convex, exact, legacy, shell], "legacy"`
12501250
This attribute controls how the mesh is used when mass and inertia are
12511251
:ref:`inferred from geometry<compiler-inertiafromgeom>`. The current default value :at-val:`legacy` will be changed
12521252
to :at-val:`convex` in a future release.
12531253

1254-
:at-val:`convex`: Use the mesh's convex hull to compute volume and inertia.
1254+
:at-val:`convex`: Use the mesh's convex hull to compute volume and inertia, assuming uniform density.
12551255

1256-
:at-val:`exact`: Use an exact algorithm to compute volume and inertia. This algorithm requires a well-oriented,
1257-
watertight mesh and will error otherwise.
1256+
:at-val:`exact`: Compute volume and inertia exactly, even for non-convex meshes. This algorithm requires a
1257+
well-oriented, watertight mesh and will error otherwise.
12581258

1259-
:at-val:`legacy`: Use the legacy algorithm, which is similar to :at-val:`convex`, but leads to volume overcounting
1260-
for non-convex meshes.
1259+
:at-val:`legacy`: Use the legacy algorithm, leads to volume overcounting for non-convex meshes. Though currently the
1260+
default to avoid breakages, it is not recommended.
1261+
1262+
:at-val:`shell`: Assume mass is concentrated on the surface of the mesh. Use the mesh's surface to compute
1263+
the inertia, assuming uniform surface density.
12611264

12621265
.. _asset-mesh-smoothnormal:
12631266

@@ -2457,8 +2460,10 @@ helps clarify the role of bodies and geoms in MuJoCo.
24572460
.. _body-geom-shellinertia:
24582461

24592462
:at:`shellinertia` :at-val:`[false, true], "false"`
2460-
If true, the geom's inertia is computed assuming that all the mass is concentrated on the boundary. In this case
2461-
:at:`density` is interpreted as surface density rather than volumetric density.
2463+
If true, the geom's inertia is computed assuming that all the mass is concentrated on the surface. In this case
2464+
:at:`density` is interpreted as surface rather than volumetric density. This attribute only applies to primitive
2465+
geoms and is ignored for meshes. Surface inertia for meshes can be specified by setting the
2466+
:ref:`asset/mesh/inertia<asset-mesh-inertia>` attribute to :at-val:`"shell"`.
24622467

24632468
.. _body-geom-solmix:
24642469

doc/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ General
3434
- Added :ref:`potential<sensor-e_potential>` and :ref:`kinetic<sensor-e_kinetic>` energy sensors.
3535
- Improved shadow rendering in the native renderer.
3636

37+
.. admonition:: Breaking API changes
38+
:class: attention
39+
40+
- Changes to inertia inference from meshes:
41+
42+
Previously, in order to specify that the mass lies on the surface, :ref:`geom/shellinertia<body-geom-shellinertia>`
43+
could be used for any geom type. Now this attribute is ignored if the geom is a mesh; instead, inertia inference
44+
for meshes is specified in the asset, using the :ref:`asset/mesh/inertia<asset-mesh-inertia>` attribute.
45+
46+
Previously, if the volumetric inertia computation failed (for example due to a very flat mesh), the compiler
47+
would silently fall back to surface inertia computation. Now, the compiler will throw an informative error.
48+
3749
MJX
3850
^^^
3951
- Added support for spatial tendons with internal sphere and cylinder wrapping.

doc/includes/references.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,10 +1652,11 @@ typedef enum mjtGeomInertia_ { // type of inertia inference
16521652
mjINERTIA_VOLUME = 0, // mass distributed in the volume
16531653
mjINERTIA_SHELL, // mass distributed on the surface
16541654
} mjtGeomInertia;
1655-
typedef enum mjtMeshInertia_ { // type of mesh inertia
1656-
mjINERTIA_CONVEX = 0, // convex mesh inertia
1657-
mjINERTIA_EXACT, // exact mesh inertia
1658-
mjINERTIA_LEGACY, // legacy mesh inertia
1655+
typedef enum mjtMeshInertia_ { // type of mesh inertia
1656+
mjMESH_INERTIA_CONVEX = 0, // convex mesh inertia
1657+
mjMESH_INERTIA_EXACT, // exact mesh inertia
1658+
mjMESH_INERTIA_LEGACY, // legacy mesh inertia
1659+
mjMESH_INERTIA_SHELL // shell mesh inertia
16591660
} mjtMeshInertia;
16601661
typedef enum mjtBuiltin_ { // type of built-in procedural texture
16611662
mjBUILTIN_NONE = 0, // no built-in texture
@@ -2008,7 +2009,7 @@ typedef struct mjsMesh_ { // mesh specification
20082009
double refpos[3]; // reference position
20092010
double refquat[4]; // reference orientation
20102011
double scale[3]; // rescale mesh
2011-
mjtMeshInertia inertia; // inertia type (convex, legacy, exact)
2012+
mjtMeshInertia inertia; // inertia type (convex, legacy, exact, shell)
20122013
mjtByte smoothnormal; // do not exclude large-angle faces from normals
20132014
int maxhullvert; // maximum vertex count for the convex hull
20142015
mjFloatVec* uservert; // user vertex data

include/mujoco/mjspec.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ typedef enum mjtGeomInertia_ { // type of inertia inference
6262
} mjtGeomInertia;
6363

6464

65-
typedef enum mjtMeshInertia_ { // type of mesh inertia
66-
mjINERTIA_CONVEX = 0, // convex mesh inertia
67-
mjINERTIA_EXACT, // exact mesh inertia
68-
mjINERTIA_LEGACY, // legacy mesh inertia
65+
typedef enum mjtMeshInertia_ { // type of mesh inertia
66+
mjMESH_INERTIA_CONVEX = 0, // convex mesh inertia
67+
mjMESH_INERTIA_EXACT, // exact mesh inertia
68+
mjMESH_INERTIA_LEGACY, // legacy mesh inertia
69+
mjMESH_INERTIA_SHELL // shell mesh inertia
6970
} mjtMeshInertia;
7071

7172

@@ -459,7 +460,7 @@ typedef struct mjsMesh_ { // mesh specification
459460
double refpos[3]; // reference position
460461
double refquat[4]; // reference orientation
461462
double scale[3]; // rescale mesh
462-
mjtMeshInertia inertia; // inertia type (convex, legacy, exact)
463+
mjtMeshInertia inertia; // inertia type (convex, legacy, exact, shell)
463464
mjtByte smoothnormal; // do not exclude large-angle faces from normals
464465
int maxhullvert; // maximum vertex count for the convex hull
465466
mjFloatVec* uservert; // user vertex data

introspect/enums.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,10 @@
734734
name='mjtMeshInertia',
735735
declname='enum mjtMeshInertia_',
736736
values=dict([
737-
('mjINERTIA_CONVEX', 0),
738-
('mjINERTIA_EXACT', 1),
739-
('mjINERTIA_LEGACY', 2),
737+
('mjMESH_INERTIA_CONVEX', 0),
738+
('mjMESH_INERTIA_EXACT', 1),
739+
('mjMESH_INERTIA_LEGACY', 2),
740+
('mjMESH_INERTIA_SHELL', 3),
740741
]),
741742
)),
742743
('mjtBuiltin',

introspect/structs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10415,7 +10415,7 @@
1041510415
StructFieldDecl(
1041610416
name='inertia',
1041710417
type=ValueType(name='mjtMeshInertia'),
10418-
doc='inertia type (convex, legacy, exact)',
10418+
doc='inertia type (convex, legacy, exact, shell)',
1041910419
),
1042010420
StructFieldDecl(
1042110421
name='smoothnormal',

src/user/user_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void mjs_defaultMesh(mjsMesh* mesh) {
245245
mesh->refquat[0] = 1;
246246
mesh->scale[0] = mesh->scale[1] = mesh->scale[2] = 1;
247247
mesh->maxhullvert = -1;
248-
mesh->inertia = mjINERTIA_LEGACY;
248+
mesh->inertia = mjMESH_INERTIA_LEGACY;
249249
}
250250

251251

0 commit comments

Comments
 (0)