Commit Graph

29 Commits

Author SHA1 Message Date
Alessio Quaglino 7a7dc7ccad Add support for loading 1D flex components from OBJ line segments.
The obj_decoder plugin is updated to parse line segments ('l') from OBJ files and represent them as degenerate triangles. The user_flexcomp compiler now supports flex dimensions of 1, using these parsed line segments to define the 1D flex elements. The compile sample's error reporting is also improved.

PiperOrigin-RevId: 928566870
Change-Id: I6920729d1b1d5aeb391401c3245ebb1d4784c190
2026-06-08 08:03:30 -07:00
Yuval Tassa 4548e81e4d Rename efc_diagApprox -> efc_diagA.
The field now stores either an approximate or exact diagonal of the constraint matrix A, so the name is made more general.

PiperOrigin-RevId: 924244954
Change-Id: I62b2f76531fb88b7b3bf96e6769940197596702b
2026-05-31 04:54:11 -07:00
Alessio Quaglino 7d54123303 Make flex vert0 rotation-invariant for interpolated flexes.
The `vert0` array, used for parametric vertex coordinates in flexes, is now computed in the flex's local, unrotated frame when using interpolation. This ensures that the parametric coordinates are independent of the flex's initial orientation. A new test confirms that `flex_vert0` is identical for an unrotated and a rotated flex grid.

PiperOrigin-RevId: 908196464
Change-Id: I47d6bcc2bc5df581479d485480e0e947ec6d3ffd
2026-04-30 08:41:01 -07:00
Alessio Quaglino 188196603d Fix flexcomp empty cell detection that was causing missing cells.
The previous implementation only checked whether grid cells contained mesh vertices to determine occupancy. For coarse meshes with large faces, most cells were incorrectly marked empty and pruned—even cells fully inside the object volume. This change improves the algorithm by:

- Marking cells that overlap with any mesh element's AABB as non-empty.
- For surface meshes, running a flood-fill from the grid boundary through non-overlapping cells to identify truly exterior cells. This preserves empty interior cells, preventing incorrect pruning of the object's core.
- For volumetric meshes, defaulting to element-AABB overlap detection directly.

Limitations for non-watertight meshes: If the mesh contains holes larger than the grid cell size, the flood-fill will leak into the interior. In this case, all non-element cells (including interior ones) will be marked as empty.

PiperOrigin-RevId: 902675331
Change-Id: I5a84303a33d5ca7436213e7ce9aca3806c9f5a0f
2026-04-20 09:27:40 -07:00
Alessio Quaglino 2d12dee025 Add dof="2d" option to flexcomp for in-plane deformations.
PiperOrigin-RevId: 902620719
Change-Id: Ib06d3f7b9439e1d90a8373a4289ade0c327e72e4
2026-04-20 07:14:40 -07:00
Alessio Quaglino 508e581ba9 Optimize flex by pinning nodes in empty cells.
This change introduces an optimization for flexcomp objects defined by a mesh. It identifies grid cells that do not contain any mesh vertices and marks them as empty. Nodes that are exclusively part of empty cells are pinned, preventing them from moving. Stiffness computations are skipped for empty cells, reducing computational cost. The total mass is now distributed only among the non-pinned nodes.

PiperOrigin-RevId: 902565735
Change-Id: Id0a9a685536d5e18a3e42124a25ab08ff3a918f2
2026-04-20 04:41:17 -07:00
Alessio Quaglino b16383dfaf Use banded solver for implicit flex integration.
The flex interpolation stiffness matrix within the implicit/implicitfast solvers is now built and factorized in a banded format instead of a dense one. This involves:
-   Calculating the bandwidth based on the sparsity of the mass/damping matrix and the connectivity within flex cells.
-   Allocating and populating a banded matrix `H`.
-   Using `mju_cholFactorBand` and `mju_cholSolveBand` for factorization and solving.
This change improves performance for flexes with many DOFs but local coupling.

PiperOrigin-RevId: 901297952
Change-Id: I3efe06353d1903ea65ab30dc49685cede228bb68
2026-04-17 08:00:07 -07:00
Alessio Quaglino 5724158593 Refactor flex stiffness storage to support variable sizes.
This change introduces `nflexstiffness` and `flex_stiffnessadr` to allow flex stiffness matrices to have sizes other than the fixed 21 per element. Higher-order flexes can now store larger stiffness matrices based on their number of nodes. The `flex_stiffnessadr` array provides the starting index for each flex's stiffness data within the `flex_stiffness` array.

