From ff5bbb1a4cd8ed567fa260bc916742e425aa1cbc Mon Sep 17 00:00:00 2001 From: zevbo Date: Thu, 31 Aug 2023 18:45:21 +0200 Subject: [PATCH] fix: dont add materials randomly (#9) --- tests/extender.urdf | 3 ++ tests/extender2.urdf | 3 ++ tests/output.urdf | 8 ++--- urdf_compose/urdf_obj.py | 64 ++-------------------------------------- 4 files changed, 13 insertions(+), 65 deletions(-) diff --git a/tests/extender.urdf b/tests/extender.urdf index 01e0d57..1d3f4e3 100644 --- a/tests/extender.urdf +++ b/tests/extender.urdf @@ -1,5 +1,8 @@ + + + diff --git a/tests/extender2.urdf b/tests/extender2.urdf index 16eca42..63a15bc 100644 --- a/tests/extender2.urdf +++ b/tests/extender2.urdf @@ -1,5 +1,8 @@ + + + diff --git a/tests/output.urdf b/tests/output.urdf index 6e3a627..1b0fa70 100644 --- a/tests/output.urdf +++ b/tests/output.urdf @@ -1,5 +1,8 @@ + + + @@ -27,10 +30,7 @@ - - - - + diff --git a/urdf_compose/urdf_obj.py b/urdf_compose/urdf_obj.py index 86b25c8..6167711 100644 --- a/urdf_compose/urdf_obj.py +++ b/urdf_compose/urdf_obj.py @@ -1,47 +1,12 @@ -import copy import os import subprocess import xml.etree.ElementTree as ET from pathlib import Path -from uuid import uuid1 from urdf_compose.xml_utils import elements_equal # URDFObj should not be specific to us as Tutor -std_materials = ET.fromstring( - """ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -""" -) - class CheckURDFFailure(Exception): pass @@ -103,20 +68,6 @@ def write_xml(self, dest: Path) -> None: dest.touch(exist_ok=True) self.tree.write(str(dest), xml_declaration=True, encoding="UTF-8") - def _add_colors(self) -> None: - materials_used = set() - materials_defined = set() - for material in self.getroot().iter("material"): - name = material.attrib["name"] - if len(material) == 0: - materials_used.add(name) - else: - materials_defined.add(name) - - for mat in std_materials: - if mat.attrib["name"] in materials_used and mat.attrib["name"] not in materials_defined: - self.getroot().append(copy.deepcopy(mat)) - def __hash__(self) -> int: return hash(id(self)) @@ -150,20 +101,11 @@ def __init__(self, path: Path, check: bool = True): tree = ET.ElementTree() tree.parse(str(self.path)) super().__init__(tree) - self._add_colors() if check: - check_file = self.path.parent / f"{self.path.name}_check_urdfOBJ{uuid1()}.urdf" - self.write_xml(check_file) - check_urdf_result = check_urdf(check_file) - - if check_file.exists() and check_urdf_result is None: - check_file.unlink() - else: - raise RuntimeError( - f"Attempted to create URDFObj, but given invalid urdf file {path}. You can" - f"check adjusted file at {check_file}. {check_urdf_result=}", - ) + check_urdf_result = check_urdf(path) + if check_urdf_result is not None: + raise check_urdf_result def __repr__(self) -> str: return f"ExplicitURDFObj from {self.path.name}"