Skip to content

Commit 4affbb6

Browse files
yuvaltassacopybara-github
authored andcommitted
Add support for mesh site types with insidesite detector integration, and mj_insideSite API function.
PiperOrigin-RevId: 977453785 Change-Id: I5b6872e6ed0f46a566a1bd75f2fd43ac0ee2a815
1 parent 83b645f commit 4affbb6

37 files changed

Lines changed: 717 additions & 33 deletions

‎doc/APIreference/functions.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,15 @@ found, the function will return ``distmax`` and ``fromto``, if given, will be se
696696
As explained in :ref:`Collision Detection<coDistance>`, distances are inaccurate when using the
697697
:ref:`legacy CCD pipeline<coCCD>`, and its use is discouraged.
698698

699+
.. _mj_insideSite:
700+
701+
`mj_insideSite <#mj_insideSite>`__
702+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
703+
704+
.. mujoco-include:: mj_insideSite
705+
706+
Return 1 if point is inside a site (convex hull for meshes), 0 otherwise.
707+
699708
.. _mj_contactForce:
700709

701710
`mj_contactForce <#mj_contactForce>`__

‎doc/XMLreference.rst‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ XML schema
1414
~~~~~~~~~~
1515

1616
The dropdown below summarizes the XML elements and their attributes in MJCF. All information in MJCF is entered through
17-
elements and attributes. Text content in elements is not used (except for CDATA in :ref:`custom text<custom-text>` elements); if present, the parser ignores it.
17+
elements and attributes. Text content in elements is not used (except for CDATA in :ref:`custom text<custom-text>`
18+
elements); if present, the parser ignores it.
1819

1920
.. only:: html
2021

@@ -3023,7 +3024,7 @@ tendons, constructing slider-crank transmissions for actuators.
30233024

30243025
.. _body-site-type:
30253026

3026-
:at:`type`: :at-val:`[sphere, capsule, ellipsoid, cylinder, box], "sphere"`
3027+
:at:`type`: :at-val:`[sphere, capsule, ellipsoid, cylinder, box, mesh], "sphere"`
30273028
Type of geometric shape. This is used for rendering, and also determines the active sensor zone for :ref:`touch
30283029
sensors <sensor-touch>`.
30293030

@@ -3038,6 +3039,11 @@ tendons, constructing slider-crank transmissions for actuators.
30383039
:at:`material`: :at-val:`string, optional`
30393040
Material used to specify the visual properties of the site.
30403041

3042+
.. _body-site-mesh:
3043+
3044+
:at:`mesh`: :at-val:`string, optional`
3045+
Mesh asset name. This attribute is required if the site type is "mesh".
3046+
30413047
.. _body-site-rgba:
30423048

30433049
:at:`rgba`: :at-val:`real(4), "0.5 0.5 0.5 1"`
@@ -3594,9 +3600,11 @@ This sub-element adjusts the attributes of the sites in the composite object. Ot
35943600

35953601
.. _composite-site-material:
35963602

3603+
.. _composite-site-mesh:
3604+
35973605
.. _composite-site-rgba:
35983606

3599-
:at:`group`, :at:`size`, :at:`material`, :at:`rgba`
3607+
:at:`group`, :at:`size`, :at:`material`, :at:`mesh`, :at:`rgba`
36003608
Same meaning as regular :ref:`site <body-site>` attributes.
36013609

36023610

@@ -10034,6 +10042,8 @@ if omitted.
1003410042

1003510043
.. _default-site-material:
1003610044

10045+
.. _default-site-mesh:
10046+
1003710047
.. _default-site-size:
1003810048

1003910049
.. _default-site-fromto:

‎doc/XMLschema.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,9 @@
10371037
.. grid-item::
10381038
:ref:`material<body-site-material>`
10391039

1040+
.. grid-item::
1041+
:ref:`mesh<body-site-mesh>`
1042+
10401043
.. grid-item::
10411044
:ref:`size<body-site-size>`
10421045

@@ -1406,6 +1409,9 @@
14061409
.. grid-item::
14071410
:ref:`rgba<composite-site-rgba>`
14081411

1412+
.. grid-item::
1413+
:ref:`mesh<composite-site-mesh>`
1414+
14091415

14101416
.. dropdown:: :ref:`plugin<composite-plugin>` |*|
14111417

@@ -5768,6 +5774,9 @@
57685774
.. grid-item::
57695775
:ref:`material<default-site-material>`
57705776

5777+
.. grid-item::
5778+
:ref:`mesh<default-site-mesh>`
5779+
57715780
.. grid-item::
57725781
:ref:`size<default-site-size>`
57735782

