Enable reading textures from spec in Python

PiperOrigin-RevId: 842151742
Change-Id: I477d118cc7e2385d29b395b192fa89e9facb9c3e
This commit is contained in:
Matija Kecman
2025-12-09 03:06:42 -08:00
committed by Copybara-Service
parent e1e2248925
commit bf49fe3daa
3 changed files with 71 additions and 0 deletions
+13
View File
@@ -654,6 +654,19 @@ The :ref:`mjsMesh` object includes convenience methods for model creation with n
mesh = spec.add_mesh(name='prism')
mesh.make_cone(nedge=5, radius=1)
Texture editing
^^^^^^^^^^^^^^^
The :ref:`mjsTexture` buffer option stores the texture bytes in the ``data`` attribute. This attribute is stored as
bytes but its elements can be read and modified as ``int``\s via index access and read as Python's built-in ``bytes`` or
``bytearray`` objects. See `specs_test.py
<https://github.com/google-deepmind/mujoco/blob/main/python/mujoco/specs_test.py>`__.
.. code-block:: python
texture = spec.add_texture(name='texture', height=1, width=3, nchannel=3)
texture.data = bytes([255, 0, 0, 0, 255, 0, 0, 0, 255]) # Assign red, green and blue pixels.
texture.data[1] = 255 # Change the first pixel to yellow.
.. _PyMJCF:
Relationship to ``PyMJCF`` and ``bind``