@@ -187,15 +187,29 @@ def transform_urdf_to_macro(input_path, connector_link, no_prefix):
187187 # Add prefix to element names
188188 if "name" in elem .attrib :
189189 elem .attrib ["name" ] = add_prefix_to_name (elem .attrib ["name" ])
190- # Update joint references to use prefixed names
191- if elem .tag in ["joint" ]:
190+ # Update references based on element type
191+ if elem .tag == "joint" :
192+ # Update joint references
192193 for sub in elem .findall ("parent" ):
193194 sub .attrib ["link" ] = add_prefix_to_name (sub .attrib ["link" ])
194195 for sub in elem .findall ("child" ):
195196 sub .attrib ["link" ] = add_prefix_to_name (sub .attrib ["link" ])
196197 for sub in elem .findall ("mimic" ):
197198 if "joint" in sub .attrib :
198199 sub .attrib ["joint" ] = add_prefix_to_name (sub .attrib ["joint" ])
200+ elif elem .tag == "link" :
201+ # Update material references in visual and collision elements
202+ for visual in elem .findall ("visual" ):
203+ for material in visual .findall ("material" ):
204+ if "name" in material .attrib :
205+ material .attrib ["name" ] = add_prefix_to_name (material .attrib ["name" ])
206+ for collision in elem .findall ("collision" ):
207+ for material in collision .findall ("material" ):
208+ if "name" in material .attrib :
209+ material .attrib ["name" ] = add_prefix_to_name (material .attrib ["name" ])
210+ elif elem .tag == "material" :
211+ # Material definitions already have their names prefixed above
212+ pass
199213 macro .append (elem )
200214
201215 indent_element (macro , level = 1 )
0 commit comments