Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
sjahr committed Nov 29, 2024
1 parent aef4db6 commit 8ee7ec1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ colcon build --packages-select moveit_drake

### .stl support

Unfortunately, Drake does not support `.stl` files (11/28/2024, see [drake#19408](https://github.com/RobotLocomotion/drake/issues/19408)). We're working around this by replacing the `.stl` files in the urdf string
with `.obj` files in the plugin implementations. Make sure that the moveit config you're using contains the relevant `.stl` files. If it doesn't,
take a look into the scripts/ directory. We've provided a simple python script to add additional `.obj` files for given `.stl` files. Usage:
Unfortunately, Drake does not support `.stl` files (11/28/2024, see [drake#19408](https://github.com/RobotLocomotion/drake/issues/19408)).
We're working around this by replacing the `.stl` files in the urdf string with `.obj` files in the plugin implementations.
Make sure that the moveit config you're using contains the relevant `.stl` files. If it doesn't, take a look into the scripts/ directory.
We've provided a simple python script to add additional `.obj` files for given `.stl` files. Usage:

```
./scripts/convert_stl_to_obj.py /PATH/TO/YOUR/MESH/DIR
```
Don't forget to rebuild your description package so the .obj files are copied into the workspace's install directory.
2 changes: 1 addition & 1 deletion include/moveit/drake/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void getRobotTrajectory(const ::drake::trajectories::Trajectory<double>& drake_t
std::shared_ptr<::robot_trajectory::RobotTrajectory>& moveit_trajectory);

/**
* @brief Converts all STL file paths in a string to OBJ file paths
* @brief Converts all STL file paths in a URDF string to OBJ file paths
*
* @param input Input robot description
* @return std::string Robot description with all STL file paths replaced by OBJ file paths
Expand Down
8 changes: 5 additions & 3 deletions scripts/convert_stl_to_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def convert_stl_to_obj(directory):
"""
for root, _, files in os.walk(directory):
for file in files:
if file.lower().endswith(".stl"):
stl_path = os.path.join(root, file)
obj_path = os.path.splitext(stl_path)[0] + ".obj"
stl_path = os.path.join(root, file)
file_root, file_ext = os.path.splitext(stl_path)

if file_ext.lower() in [".stl", ".STL"]: # Check if the file is an STL file
obj_path = file_root + ".obj" # Create the OBJ file path

try:
# Load the STL file
Expand Down
14 changes: 11 additions & 3 deletions src/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,21 @@ void getRobotTrajectory(const ::drake::trajectories::Trajectory<double>& drake_t
std::string replaceSTLWithOBJ(const std::string& input)
{
std::string result = input;
const std::string target = ".stl";
const std::string lower_case_stl = ".stl";
const std::string upper_case_stl = ".STL";
const std::string replacement = ".obj";

size_t pos = 0;
while ((pos = result.find(target, pos)) != std::string::npos)
while ((pos = result.find(lower_case_stl, pos)) != std::string::npos)
{
result.replace(pos, target.length(), replacement);
result.replace(pos, lower_case_stl.length(), replacement);
pos += replacement.length(); // Move past the replacement to avoid infinite loop
}

pos = 0;
while ((pos = result.find(upper_case_stl, pos)) != std::string::npos)
{
result.replace(pos, upper_case_stl.length(), replacement);
pos += replacement.length(); // Move past the replacement to avoid infinite loop
}

Expand Down

0 comments on commit 8ee7ec1

Please sign in to comment.