Any use of KTX textures crash mujoco simulate, and the ogl renderer.
Intro
Hi!
I am a software engineer at Boston Dynamics, I support MuJoCo for our robotics simulations.
My setup
I've been experimenting with the filament renderer (we rolled our own backend so it's not exactly the same as the mujoco one) Currently we are using mujoco 3.7 via C and python, on linux and windows.
What's happening? What did you expect?
Attempting to use KTX textures in MuJoCo causes an immediate crash in mjr_uploadTexture with the error: ERROR: Number of channels not supported: 1 Upon inspecting the source code, mjCTexture::LoadKTX does not actually parse the KTX container or decompress the texture. Instead, it treats the entire raw binary file payload as a 1D pixel array of 1 channel, setting the width (w) to the file size in bytes. This blows up downstream code, and is pretty confusing till you realize that the ktx header needs to be parsed out of the bytestream.
I understand that you aren't looking to support advanced rendering in the opengl renderer, but this means that adding any pbr ktx textures to a mjcf file (even if you leave the base texture a png) crashes the ogl renderer and the pip installed python viewer. Which really throws a wrench in some of our dev workflows. Adding libktx loading for opengl should be fairly straightforward.. https://github.khronos.org/KTX-Software/libktx/index.html
But right now this seems to be the worst of all possible setups forcing wholesale switching to a filament renderer and breaking the python viewer with any use of compressed textures, or patching mujoco. I don't think there are callbacks for overriding any of this functionality, which still wouldn't really help with the pypi wheel.
Steps for reproduction
Use a ktx texture in a mjcf file.
Minimal model for reproduction
No response
Code required for reproduction
No response
Confirmations
- [x] I searched the latest documentation thoroughly before posting.
- [x] I searched previous Issues and Discussions, I am certain this has not been raised before.
Saw this is assigned, so ignore if you've got it covered. PR in case it's useful.
It just skips textures mjr_uploadTexture can't handle (not 3/4-channel) with a warning instead of aborting, so KTX stops crashing simulate. Only stops the crash though, ofc still won't render without libktx 😕
Thanks! I hadn't had a chance to look at it just yet, so your PR is much appreciated and I've gone ahead and approved it. Thanks!
My pleasure ! Thank you for approving