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:
committed by
Copybara-Service
parent
42d8454555
commit
1fb1810b07
@@ -9353,6 +9353,13 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
||||
type=ValueType(name='mjsPlugin'),
|
||||
doc='sdf plugin',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='material',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjString'),
|
||||
),
|
||||
doc='name of material',
|
||||
),
|
||||
StructFieldDecl(
|
||||
name='info',
|
||||
type=PointerType(
|
||||
|
||||
@@ -1478,6 +1478,34 @@ class SpecsTest(absltest.TestCase):
|
||||
self.assertEqual(mj_model.sensor_dim[0], 4)
|
||||
self.assertEqual(mj_model.sensor_dim[1], 1)
|
||||
|
||||
def test_mesh_material(self):
|
||||
spec = mujoco.MjSpec()
|
||||
|
||||
spec.add_material(name='red', rgba=(1, 0, 0, 1))
|
||||
spec.add_material(name='green', rgba=(0, 1, 0, 1))
|
||||
|
||||
mesh = spec.add_mesh(name='sphere')
|
||||
mesh.make_sphere(subdivision=1)
|
||||
mesh.material = 'red'
|
||||
|
||||
geom = spec.worldbody.add_geom()
|
||||
geom.type = mujoco.mjtGeom.mjGEOM_MESH
|
||||
geom.meshname = 'sphere'
|
||||
|
||||
geom_2 = spec.worldbody.add_geom()
|
||||
geom_2.type = mujoco.mjtGeom.mjGEOM_MESH
|
||||
geom_2.meshname = 'sphere'
|
||||
geom_2.material = 'green'
|
||||
|
||||
model = spec.compile()
|
||||
|
||||
self.assertEqual(model.geom_matid[0], 0)
|
||||
self.assertEqual(model.geom_matid[1], 1)
|
||||
|
||||
mesh.material = 'green'
|
||||
model = spec.compile()
|
||||
|
||||
self.assertEqual(model.geom_matid[0], 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
absltest.main()
|
||||
|
||||
Reference in New Issue
Block a user