-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify the URDF model for meshes paths #23
Comments
Steps
|
ImplementationI have implemented the changes in the Code ChangesIn the first part, the <visual name="Pelvis">
<geometry>
<mesh filename="package://meshes/Pelvis.stl" scale="0.6 1.06060606 1.06060606"/>
</geometry>
<material name="Link">
<color rgba="0.9922 0.8667 0.7922 1.0"/>
</material>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
</visual>
<visual name="Pelvis_RightRecAbd">
<geometry>
<mesh filename="package://meshes/Pelvis_RightRecAbd.stl" scale="0.6 1.06060606 1.06060606"/>
</geometry>
<material name="muscle">
<color rgba="0.9922 0.8667 0.7922 1.0"/>
</material>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
</visual> This change allows the Here’s the code that accomplishes this: with open(URDF_FILE_PATH, "r") as file:
urdf_content = file.read()
def modify_mesh_line(match):
filename = match.group(1)
scale_values = match.group(2)
new_filename = "package://meshes/" + filename.split("\\")[-1]
return f'<mesh filename="{new_filename}" scale="{scale_values}"/>'
modified_urdf_content = re.sub(r'<mesh filename=".*?\\meshes\\(.*?)" scale="(.*?)"/>', modify_mesh_line, urdf_content)
with open(URDF_FILE_PATH, "w") as file:
file.write(modified_urdf_content)
print("[OUTPUT] Model with 'package' successfully created. ✔") In the second part of the code, the process of visualizing the model requires the mesh files to be accessible using absolute paths. This is where the environment variable comes in: it points to the local directory containing the mesh files, allowing the model to load correctly in different environments. Here’s how the environment variable is used to modify the package_value = os.getenv('package')
if not package_value:
raise EnvironmentError("The environment variable 'package' is not set")
with open(URDF_FILE_PATH, "r") as file:
urdf_content = file.read()
def modify_mesh_line2(match):
filename = match.group(1)
scale_values = match.group(2)
new_filename = f"{package_value}/" + filename.split("\\")[-1]
return f'<mesh filename="{new_filename}" scale="{scale_values}"/>'
modified_urdf_content = re.sub(r'<mesh filename=".*?//meshes/(.*?)" scale="(.*?)"/>', modify_mesh_line2, urdf_content)
with open(URDF_FILE_PATH, "w") as file:
file.write(modified_urdf_content)
print("[OUTPUT] Model with path successfully created. ✔") This approach ensures that the model can be visualized with the correct mesh paths when the environment variable is set. To make this work, users must set the environment variable
|
Hello @LudovicaDanovaro , I am afraid using |
@traversaro I modified the |
Just FYI, the link to the commit I guess is 1048b96 . Anyhow, while I see that we are not setting anymore the |
More in general, instead of parsing the generated URDF two times to modify some values, could it make sense to directly set the mesh URI we want to set in human-model-generator/code/src/modifyMeshModels.py Lines 66 to 86 in 1048b96
|
At the moment of this commit, there are already some issues. To solve this problem I opened an issue in https://github.com/fishbotics/urchin: fishbotics/urchin#28 |
Thanks @LudovicaDanovaro ! In the meanwhile using the absolute path when dealing with urchin and then changing the path in the xml is a perfectly fine workaround! |
Objective
The goal is to make the human model URDF agnostic to local directory paths for meshes. Currently, the mesh files in the URDF model are referenced using a fixed local directory path. This requires modifying the URDF file on every computer or for every user. Instead, we aim to update the URDF to use a
package
variable, which will:package
variable to be set as an environment variable by the user. This variable should point to themeshes
folder inside thehuman-model-generator
repository.The text was updated successfully, but these errors were encountered: