-
Notifications
You must be signed in to change notification settings - Fork 10
Add rudimentary stl support #64
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
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 |
|---|---|---|
|
|
@@ -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 | ||
sea-bass marked this conversation as resolved.
Show resolved
Hide resolved
Member
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. I am worried about the fact that dockerfile doesnt use this repos file. |
||
| 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,49 @@ | ||
| #!/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: | ||
| stl_path = os.path.join(root, file) | ||
| file_root, file_ext = os.path.splitext(stl_path) | ||
|
|
||
| if file_ext.lower() == ".stl": # Check if the file is an STL file | ||
| obj_path = file_root + ".obj" # Create the OBJ file path | ||
|
|
||
| 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,28 @@ 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 lower_case_stl = ".stl"; | ||
| const std::string upper_case_stl = ".STL"; | ||
| const std::string replacement = ".obj"; | ||
|
Comment on lines
+244
to
+246
Member
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 didn't we think of to use |
||
|
|
||
| size_t pos = 0; | ||
| while ((pos = result.find(lower_case_stl, pos)) != std::string::npos) | ||
| { | ||
| 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 | ||
| } | ||
|
Comment on lines
+243
to
+260
Member
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. As i understood, you're trying to change file extenstions only. By asssuming it is used c++17 standard, why didn't you consider to use filesystem library's replace extenstion for this stuff? |
||
|
|
||
| return result; | ||
| } | ||
| } // namespace moveit::drake | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| #include <cmath> | ||
| #include <iostream> | ||
|
Member
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. Is this header really necessary? |
||
| #include <string> | ||
|
|
||
| #include <drake/geometry/meshcat_params.h> | ||
| #include <drake/geometry/geometry_frame.h> | ||
|
|
@@ -358,8 +360,6 @@ bool KTOptPlanningContext::terminate() | |
|
|
||
| void KTOptPlanningContext::setRobotDescription(const std::string& robot_description) | ||
| { | ||
| robot_description_ = robot_description; | ||
|
|
||
| // also perform some drake related initialisations here | ||
| builder = std::make_unique<DiagramBuilder<double>>(); | ||
|
|
||
|
|
@@ -369,13 +369,11 @@ void KTOptPlanningContext::setRobotDescription(const std::string& robot_descript | |
|
|
||
| auto [plant, scene_graph] = drake::multibody::AddMultibodyPlantSceneGraph(builder.get(), 0.0); | ||
|
|
||
| // TODO:(kamiradi) Figure out object parsing | ||
| // auto robot_instance = Parser(plant_, | ||
| // scene_graph_).AddModelsFromString(robot_description_, ".urdf"); | ||
| // Drake cannot handle stl files, so we convert them to obj. Make sure these files are available in your moveit config! | ||
| const auto description_with_obj = moveit::drake::replaceSTLWithOBJ(robot_description); | ||
| auto robot_instance = | ||
| drake::multibody::Parser(&plant, &scene_graph).AddModelsFromString(description_with_obj, ".urdf"); | ||
|
|
||
| const char* ModelUrl = params_.drake_robot_description.c_str(); | ||
| const std::string urdf = drake::multibody::PackageMap{}.ResolveUrl(ModelUrl); | ||
| auto robot_instance = drake::multibody::Parser(&plant, &scene_graph).AddModels(urdf); | ||
| plant.WeldFrames(plant.world_frame(), plant.GetFrameByName(params_.base_frame)); | ||
|
|
||
| // planning scene transcription | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.