add support for non-rgb textures in xml_native_writer

PiperOrigin-RevId: 736221430
Change-Id: I83c19e06f0f7be054a88c3e894807e7b90ee012a
This commit is contained in:
Tom Power
2025-03-12 12:16:31 -07:00
committed by Copybara-Service
parent 5c3bab4d09
commit 8f4c5c4b16
5 changed files with 55 additions and 6 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+17
View File
@@ -0,0 +1,17 @@
<mujoco>
<asset>
<hfield name="hfield" file="hfield.png" size="0.5 0.5 0.05 0.1"/>
<texture name="hfield" type="2d" file="hfield.png"/>
<material name="hfield">
<layer texture="hfield" role="rgb"/>
<layer texture="hfield" role="orm"/>
<layer texture="hfield" role="normal"/>
</material>
</asset>
<worldbody>
<light pos="-.4 .6 1"/>
<geom type="hfield" hfield="hfield" pos="-.4 .6 .05" material="hfield"/>
</worldbody>
</mujoco>
+21
View File
@@ -46,6 +46,9 @@ using ::testing::FloatEq;
using XMLWriterTest = PluginTest;
static const char* const kNonRgbTextureXMLPath =
"xml/testdata/hfield_png_nonrgb.xml";
TEST_F(XMLWriterTest, EmptyModel) {
static constexpr char xml[] = "<mujoco/>";
mjModel* model = LoadModelFromString(xml);
@@ -1326,6 +1329,24 @@ TEST_F(XMLWriterLocaleTest, IgnoresLocale) {
EXPECT_EQ(std::string(formatted), "3,9375");
}
TEST_F(XMLWriterTest, NonRGBTextures) {
const std::string xml_path = GetTestDataFilePath(kNonRgbTextureXMLPath);
std::array<char, 1024> error;
mjModel* model = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
std::string saved_xml = SaveAndReadXml(model);
EXPECT_FALSE(saved_xml.empty());
// check that layers are written correctly
EXPECT_THAT(saved_xml, HasSubstr("<material name=\"hfield\">"));
EXPECT_THAT(saved_xml, HasSubstr("<layer texture=\"hfield\" role=\"rgb\"/>"));
EXPECT_THAT(saved_xml, HasSubstr("<layer texture=\"hfield\" role=\"orm\"/>"));
EXPECT_THAT(saved_xml,
HasSubstr("<layer texture=\"hfield\" role=\"normal\"/>"));
mj_deleteModel(model);
}
// ------------------- test loading and saving multiple files ------------------
TEST_F(XMLWriterTest, WriteReadCompare) {