forked from robocasa/robocasa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_collision.py
32 lines (25 loc) · 1.06 KB
/
remove_collision.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import xml.etree.ElementTree as ET
import re
# Define the regex pattern
pattern = re.compile(r'cab_.*door')
# Load the XML file
INPUT_FILE = 'modified_baseline_model_no_doors.xml'
tree = ET.parse(INPUT_FILE)
root = tree.getroot()
# List to hold elements to remove
elements_to_remove = []
# Iterate through all elements in the XML tree
for elem in root.findall('.//*'):
# Check if the element has a "name" attribute and if it contains "cab" and "door"
if ("name" in elem.attrib and "coll" in elem.attrib["name"]) or ("rgba" in elem.attrib and (elem.attrib["rgba"] == "0.5 0 0 0.5" or elem.attrib["rgba"] == "0.5 0 0 1")):
elements_to_remove.append(elem)
# Remove the collected elements from their parents
for elem in elements_to_remove:
# Find the parent of the element
for parent in root.findall('.//*'):
if elem in list(parent):
print("removing..")
parent.remove(elem)
break # Exit the loop once the element is removed
# Save the modified XML back to a file
tree.write('modified_baseline_model_no_doors.xml')