Add ability to specify a material assignment to a mesh asset.

This extends both the spec and the XML definition to allow specification of a material name on a mesh. This material acts as a fallback in the case that the referencing geom element does not specify a material of it's own.

PiperOrigin-RevId: 798232378
Change-Id: Iaf300c727732744ea1b613e64334ee505ac6e209
This commit is contained in:
Sam Haves
2025-08-22 09:10:35 -07:00
committed by Copybara-Service
parent 42d8454555
commit 1fb1810b07
13 changed files with 120 additions and 29 deletions
+23
View File
@@ -1379,5 +1379,28 @@ TEST_F(MjCMeshTest, SphereSizes) {
mj_deleteModel(model);
}
TEST_F(MjCMeshTest, MeshMaterial) {
static constexpr char xml[] = R"(
<mujoco model="mesh_material">
<asset>
<mesh name="h0" builtin="sphere" params="0" material="m1"/>
<material name="m0" rgba="1 0 0 1"/>
<material name="m1" rgba="1 1 0 1"/>
</asset>
<worldbody>
<geom name="g0" type="mesh" mesh="h0"/>
<geom name="g1" type="mesh" mesh="h0" material="m0"/>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
EXPECT_EQ(model->geom_matid[0], 1);
EXPECT_EQ(model->geom_matid[1], 0);
mj_deleteModel(model);
}
} // namespace
} // namespace mujoco