Fix texture indexing bug in bindings.

Fixes #2341.

PiperOrigin-RevId: 713667648
Change-Id: I7fa5da1506306c5374febf762ce54aff9146079b
This commit is contained in:
Alessio Quaglino
2025-01-09 07:37:31 -08:00
committed by Copybara-Service
parent 419da17395
commit 90049343b9
2 changed files with 18 additions and 0 deletions
+17
View File
@@ -93,6 +93,19 @@ TEST_XML_PLUGIN = r"""
</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):
@@ -1619,6 +1632,10 @@ Euler integrator, semi-implicit in velocity.
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)
+1
View File
@@ -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) {