Model Generation
This package generates MuJoCo MjSpec models from either triangle dictionaries
or routed shape dictionaries.
Custom Triangle Trusses
Custom trusses are represented with two dictionaries.
node_dict maps node names to 3D positions:
node_dict = {
"node_1": [0.0, 0.0, 0.2],
"node_2": [0.8, 0.0, 0.2],
"node_3": [0.4, 0.7, 0.2],
}
triangle_dict maps triangle names to four node names:
triangle_dict = {
"triangle_1": ["node_1", "node_2", "node_3", "node_1"],
}
The first three names are the triangle vertices. The fourth name is the passive node for that triangle's perimeter constraint and must be one of the first three vertex names.
Build a model from those dictionaries:
from mujoco_truss_gen import get_mujoco_spec
spec = get_mujoco_spec(node_dict, triangle_dict, realistic=False)
model = spec.compile()
Routed Shape Dictionaries
Continuous tube shapes can be represented with a shape dictionary. Each shape defines a routed path:
import numpy as np
node_dict = {
"node_1": [0.0, 0.0, 0.1],
"node_2": [1.0, 0.0, 0.1],
"node_3": [0.5, 0.8660, 0.1],
"node_4": [0.5, np.sqrt(3) / 6, 0.1 + np.sqrt(2 / 3)],
}
shape_dict = {
"path_1": {
"route": ["node_1", "node_2", "node_4", "node_3"],
"active_edges": [
["node_1", "node_2"],
["node_4", "node_3"],
],
},
"path_2": {
"route": ["node_2", "node_3", "node_1", "node_4"],
"active_edges": [
["node_2", "node_3"],
["node_1", "node_4"],
],
},
}
spec = get_mujoco_spec(node_dict, shape_dict, realistic=False)
model = spec.compile()
The route creates one edge tendon for each adjacent node pair in the path.
Every unique route edge receives an actuator. By default a separate,
non-actuated tendon represents the whole route and has a soft equality
constraint on its initial length. Set disable_route_length_constraint=True
on a route to omit that equality, as the STL importer does. The whole-route
tendon is still generated for visualization and metadata.
get_mujoco_spec(), build_triangle(), and build_shapes() treat caller-provided
dictionaries as read-only inputs. Realistic builders clone shared nodes
internally, but they do not mutate the original dictionaries passed by the
caller.
Public Generation Helpers
build_world(terrain=None)creates a basemujoco.MjSpeccontaining a checker-textured ground plane, bright skybox, and key/fill lighting. Passing aTerrainConfigreplaces the plane with a generated checker-textured height field.build_triangle(spec, node_dict, triangle_dict, realistic=False)adds truss bodies, sites, tendons, actuators, and perimeter constraints to an existing spec.build_shapes(spec, node_dict, shape_dict, realistic=False)adds routed continuous-tube shapes with per-edge tendon actuators and a soft equality constraint on each route's initial total length. Setdisable_route_length_constraint=Trueon a shape to opt out. Withrealistic=True, shared routed node occurrences are cloned and connected to connector balls by in-plane bisector rods.get_mujoco_spec("octahedron", realistic=False, scale=1.0, terrain=None)and the other names inPRESETSbuild built-in presets. Increase or decreasescaleto generate the same preset with different structural tendon lengths. For a realistic model, setTrussPhysicalParameters(connector_rod_length=...)to keep the nominal connector rod length fixed independently of preset scale. Passterrain=TerrainConfig(...)to place the generated robot on an explicit flat, slope, stair, wave, or rough height field. Omitting terrain preserves the existing plane exactly; see Height-field terrain.get_mujoco_spec(node_dict, triangle_dict, realistic=False)builds a custom dictionary-defined truss.get_mujoco_spec(node_dict, shape_dict, realistic=False)builds a routed continuous-tube shape model.get_octahedron_definition(scale=1.0)returns fresh node and triangle dictionaries for the built-in preset.get_icosahedron_definition(scale=1.0)returns fresh node and triangle dictionaries for the built-in preset.get_usevitch_graph_definition(graph_label, partition_index=1, scale=1.0)returns one of the non-octahedron triangle-decomposable graph definitions enumerated in Usevitch et al. (2025), Fig. 3. Named presets use the paper's graph labels, for exampleusevitch_1514879orusevitch_60243677150_p3when multiple partitions exist. Triangle partitions are recomputed from the decoded graph with the paper's exhaustive exact-cover criterion: enumerate every graph 3-cycle, then select edge-disjoint triangles that cover every graph edge exactly once. The integer programming formulations described in the paper are not used for these small built-in preset graphs. Node positions are generated with a multidimensional-scaling embedding search based on the paper's graph-derived distance matrices: each trial assigns random distances to connected node pairs, assigns a larger fixed distance to disjoint node pairs, and computes a 3D MDS embedding. The default search uses the paper-style[0, 1)connected range with disjoint-pair distance10; if that search does not find a candidate with worst case rigidity index above1e-4, a fallback search evaluates several connected-distance ranges and disjoint-pair distances. Each MDS candidate is then rescaled so the mean structural edge length is1.0, which keeps model sizes close to the other built-in presets without changing the candidate's shape. The selected embedding is the candidate with the largest worst case rigidity index; when candidates have nearly identical rigidity index values, the tie-breaker is the smaller RMS error from unit structural edge lengths. Generated embeddings are finally transformed into a reproducible frame: a support face throughnode_1lies onz = 0,node_1is at the origin, and the second-highest numbered node on that face lies on the positive x axis.get_henneberg_routed_graph_definition(node_count, tube_count, scale=1.0, preset_index=1)returns a curated routed continuous-tendon graph generated from Henneberg H1 and H2 moves starting atK4. Named presets are indexed ashenneberg_n{nodes}_{tubes}tube_{index}, for examplehenneberg_n6_1tube_2. The unsuffixed names such ashenneberg_n6_1tubeare aliases for variant_1. Available variant counts are:henneberg_n5_1tube_1;henneberg_n6_1tube_1through_2;henneberg_n6_2tube_1;henneberg_n6_3tube_1;henneberg_n7_1tube_1through_10;henneberg_n7_3tube_1through_3;henneberg_n8_1tube_1through_85;henneberg_n8_2tube_1through_190; andhenneberg_n8_3tube_1through_89. Henneberg candidates are filtered to minimally rigid edge counts (3 * nodes - 6), deduplicated with NetworkX graph isomorphism checks, and classified by the minimum number of trails required to cover every edge.2tubeand3tubepresets use equal edge counts per routed tendon. Each candidate embedding starts fromnetworkx.spring_layout(..., dim=3), is refined against unit edge-length and separated non-edge targets, and is accepted only if the selected coordinates pass an infinitesimal-rigidity rank gate using the 3D rigidity matrix. Worst case rigidity index is still used to choose the best embedding candidate, but it is a quality score rather than the hard indexed-preset acceptance criterion. The final coordinates use the same reproduciblenode_1ground-face frame as the Usevitch graph presets.get_perimeter(node_dict, triangle_dict)computes each triangle perimeter from the first three vertices.save_xml(spec, filename)writesspec.to_xml()to disk and returns the resolved path.view(spec)compiles and opens the generated model in MuJoCo's passive viewer.view_node_velocity_terminal(spec, speed=0.01)opens a routed continuous-tube model in MuJoCo's passive viewer and accepts terminal commands that set node-level scalar velocity commands. Those node commands are mapped to routed tendon actuator commands each simulation step.
from mujoco_truss_gen import get_mujoco_spec, view_node_velocity_terminal
spec = get_mujoco_spec("tetrahedron", realistic=False)
view_node_velocity_terminal(spec)
Example terminal commands:
nodes
set node_2 0.01
add node_2 -0.002
show
zero
quit
Input Expectations
- Node names should be unique strings. Names beginning with
node_are required for the built-in metadata and environment helpers. - Node positions must be 3D numeric sequences.
- Triangle entries must contain exactly the three vertex nodes plus one passive node.
- The passive node must appear in that triangle's first three vertices.
- Custom triangle definitions are validated before MuJoCo objects are created, and validation errors name the node, triangle, or shape entry that needs to be fixed.
- Shape entries must contain
routeandactive_edgeskeys.active_edgesis accepted for compatibility, but all adjacent route edges are actuated. - Shape routes must contain at least two node names. Each active edge must be an adjacent pair in the route.
- The builder helpers should be used when environment rigidity and slip helpers are needed, because those helpers infer structure from generated body, site, tendon, and actuator names.
Fixed Physical Parameters
Pass physical_params=TrussPhysicalParameters(...) to get_mujoco_spec()
to set the physical properties when you generate the model. The
physical parameter reference lists the defaults
and which model modes use each field.
Model Modes
realistic=Falsecreates one world-body per node with slide joints onx,y, andz. This is the simpler abstract model and is useful for fast algorithm development.realistic=Truecreates one free triangle body per triangle for triangle dictionaries. For routed shape dictionaries, it creates direct world-level cloned route node bodies rather than a shared plane parent. In both cases, shared logical nodes are connected through connector balls. Connector rods are initialized in the original local route or triangle plane, and the internal bisector controller keeps each rod aligned with the projected angle bisector of the adjacent edges.connector_rod_lengthis an absolute nominal length; for regular triangles it is the length of every rod, while irregular custom triangles use it as the mean rod length so each triangle remains rigid and its tendon geometry is not distorted. The default is absolute and independent of preset scale. Setconnector_rod_length=Noneto use the legacy scale-proportionalrealistic_node_clone_offsetbehavior. In routed shape dictionaries, passive route endpoints are rendered as cylinders with their flat-face normal aligned to the connector rod and radius set by the edge tendon width. The routed-tuberealistic=Truepath is still incomplete and should be treated as a known modeling limitation until the routed connector/body geometry is fixed.
Generated robot geoms collide with the ground but not with one another. This ground-only profile avoids redundant internal contacts and is compatible with MJX's supported collision pairs.
Realistic triangle models include one accelerometer sensor per generated node
site by default. Pass accelerometer_config=AccelerometerConfig(...) to
configure sensor fields such as noise, cutoff, nsample, delay, or
name_prefix. Pass accelerometer_config=None to omit them. See
Read accelerometers for a
working example.
To place the accelerometers on the node housings, pass a mounting pose in
AccelerometerConfig, for example
AccelerometerConfig(pos=(0.01, 0.0, 0.0), quat=(0.70710678, 0.0, 0.0, 0.70710678)).
The same pose is applied to each generated node in its local body frame.
pos is measured in meters from the node center and quat uses MuJoCo's
(w, x, y, z) order. The node body frame can differ from the box geometry's
frame. Omitted position and orientation default to zero offset and identity
rotation. A custom mount uses a dedicated sensor site and leaves the original
node site available for control.
See Sensors for a complete mounting example.
References
- Nathan Usevitch, Isaac Weaver, and James Usevitch. "Triangle-Decomposable Graphs for Isoperimetric Robots." arXiv:2505.01624, 2025. https://arxiv.org/abs/2505.01624