Skip to content

Commit

Permalink
Fix texture indexing bug in bindings.
Browse files Browse the repository at this point in the history
Fixes #2341.

PiperOrigin-RevId: 713667648
Change-Id: I7fa5da1506306c5374febf762ce54aff9146079b
  • Loading branch information
quagla authored and copybara-github committed Jan 9, 2025
1 parent 419da17 commit 9004934
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/mujoco/bindings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@
</mujoco>
"""

TEST_XML_TEXTURE = r"""
<mujoco>
<asset>
<texture name="tex" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2"
width="512" height="512" mark="cross" markrgb=".8 .8 .8"/>
<material name="mat" reflectance="0.3" texture="tex" texrepeat="1 1" texuniform="true"/>
</asset>
<worldbody>
<geom type="plane" size="1 1 1" material="mat"/>
</worldbody>
</mujoco>
"""


@contextlib.contextmanager
def temporary_callback(setter, callback):
Expand Down Expand Up @@ -1619,6 +1632,10 @@ def test_deepcopy_mjdata_with_plugin(self):
self.assertIsNot(data1.model, data2.model)
self.assertNotEqual(data1.model._address, data2.model._address)

def test_texture_size(self):
model = mujoco.MjModel.from_xml_string(TEST_XML_TEXTURE)
self.assertEqual(model.tex('tex').data.shape, (512, 512, 3))

def _assert_attributes_equal(self, actual_obj, expected_obj, attr_to_compare):
for name in attr_to_compare:
actual_value = getattr(actual_obj, name)
Expand Down
1 change: 1 addition & 0 deletions python/mujoco/indexers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ py::array_t<T> MakeArray(T* base_ptr, int index, std::vector<int>&& shape,
shape.insert(shape.begin(), m.hfield_nrow[index]);
} else if (MjSize == &raw::MjModel::ntexdata) {
offset = m.tex_adr[index];
shape.insert(shape.begin(), m.tex_nchannel[index]);
shape.insert(shape.begin(), m.tex_width[index]);
shape.insert(shape.begin(), m.tex_height[index]);
} else if (MjSize == &raw::MjModel::nsensordata) {
Expand Down

0 comments on commit 9004934

Please sign in to comment.