‎doc/changelog.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ General
99
^^^^^^^
1010
- The :ref:`.mjz <MJZArchives>` encoder now writes the root file as ``model.xml`` in the archive as this is less
1111
susceptible to breakage due to file renaming.
12+
- Site geometries can now also be associated with meshes (:ref:`type="mesh"<body-site-type>` with
13+
:ref:`mesh="name"<body-site-mesh>`), supporting visualization, the :ref:`insidesite<sensor-insidesite>`
14+
sensor, and the new :ref:`mj_insideSite` function.
1215
- Added support for Python 3.15 (GIL and Free-Threading).
1316

1417
Engine

‎doc/includes/references.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ typedef struct mjModel_ {
835835
// sites
836836
int* site_type; // geom type for rendering (mjtGeom) (nsite x 1)
837837
int* site_bodyid; // id of site's body (nsite x 1)
838+
int* site_dataid; // id of site's mesh; -1: none (nsite x 1)
838839
int* site_matid; // material id for rendering; -1: none (nsite x 1)
839840
int* site_group; // group for visibility (nsite x 1)
840841
mjtByte* site_sameframe; // same frame as body (mjtSameframe) (nsite x 1)
@@ -1978,6 +1979,7 @@ typedef struct mjsSite_ { // site specification
19781979
float rgba[4]; // rgba when material is omitted
19791980

19801981
// other
1982+
mjString* meshname; // mesh attached to site
19811983
mjDoubleVec* userdata; // user data
19821984
mjString* info; // message appended to compiler errors
19831985
} mjsSite;
@@ -3809,6 +3811,7 @@ void mj_objectAcceleration(const mjModel* m, const mjData* d,
38093811
int objtype, int objid, mjtNum res[6], int flg_local);
38103812
mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax,
38113813
mjtNum fromto[6]);
3814+
int mj_insideSite(const mjModel* m, const mjData* d, int siteid, const mjtNum point[3]);
38123815
void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum result[6]);
38133816
void mj_differentiatePos(const mjModel* m, mjtNum* qvel, mjtNum dt,
38143817
const mjtNum* qpos1, const mjtNum* qpos2);

‎include/mujoco/mjmodel.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ typedef struct mjModel_ {
485485
// sites
486486
int* site_type; // geom type for rendering (mjtGeom) (nsite x 1)
487487
int* site_bodyid; // id of site's body (nsite x 1)
488+
int* site_dataid; // id of site's mesh; -1: none (nsite x 1)
488489
int* site_matid; // material id for rendering; -1: none (nsite x 1)
489490
int* site_group; // group for visibility (nsite x 1)
490491
mjtByte* site_sameframe; // same frame as body (mjtSameframe) (nsite x 1)

‎include/mujoco/mjspec.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ typedef struct mjsSite_ { // site specification
402402
float rgba[4]; // rgba when material is omitted
403403

404404
// other
405+
mjString* meshname; // mesh attached to site
405406
mjDoubleVec* userdata; // user data
406407
mjString* info; // message appended to compiler errors
407408
} mjsSite;

‎include/mujoco/mjspecmacro.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
X ( mjString*, material, 1 ) \
214214
X ( int, group, 1 ) \
215215
XVEC( float, rgba, 4 ) \
216+
X ( mjString*, meshname, 1 ) \
216217
X ( mjDoubleVec*, userdata, 1 ) \
217218
X ( mjString*, info, 1 )
218219

‎include/mujoco/mjxmacro.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
#define MJMODEL_POINTERS_SITE \
395395
X ( int, site_type, nsite, 1 ) \
396396
X ( int, site_bodyid, nsite, 1 ) \
397+
X ( int, site_dataid, nsite, 1 ) \
397398
X ( int, site_matid, nsite, 1 ) \
398399
X ( int, site_group, nsite, 1 ) \
399400
X ( mjtByte, site_sameframe, nsite, 1 ) \

‎include/mujoco/mujoco.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ MJAPI void mj_objectAcceleration(const mjModel* m, const mjData* d,
640640
MJAPI mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax,
641641
mjtNum fromto[6]);
642642

643+
// Return 1 if point is inside a site (convex hull for meshes), 0 otherwise.
644+
MJAPI int mj_insideSite(const mjModel* m, const mjData* d, int siteid, const mjtNum point[3]);
645+
643646
// Extract 6D force:torque given contact id, in the contact frame.
644647
MJAPI void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum result[6]);
645648

0 commit comments

Comments
 (0)
⌂ 换网址