Add mjs_makeMesh to create a builtin mesh.

PiperOrigin-RevId: 788538127
Change-Id: I999733399a1a0da07b0f915f34d31364ab8b3b52
This commit is contained in:
Alessio Quaglino
2025-07-29 11:30:19 -07:00
committed by Copybara-Service
parent 46dc67b7eb
commit 89f4789085
23 changed files with 569 additions and 649 deletions
+9
View File
@@ -4074,6 +4074,15 @@ Add texture.
Add material.
.. _mjs_makeMesh:
`mjs_makeMesh <#mjs_makeMesh>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjs_makeMesh
Sets the vertices and normals of a mesh.
.. _FindAndGetUtilities:
Find and get utilities
+54
View File
@@ -1323,6 +1323,60 @@ The full list of processing steps applied by the compiler to each mesh is as fol
Reference orientation relative to which the 3D vertex coordinates and normals are defined. The conjugate of this
quaternion is used to rotate the positions and normals. The model compiler normalizes the quaternion automatically.
.. _asset-mesh-builtin:
:at:`builtin`: :at-val:`string, optional`
The mesh is generated by the compiler from a set of parameters specified in :ref:`params<asset-mesh-params>`.
When saved to XML, meshes produced this way are converted to explicit vertices.
The available built-in types, their parameters and semantics are:
:at-val:`sphere` (subdivision)
Repeated subdivisions :math:`s` of a unit icosahedron. Has :math:`2 + 10 \cdot 4^s` vertices.
**subdivision**: integer in [0-4]: The number of subdivisions to apply to icosahedron faces.
:at-val:`hemisphere` (subdivision)
Repeated subdivisions :math:`s` of a square-based pyramid. Has :math:`1 + 2(s+1)(s+2)` vertices.
**subdivision**: integer in [0-10]: The number of subdivisions to apply to the pyramid.
:at-val:`prism` (nvert)
An extruded regular unit polygon.
**nvert**: integer >= 3: The number vertices in the polygon.
:at-val:`cone` (nvert)
The convex hull of a regular unit polygon and the vertex (0, 0, 1).
**nvert**: integer >= 3: The number vertices in the polygon.
:at-val:`torus` (radius, resolution)
A torus with major radius of 1 and given minor radius.
**radius**: real in (0, 1]: The minor radius of the torus.
|br| **resolution** integer >= 4: The discretization of both major and minor radii.
:at-val:`wedge` (res_phi, res_theta, fov_phi, fov_theta, gamma)
A slice of a unit spherical shell in spherical coordinates.
**res_phi**: integer >= 0: The vertical resolution of the slice.
|br| **res_theta**: integer >= 0: The horizontal resolution of the slice.
|br| **fov_phi**: real in (0, 180]: The horizontal field of view (longitude) in degrees.
|br| **fov_phi**: real in (0, 90): The vertical field of view (latitude) in degrees.
|br| **gamma**: real in [0, 1]: Foveal deformation of the discretization.
:at-val:`plate` (res_x, res_y)
A rectangular plate with resolution in each dimension.
**res_x**: integer > 0: The horizontal resolution of the plate.
|br| **res_y**: integer > 0: The vertical resolution of the plate.
.. _asset-mesh-params:
:at:`params`: :at-val:`real(nparam), optional`
The parameters used to generate a builtin mesh. The number and type of parameters and their semantic depends on the
mesh type. See :ref:`mesh/builtin<asset-mesh-builtin>` for details.
.. _mesh-plugin:
:el-prefix:`mesh/` |-| **plugin** (?)
+1 -1
View File
@@ -103,7 +103,7 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`refpos<asset-mesh-refpos>` | :ref:`refquat<asset-mesh-refquat>` | :ref:`scale<asset-mesh-scale>` | :ref:`smoothnormal<asset-mesh-smoothnormal>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`maxhullvert<asset-mesh-maxhullvert>` | :ref:`inertia<asset-mesh-inertia>` | | | |
| | | | :ref:`maxhullvert<asset-mesh-maxhullvert>` | :ref:`inertia<asset-mesh-inertia>` | :ref:`builtin<asset-mesh-builtin>` | :ref:`params<asset-mesh-params>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |_2| mesh |br| |_2| |L| | | .. table:: |
+1
View File
@@ -15,6 +15,7 @@ General
- Removed the SdfLib plugin and the dependency on `SdfLib <https://github.com/UPC-ViRVIG/SdfLib>`__. SDFs are now
supported natively in mjModel.
- Removed ``oct_depth`` from :ref:`mjvOption` (unused).
- Added the functionality to create a builtin meshes, see :ref:`mesh/builtin<asset-mesh-builtin>`.
- Inertia computation in MuJoCo C is now performed by a new :ref:`pipeline<piStages>` function :ref:`mj_makeM`, which
combines the Composite Rigid Body algorithm in :ref:`mj_crb` and additional terms related to
:ref:`tendon armature<tendon-spatial-armature>`. Code that uses :ref:`mj_crb` to compute the inertia should now use
+11
View File
@@ -1781,6 +1781,16 @@ typedef enum mjtMeshInertia_ { // type of mesh inertia
mjMESH_INERTIA_LEGACY, // legacy mesh inertia
mjMESH_INERTIA_SHELL // shell mesh inertia
} mjtMeshInertia;
typedef enum mjtMeshBuiltin_ { // type of built-in procedural mesh
mjMESH_BUILTIN_NONE = 0, // no built-in mesh
mjMESH_BUILTIN_SPHERE, // sphere
mjMESH_BUILTIN_HEMISPHERE, // hemisphere
mjMESH_BUILTIN_PRISM, // prism
mjMESH_BUILTIN_CONE, // cone
mjMESH_BUILTIN_TORUS, // torus
mjMESH_BUILTIN_WEDGE, // wedge
mjMESH_BUILTIN_PLATE, // plate
} mjtMeshBuiltin;
typedef enum mjtBuiltin_ { // type of built-in procedural texture
mjBUILTIN_NONE = 0, // no built-in texture
mjBUILTIN_GRADIENT, // gradient: rgb1->rgb2
@@ -3457,6 +3467,7 @@ mjsHField* mjs_addHField(mjSpec* s);
mjsSkin* mjs_addSkin(mjSpec* s);
mjsTexture* mjs_addTexture(mjSpec* s);
mjsMaterial* mjs_addMaterial(mjSpec* s, const mjsDefault* def);
int mjs_makeMesh(mjsMesh* mesh, mjtMeshBuiltin builtin, double* params, int nparams);
mjSpec* mjs_getSpec(mjsElement* element);
mjSpec* mjs_findSpec(mjSpec* spec, const char* name);
mjsBody* mjs_findBody(mjSpec* s, const char* name);