Document how to save MjSpec to XML. Fixes #2075
PiperOrigin-RevId: 704712337 Change-Id: I51c1a14c5c48ffc8e37d9e31162a3e70a3b10313
This commit is contained in:
committed by
Copybara-Service
parent
83c0ac148c
commit
a7fed25fdd
+23
-1
@@ -479,6 +479,7 @@ Below is a minimal usage example, more examples can be found in the Model Editin
|
||||
|
||||
import mujoco
|
||||
spec = mujoco.MjSpec()
|
||||
spec.modelname = "my model"
|
||||
body = spec.worldbody.add_body(
|
||||
pos=[1, 2, 3],
|
||||
quat=[0, 1, 0, 0],
|
||||
@@ -503,9 +504,30 @@ The ``MjSpec`` object wraps the :ref:`mjSpec` struct and can be constructed in t
|
||||
|
||||
Note the ``from_string()`` and ``from_file()`` methods can only be called at construction time.
|
||||
|
||||
Attachments
|
||||
Save to XML
|
||||
-----------
|
||||
|
||||
Compiled ``MjSpec`` objects can be saved to XML string with the ``to_xml()`` method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
print(spec.to_xml())
|
||||
|
||||
.. code-block:: XML
|
||||
|
||||
<mujoco model="my model">
|
||||
<compiler angle="radian"/>
|
||||
|
||||
<worldbody>
|
||||
<body pos="1 2 3" quat="0 1 0 0">
|
||||
<geom name="my_geom" size="1" rgba="1 0 0 1"/>
|
||||
</body>
|
||||
</worldbody>
|
||||
</mujoco>
|
||||
|
||||
Attachment
|
||||
----------
|
||||
|
||||
It is possible to combine multiple specs by using attachments. The following options are possible:
|
||||
|
||||
- Attach a body from the child spec to a frame in the parent spec: ``body.attach_body(body, prefix, suffix)``, returns
|
||||
|
||||
Reference in New Issue
Block a user