-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add rudimentary stl support #64
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,15 @@ To rebuild only the `moveit_drake` package: | |
rm -rf build/moveit_drake install/moveit_drake | ||
colcon build --packages-select moveit_drake | ||
``` | ||
|
||
## Known issues | ||
|
||
### .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: | ||
|
||
``` | ||
./scripts/convert_stl_to_obj.py /PATH/TO/YOUR/MESH/DIR | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to instruct people to rebuild the package after running the script? I assume the OBJ files won't make it into install space otherwise. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -147,4 +147,12 @@ getPiecewisePolynomial(const ::robot_trajectory::RobotTrajectory& robot_trajecto | |||||
void getRobotTrajectory(const ::drake::trajectories::Trajectory<double>& drake_trajectory, const double delta_t, | ||||||
const ::drake::multibody::MultibodyPlant<double>& plant, | ||||||
std::shared_ptr<::robot_trajectory::RobotTrajectory>& moveit_trajectory); | ||||||
|
||||||
/** | ||||||
* @brief Converts all STL file paths in a string to OBJ file paths | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it clear that it's in a URDF description string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* @param input Input robot description | ||||||
* @return std::string Robot description with all STL file paths replaced by OBJ file paths | ||||||
*/ | ||||||
[[nodiscard]] std::string replaceSTLWithOBJ(const std::string& input); | ||||||
} // namespace moveit::drake |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ repositories: | |
version: main | ||
moveit_resources: | ||
type: git | ||
url: https://github.com/moveit/moveit_resources | ||
version: ros2 | ||
url: https://github.com/sjahr/moveit_resources | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need a new branch of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has the .obj files already, so no need to run the script again |
||
version: moveit_drake | ||
moveit_msgs: | ||
type: git | ||
url: https://github.com/moveit/moveit_msgs | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import trimesh | ||
import argparse | ||
|
||
|
||
def convert_stl_to_obj(directory): | ||
""" | ||
Finds all STL files in the given directory and subdirectories, and converts each to an OBJ file. | ||
|
||
Args: | ||
directory (str): The path to the directory to search. | ||
""" | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if file.lower().endswith(".stl"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're already calling |
||
stl_path = os.path.join(root, file) | ||
obj_path = os.path.splitext(stl_path)[0] + ".obj" | ||
|
||
try: | ||
# Load the STL file | ||
mesh = trimesh.load(stl_path) | ||
|
||
# Export the mesh as OBJ | ||
mesh.export(obj_path) | ||
|
||
print(f"Converted: {stl_path} -> {obj_path}") | ||
except Exception as e: | ||
print(f"Failed to convert {stl_path}: {e}") | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Convert STL files to OBJ format.") | ||
parser.add_argument( | ||
"directory", type=str, help="The directory to search for STL files." | ||
) | ||
args = parser.parse_args() | ||
|
||
if os.path.isdir(args.directory): | ||
convert_stl_to_obj(args.directory) | ||
else: | ||
print("The provided path is not a directory. Please check and try again.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,4 +237,20 @@ void getRobotTrajectory(const ::drake::trajectories::Trajectory<double>& drake_t | |
t_prev = t; | ||
} | ||
} | ||
|
||
std::string replaceSTLWithOBJ(const std::string& input) | ||
{ | ||
std::string result = input; | ||
const std::string target = ".stl"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
const std::string replacement = ".obj"; | ||
|
||
size_t pos = 0; | ||
while ((pos = result.find(target, pos)) != std::string::npos) | ||
{ | ||
result.replace(pos, target.length(), replacement); | ||
pos += replacement.length(); // Move past the replacement to avoid infinite loop | ||
} | ||
|
||
return result; | ||
} | ||
} // namespace moveit::drake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One sentence per line would be preferable