Skip to content

Commit 9004934

Browse files
quaglacopybara-github
authored andcommitted
Fix texture indexing bug in bindings.
Fixes #2341. PiperOrigin-RevId: 713667648 Change-Id: I7fa5da1506306c5374febf762ce54aff9146079b
1 parent 419da17 commit 9004934

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

python/mujoco/bindings_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@
9393
</mujoco>
9494
"""
9595

96+
TEST_XML_TEXTURE = r"""
97+
<mujoco>
98+
<asset>
99+
<texture name="tex" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2"
100+
width="512" height="512" mark="cross" markrgb=".8 .8 .8"/>
101+
<material name="mat" reflectance="0.3" texture="tex" texrepeat="1 1" texuniform="true"/>
102+
</asset>
103+
<worldbody>
104+
<geom type="plane" size="1 1 1" material="mat"/>
105+
</worldbody>
106+
</mujoco>
107+
"""
108+
96109

97110
@contextlib.contextmanager
98111
def temporary_callback(setter, callback):
@@ -1619,6 +1632,10 @@ def test_deepcopy_mjdata_with_plugin(self):
16191632
self.assertIsNot(data1.model, data2.model)
16201633
self.assertNotEqual(data1.model._address, data2.model._address)
16211634

1635+
def test_texture_size(self):
1636+
model = mujoco.MjModel.from_xml_string(TEST_XML_TEXTURE)
1637+
self.assertEqual(model.tex('tex').data.shape, (512, 512, 3))
1638+
16221639
def _assert_attributes_equal(self, actual_obj, expected_obj, attr_to_compare):
16231640
for name in attr_to_compare:
16241641
actual_value = getattr(actual_obj, name)

python/mujoco/indexers.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ py::array_t<T> MakeArray(T* base_ptr, int index, std::vector<int>&& shape,
103103
shape.insert(shape.begin(), m.hfield_nrow[index]);
104104
} else if (MjSize == &raw::MjModel::ntexdata) {
105105
offset = m.tex_adr[index];
106+
shape.insert(shape.begin(), m.tex_nchannel[index]);
106107
shape.insert(shape.begin(), m.tex_width[index]);
107108
shape.insert(shape.begin(), m.tex_height[index]);
108109
} else if (MjSize == &raw::MjModel::nsensordata) {

0 commit comments

Comments
 (0)