PiperOrigin-RevId: 899632263
Change-Id: Ie49182c46c3777acf0c6b492345edfcf62fb5e44
2026-04-14 09:39:00 -07:00
Alessio Quaglino c49bc7c7c0 Warn when a non-rigid flex has no constraints or passive forces.
Add a warning in user_model.cc if a flex is not rigid and has no edge equality constraints or passive forces (edge stiffness, edge damping, or vertex damping). Such flexes would not affect the simulation. A test case is added to verify the warning.

PiperOrigin-RevId: 889215981
Change-Id: I481128e1456921b632719547c676d201fdfbe931
2026-03-25 06:50:30 -07:00
Yuval Tassa 9fa3f6f77e Enable float32 testing for most MuJoCo engine and user tests.
PiperOrigin-RevId: 886697701
Change-Id: I4a96fae03ea18494c3fcef8eb17b3b6f0863e9b7
2026-03-20 04:05:06 -07:00
Alessio Quaglino 713b5524bc Introduces a new "strain" equality mode (flex_edgeequality = 3) for flexcomps with trilinear interpolation. This mode enforces constraints on the three invariants of the Green-Lagrange strain tensor at 8 Gauss quadrature points within each flex element, resulting in 24 equality constraints per flexcomp.
Also fixes a bug when attaching a flex with constraints.

PiperOrigin-RevId: 881349765
Change-Id: I8e6df8239488bfdc87d7e5b473568975e38c737e
2026-03-10 04:26:07 -07:00
Mark Yang 95724d1ec2 Fix vfs load for mesh gmeshs type 2026-03-07 21:45:12 -05:00
Alessio Quaglino 09c7633a76 Add caching for flex stiffness computation.
This change introduces methods to cache and load the computed stiffness matrix and nodal masses for flex elements. The cache key is generated based on material properties (Young's modulus, Poisson's ratio), interpolation order, and the bounding box of the flex. This avoids redundant expensive computations when compiling models with identical flex definitions.

PiperOrigin-RevId: 874689771
Change-Id: I6d1e299baf294a984b507e2a2602b2c068610536
2026-02-24 10:45:23 -08:00
Alessio Quaglino 6afd742f43 Fix trilinear flexcomp with unused vertices.
Fix a crash and dimension mismatch issue in user_flexcomp when dealing with interpolated="true" meshes that contain unused vertices. Previously, vertbody would correspond only to used vertices while vert included all vertices, leading to assertions or out-of-bounds access. Also enable node pinning for interpolated meshes.

PiperOrigin-RevId: 865881995
Change-Id: Id150f00f22b5f48896ffbffddf03c57b252de8c0
2026-02-05 04:41:02 -08:00
Alessio Quaglino ad80a4625b Always generate a BVH in flex.
The BVH is used also for computing normalized vertex coordinates in the trilinear interpolation, so we need to compute it also when the flex cannot collide.

PiperOrigin-RevId: 756349244
Change-Id: Ib397c472e31251df5a7ea85850d83a62f3b2c949
2025-05-08 09:46:47 -07:00
Mohammad Hamid 3429a4881a Detect mismatch between maxNodes and Nodes in a gmsh block. Fixes #2342
PiperOrigin-RevId: 745967745
Change-Id: If1b5fcd71079a0e6a6def9b442758678e31a5828
2025-04-10 04:15:21 -07:00
Alessio Quaglino 7651cb1b33 Copy texture coordinates from OBJ into flex. Fixes #2464.
PiperOrigin-RevId: 732109960
Change-Id: I506b3540ab5d489ce8f10d0c473919611ccb654a
2025-02-28 06:04:19 -08:00
Alessio Quaglino 7cdf180641 Introduce trilinear flex parametrization.
These flexes use only 24 DOFs (3 per vertex of the bounding box), while colliding with the full high resolution mesh.

On an 8x8x8 cube, the performance using DOFs at all vertices is

```
 Simulation time      : 18.74 s
 Steps per second     : 533
 Realtime factor      : 0.53 x
 Time per step        : 1874.4 µs

 Contacts per step    : 114.88
 Constraints per step : 3322.51
 Degrees of freedom   : 1536
```

With the new implementation, it is the following:

