Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dm_control/mjcf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@
<attribute name="texcoord" type="string"/>
<attribute name="material" type="string"/>
<attribute name="rgba" type="array" array_type="float" array_size="4"/>
<attribute name="flatskin" type="int"/>
<attribute name="flatskin" type="keyword" valid_values="false true"/>
<attribute name="pos" type="array" array_type="float" array_size="3"/>
<attribute name="quat" type="array" array_type="float" array_size="4"/>
<attribute name="axisangle" type="array" array_type="float" array_size="4"/>
Expand Down Expand Up @@ -1641,7 +1641,7 @@
<attribute name="texcoord" type="string"/>
<attribute name="material" type="string"/>
<attribute name="rgba" type="array" array_type="float" array_size="4"/>
<attribute name="flatskin" type="int"/>
<attribute name="flatskin" type="keyword" valid_values="false true"/>
<attribute name="pos" type="array" array_type="float" array_size="3"/>
<attribute name="quat" type="array" array_type="float" array_size="4"/>
<attribute name="axisangle" type="array" array_type="float" array_size="4"/>
Expand Down Expand Up @@ -1810,18 +1810,18 @@
<element name="flex" repeated="true" namespace="deformable">
<attributes>
<attribute name="name" type="identifier"/>
<attribute name="group" type="reference"/>
<attribute name="dim" type="int" required="true"/>
<attribute name="radius" type="float" required="true"/>
<attribute name="group" type="int"/>
<attribute name="dim" type="int"/>
<attribute name="radius" type="float"/>
<attribute name="material" type="reference"/>
<attribute name="rgba" type="array" array_type="float" array_size="4"/>
<attribute name="flatskin" type="array" array_type="float" array_size="2"/>
<attribute name="flatskin" type="keyword" valid_values="false true"/>
<attribute name="body" type="string"/>
<attribute name="vertex" type="array" array_type="float" array_size="5"/>
<attribute name="vertex" type="array" array_type="float"/>
<attribute name="element" type="array" array_type="int"/>
<attribute name="texcoord" type="array" array_type="float"/>
<attribute name="elemtexcoord" type="array" array_type="float"/>
<attribute name="node" type="array" array_type="float" array_size="3"/>
<attribute name="node" type="array" array_type="float"/>
<attribute name="nodecoord" type="array" array_type="float"/>
<attribute name="cellcount" type="array" array_type="int" array_size="3"/>
<attribute name="dof" type="keyword" valid_values="trilinear quadratic"/>
Expand Down
41 changes: 41 additions & 0 deletions dm_control/mjcf/xml_validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,47 @@ def validate(xml_string, assets=None):

class XMLValidationTest(absltest.TestCase):

def testDeformableFlexRoundTrip(self):
# A flex needs three floats per vertex, so even the smallest one exceeds
# the five entries the schema used to allow. `dim` and `radius` are
# omitted here because MuJoCo supplies defaults for both.
model = parser.from_xml_string("""
<mujoco model="test">
<worldbody>
<body name="v0"><freejoint/><geom type="sphere" size="0.01"/></body>
<body name="v1" pos="0.1 0 0"><freejoint/><geom type="sphere" size="0.01"/></body>
<body name="v2" pos="0 0.1 0"><freejoint/><geom type="sphere" size="0.01"/></body>
</worldbody>
<deformable>
<flex name="f" group="2" flatskin="true" body="v0 v1 v2"
vertex="0 0 0 0.1 0 0 0 0.1 0" element="0 1 2"/>
</deformable>
</mujoco>
""")
xml_string = model.to_xml_string()
validate(xml_string)
mjmodel = wrapper.MjModel.from_xml_string(xml_string)
self.assertEqual(mjmodel.flex_vertnum[0], 3)
self.assertEqual(mjmodel.flex_group[0], 2)
self.assertTrue(mjmodel.flex_flatskin[0])

def testFlexcompFlatskinIsBoolean(self):
for parent_open, parent_close in (('<body name="b">', '</body>'), ('', '')):
model = parser.from_xml_string("""
<mujoco model="test">
<worldbody>
%s
<flexcomp name="fc" type="grid" dim="2" count="3 3 1" spacing="0.1 0.1 0.1"
radius="0.001" flatskin="true"/>
%s
</worldbody>
</mujoco>
""" % (parent_open, parent_close))
xml_string = model.to_xml_string()
validate(xml_string)
mjmodel = wrapper.MjModel.from_xml_string(xml_string)
self.assertTrue(mjmodel.flex_flatskin[0])

def testXmlAttach(self):
robot_arm = parser.from_file(_ROBOT_XML)
arena = parser.from_file(_ARENA_XML)
Expand Down