Add mjmodel support for textures with different number of channels.

PiperOrigin-RevId: 653974959
Change-Id: Ia280e0bdb21027646249f104f21bedee792ba7e5
This commit is contained in:
Tom Erez
2024-07-19 05:21:16 -07:00
committed by Copybara-Service
parent 70ac76bb4b
commit e92af73cbf
11 changed files with 43 additions and 24 deletions
+6 -5
View File
@@ -262,11 +262,12 @@
X( float, tendon, _rgba, ntendon, 4 )
#define MJMODEL_TEXTURE \
X( int, tex_, type, ntex, 1 ) \
X( int, tex_, height, ntex, 1 ) \
X( int, tex_, width, ntex, 1 ) \
X( int, tex_, adr, ntex, 1 ) \
X( mjtByte, tex_, rgb, ntexdata, 1 )
X( int, tex_, type, ntex, 1 ) \
X( int, tex_, height, ntex, 1 ) \
X( int, tex_, width, ntex, 1 ) \
X( int, tex_, nchannel, ntex, 1 ) \
X( int, tex_, adr, ntex, 1 ) \
X( mjtByte, tex_, data, ntexdata, 1 )
#define MJMODEL_TUPLE \
X( int, tuple_, adr, ntuple, 1 ) \
+3 -2
View File
@@ -212,9 +212,10 @@ class USDExporter:
for texture_id in tqdm.tqdm(range(self.model.ntex)):
texture_height = self.model.tex_height[texture_id]
texture_width = self.model.tex_width[texture_id]
pixels = 3 * texture_height * texture_width
texture_nchannel = self.model.tex_nchannel[texture_id]
pixels = texture_nchannel * texture_height * texture_width
img = im.fromarray(
self.model.tex_rgb[data_adr : data_adr + pixels].reshape(
self.model.tex_data[data_adr : data_adr + pixels].reshape(
texture_height, texture_width, 3
)
)