Skip to content

Commit b32358b

Browse files
committed
Adjust parser
1 parent be935ba commit b32358b

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<robot name="different_places">
1+
<robot name="warning_different_place">
22
<link name="BaseLink">
33
<visual>
4-
<material name="green" />
4+
<material name="green">
5+
<color rgba="0.0 1.0 0.0 1"/>
6+
</material>
57
</visual>
68
<!-- This is a deliberate mistake. -->
79
<!-- The geometry is not a child of the visual. -->

tests/test_parser.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import pathlib
44

5+
import usdex.core
6+
from pxr import Tf
7+
58
from tests.util.ConverterTestCase import ConverterTestCase
69
from urdf_usd_converter._impl.urdf_parser.parser import URDFParser
710

@@ -60,16 +63,6 @@ def test_load_error_incorrect_vec4(self):
6063
with self.assertRaisesRegex(RuntimeError, r".*rgba: Invalid value: 0.0 1.0 \(line: 5\).*"):
6164
parser.parse()
6265

63-
def test_load_error_different_place(self):
64-
# Load the specified URDF file.
65-
model_path = pathlib.Path("tests/data/error_different_place.urdf")
66-
parser = URDFParser(model_path)
67-
68-
with self.assertRaisesRegex(
69-
RuntimeError, r".*geometry: Invalid element type. This uses a reserved tag, but in the wrong place \(line: 8\).*"
70-
):
71-
parser.parse()
72-
7366
def test_load_error_no_material_name(self):
7467
# Load the specified URDF file.
7568
model_path = pathlib.Path("tests/data/error_no_material_name.urdf")
@@ -222,6 +215,18 @@ def test_load_error_joint_axis_0(self):
222215
with self.assertRaisesRegex(RuntimeError, r".*axis: Axis xyz cannot be \(0, 0, 0\) \(line: 25\).*"):
223216
parser.parse()
224217

218+
def test_load_warning_different_place(self):
219+
# Load the specified URDF file.
220+
model_path = pathlib.Path("tests/data/warning_different_place.urdf")
221+
parser = URDFParser(model_path)
222+
223+
with usdex.test.ScopedDiagnosticChecker(
224+
self,
225+
[(Tf.TF_DIAGNOSTIC_WARNING_TYPE, ".*geometry: Invalid element type. This uses a reserved tag, but in the wrong place.*")],
226+
level=usdex.core.DiagnosticsLevel.eWarning,
227+
):
228+
parser.parse()
229+
225230
def test_has_no_material(self):
226231
# Load the specified URDF file.
227232
model_path = pathlib.Path("tests/data/simple_box_no_material.urdf")

urdf_usd_converter/_impl/mesh.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def convert_meshes(data: ConversionData):
4545

4646
if name != safe_name:
4747
usdex.core.setDisplayName(mesh_prim, name)
48-
convert_mesh(mesh_prim, filename, data)
48+
49+
try:
50+
convert_mesh(mesh_prim, filename, data)
51+
except Exception as e:
52+
Tf.Warn(f"Failed to convert mesh: {filename}: {e}")
4953

5054
usdex.core.saveStage(data.libraries[Tokens.Geometry], comment=f"Mesh Library for {data.urdf_parser.get_robot_name()}. {data.comment}")
5155

urdf_usd_converter/_impl/urdf_parser/parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import xml.etree.ElementTree as ET
55
from pathlib import Path
66

7+
from pxr import Tf
8+
79
from .elements import (
810
ElementAxis,
911
ElementBase,
@@ -223,7 +225,8 @@ def _parse_xml_elements(self, node: ET.Element, prev_element: ElementBase = None
223225

224226
# Error if using reserved tags but structure is different.
225227
if not element:
226-
raise ValueError(self._get_error_message("Invalid element type. This uses a reserved tag, but in the wrong place", node))
228+
Tf.Warn(self._get_error_message("Invalid element type. This uses a reserved tag, but in the wrong place", node))
229+
element = ElementUndefined()
227230

228231
element.tag = node.tag
229232
element.path = current_path
@@ -458,13 +461,13 @@ def _get_element_line_number(self, element: ET.Element) -> int:
458461
def _get_defined_material_names(self) -> list[str]:
459462
"""
460463
Get the defined material names.
461-
462464
Returns:
463465
A list of defined material names.
464466
"""
465467
# Create a list of defined material names.
466468
# This includes both global materials and materials specified within the visual.
467469
defined_material_names = [material.name for material in self.root_element.materials]
470+
468471
for link in self.root_element.links:
469472
for visual in link.visuals:
470473
material = visual.material

0 commit comments

Comments
 (0)