Package: blend-my-bot
Blend My BotImport your robot in Blender and create a nice render of it!https://github.com/ami-iit/blend-my-bot/assets/29798643/c224cd56-1d90-42dd-aec5-960a13690ce7🐍 Requirementspython3Blender 3.6iDynTreenumpybpy 3.6Note: This library has been tested with theappimageversion of Blender 3.6. You should use a Python version that matches the one supported by the Blender version.Note 2: This library does not define the rig of the robot. For this, you can use a library such asblender-robotics-utils.💾 InstallationCreate a conda environment and install the dependencies:condacreate-nblender_envpython=3.10
condaactivateblender_envCreate a backup of the python folder in the blender folder:mvblender_folder/version/pythonblender_folder/version/python_backupRun the command below in the blender python folder to create a symbolic link to the conda environment in the blender python folder:sudoln-s~/mambaforge/envs/blender_envblender_folder/version/pythonFrom the root of the repository install the package:pipinstallblend-my-botIf you want to run the scripts fromVisual Studio Code, you need to install thevscode pythonextension and set the python interpreter to the already created conda environment.You need an additional vscode extension:Blender Developmentwhich can be foundhere.Once installed, you can run Blender by typingCtrl+Shift+Pand thenBlender: Start. It will ask you to select the blender executable: select the one in the folder where you extracted the blender archive (or the installed version if you installed it). Once Blender is running, you can run the script by typingCtrl+Shift+Pand thenBlender: Run Script.You can add objects, lights, and cameras as well as play with render parameters directly in Blender.
If you prefer, you can save the Blender project. Everything will be there, including the robot and its motion, so that it does not need to run your script again.Note that you could also write a script directly in theScriptingtab of Blender and run it from there.For possible issues when running the script see theTroubleshootingsection.🚀 Usage# import the libraryfromblend_my_botimportModelImporter# import the blender python APIimportbpy# ModelImporter needs 3 arguments:# - the name you want to give to your robot# - the path to the urdf file# - the list of the joints you want to move in the animationurdf_path="path/to/urdf"robot_name="my_robot"joints_list=["joint1","joint2","joint3","etc"]# build the blender robot modelmodel=ModelImporter.build_model(robot_name,urdf_path,joints_list)# you need to set the frame rate and the number of frames of the animation# length of the animation in secondsbpy.context.scene.render.fps_base=time_length# number of framesbpy.context.scene.render.fps=number_of_frames# when the animation startsbpy.context.scene.frame_start=0# when the animation endsbpy.context.scene.frame_end=number_of_frames# in Blender the effective frame rate is fps / fps_base# you can now move the base and the joints of the robotforkinrange(number_of_frames):# jet the joint trajectory at time ks=joint_trajectory[k]# get the base pose described by a 4x4 homogeneous matrix at time kw_H_b=base_trajectory[k]# update the robot modelmodel.update(w_H_b,s)# set the framebpy.context.scene.frame_set(k)Have a look at theexamplesfolder for more examples.In theexamples/jumpingfolder you can find a script that generates a jumping animation of theiCubrobot. Here the meshes are in a gray,stlformat.Having the meshes in anobjformat, instead, will give a nicer and more colorful render! See the Readme of the following repository, for example!Whole-Body Trajectory Optimization for Robot Multimodal Locomotion🦿 TroubleshootingIf you install a new package in the conda environment but it is not working as you expect when you run the script, try to activate it in a terminalbeforeand then openVisual Studio Codefrom the terminal:condaactivateblender_env
code.For example, when usingresolve_robotics_uri_pyan error like the following one appears:FileNotFoundError: resolve-robotics-uri-py: No file corresponding to uri "package://iCub/robots/iCubGazeboV2_7/model.urdf" foundThis is due to the fact that environmental variables are not sourced. Activating the conda environment before openingvscodesolves this issue!🦸‍♂️ Contributingblend-my-botis an open-source project. Contributions are very welcome!Open an issue with your feature request or if you spot a bug. Then, you can also proceed with a Pull-requests! 🚀📝 TipsSome tips to speed up your Cycle render:https://www.youtube.com/watch?v=FNiobzflmpAFeel free to add your own tips here!