```
 Simulation time      : 1.82 s
 Steps per second     : 5507
 Realtime factor      : 5.51 x
 Time per step        : 181.6 µs

 Contacts per step    : 38.84
 Constraints per step : 155.36
 Degrees of freedom   : 24
```

PiperOrigin-RevId: 721008829
Change-Id: I833df027527db578d86667cc4b24295bcf6f7d22
2025-01-29 09:38:22 -08:00
Alessio Quaglino 94bbf297fc Replace flex_xvert0 with flex_vert0
`flex_xvert0` stored the Cartesian position of the vertices in `qpos0`. This array was unused, so it is now replaced with `flex_vert0`, which still contains the positions of the vertices, but normalized on the bounding box of the flex so that the coordinates are in `[0,1]^m->flex_dim`. This will be useful in the future for using different interpolation methods for computing flex deformations.

PiperOrigin-RevId: 691779361
Change-Id: I5c4223103cd4558f4e268fe3e8d8177541e4754f
2024-10-31 06:30:36 -07:00
Mohammad Hamid 694bdebc19 Fixed a bug that caused dim to be necessary in flexcomp even when it was inferred from GMSH files.
Fixes #2107.

Co-authored-by: Alessio Quaglino <quaglino@google.com>
PiperOrigin-RevId: 684419740
Change-Id: Ia73e719bd37503563223ed92f4dbe0ae07eef300
2024-10-10 06:20:43 -07:00
Mohammad Hamid d6bc8c7781 BEGIN_PUBLIC
Replaced "shark" test models with lighter models to speed up tests.
END_PUBLIC.

- procedurally generated light cube
- replaced shark GMSH with cube for all tests with extension GMSH
- Reduced size of shark model used for tests with extension Ftetwild

PiperOrigin-RevId: 631776421
Change-Id: I66f6b4058b86338a10d06c39bc93bef1c6fbdab6
2024-05-08 06:15:18 -07:00
Alessio Quaglino 7eb8c4b9f4 Set all flex edges to rigid when the flex is rigid.
PiperOrigin-RevId: 629740153
Change-Id: Ib2fb6f64e3d160268d2521d63830f41e44d03b20
2024-05-01 09:06:01 -07:00
Mohammad Hamid 131b1745db Added support for GMSH22 surface loading
PiperOrigin-RevId: 629734063
Change-Id: I6a250b81de4e7c8f7520795bfe74a81d719dfb50
2024-05-01 08:44:05 -07:00
Nimrod Gileadi b33230210a Disable precise error message check in LoadMSHASCII_22_MissingNumElements_Fail
For some reason, this check fails on Windows on GH Actions.

PiperOrigin-RevId: 625396036
Change-Id: I96bf233dcd61e7a64f817da41e47ea39e0c5c157
2024-04-16 11:22:54 -07:00
Google DeepMind f086dc9b4b Better parsing for GMSH2.2
PiperOrigin-RevId: 625267106
Change-Id: Iecf767c43cee1067fdab3859df28050f8a365e2b
2024-04-16 03:23:52 -07:00
Nimrod Gileadi 7d3b662d5b Check for invalid node tags in gmsh parser.
PiperOrigin-RevId: 621538409
Change-Id: I91ba56b931d815fccd65ae32281bc19ae3a45ee7
2024-04-03 08:56:57 -07:00
Google DeepMind 4f0293c6cb Added support for msh2.2
Now we can load flex with format 2.2 binary and ASCII.
There are two different parsing strategies. One for gmsh app and the other is for ftetwild.

Used the shark model from Scanned Objects by Google Research:
https://app.gazebosim.org/GoogleResearch/fuel/models/Weisshai_Great_White_Shark

PiperOrigin-RevId: 619229499
Change-Id: I6eb876afcbc8a00631914b093c45bde10c0caaf6
2024-03-26 10:12:13 -07:00
Alessio Quaglino 9e1d7d6ab8 Fix typo in flex and composite error message.
PiperOrigin-RevId: 611115238
Change-Id: Iadb9b4b078e60bca15184f3435380eb67b2da8a9
2024-02-28 08:45:11 -08:00
Alessio Quaglino 5a70ad08ab Add Flex component.
PiperOrigin-RevId: 572830650
Change-Id: I6908228087b7b9683be3506c8d9cdc725ed5dcd5
2023-10-12 10:49:35 +01:00