blend-my-bot


Nameblend-my-bot JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryA package to import URDF files into Blender
upload_time2024-01-29 10:11:42
maintainer
docs_urlNone
author"Giuseppe L'Erario"
requires_python>=3.10
license
keywords robotics blender animation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Blend My Bot

<div align="center">

**Import 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

</div>

## 🐍 Requirements

- [`python3`](<https://wiki.python.org/moin/BeginnersGuide>)
- [`Blender 3.6`](<https://www.blender.org/download/lts/3-6/>)
- [`iDynTree`](<https://github.com/robotology/idyntree>)
- [`numpy`](<https://numpy.org/>)
- [`bpy 3.6`](<https://pypi.org/project/bpy/>)

Note: This library has been tested with the `appimage` version 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 as [`blender-robotics-utils`](https://github.com/robotology/blender-robotics-utils).

## πŸ’Ύ Installation

Create a conda environment and install the dependencies:

```bash
conda create -n blender_env python=3.10
conda activate blender_env
```

Create a backup of the python folder in the blender folder:

```bash
mv blender_folder/version/python blender_folder/version/python_backup
```

Run the command below in the blender python folder to create a symbolic link to the conda environment in the blender python folder:

```bash
sudo ln -s ~/mambaforge/envs/blender_env blender_folder/version/python
```

From the root of the repository install the package:

```bash
pip install blend-my-bot
```

If you want to run the scripts from `Visual Studio Code`, you need to install the `vscode python` extension and set the python interpreter to the already created conda environment.

You need an additional vscode extension: `Blender Development` which can be found [here](https://marketplace.visualstudio.com/items?itemName=JacquesLucke.blender-development).

Once installed, you can run Blender by typing `Ctrl+Shift+P` and then `Blender: 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 typing `Ctrl+Shift+P` and then `Blender: 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 the `Scripting` tab of Blender and run it from there.

For possible issues when running the script see the [Troubleshooting](#troubleshooting) section.

## πŸš€ Usage

```python
# import the library
from blend_my_bot import ModelImporter
# import the blender python API
import bpy

# 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 animation

urdf_path = "path/to/urdf"
robot_name = "my_robot"
joints_list = ["joint1", "joint2", "joint3", "etc"]

# build the blender robot model
model = 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 seconds
bpy.context.scene.render.fps_base = time_length
# number of frames
bpy.context.scene.render.fps = number_of_frames
# when the animation starts
bpy.context.scene.frame_start = 0
# when the animation ends
bpy.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 robot
for k in range(number_of_frames):
    # jet the joint trajectory at time k
    s = joint_trajectory[k]
    # get the base pose described by a 4x4 homogeneous matrix at time k
    w_H_b = base_trajectory[k]
    # update the robot model
    model.update(w_H_b, s)
    # set the frame
    bpy.context.scene.frame_set(k)
```

Have a look at the `examples` folder for more examples.

In the `examples/jumping` folder you can find a script that generates a jumping animation of the `iCub` robot. Here the meshes are in a gray, `stl` format.

Having the meshes in an `obj` format, 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](<https://github.com/ami-iit/paper_lerario_2022_humanoids_planning-multimodal-locomotion>)

## 🦿 Troubleshooting

If 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 terminal **before** and then open `Visual Studio Code` from the terminal:

```bash
conda activate blender_env
code .
```

For example, when using [`resolve_robotics_uri_py`](https://github.com/ami-iit/resolve-robotics-uri-py) an error like the following one appears:

```
FileNotFoundError: resolve-robotics-uri-py: No file corresponding to uri "package://iCub/robots/iCubGazeboV2_7/model.urdf" found
```

This is due to the fact that environmental variables are not sourced. Activating the conda environment before opening `vscode` solves this issue!

## πŸ¦Έβ€β™‚οΈ Contributing

`blend-my-bot` is 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! πŸš€

## πŸ“ Tips

Some tips to speed up your Cycle render:
<https://www.youtube.com/watch?v=FNiobzflmpA>

Feel free to add your own tips here!

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "blend-my-bot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "robotics,blender,animation",
    "author": "\"Giuseppe L'Erario\"",
    "author_email": "gl.giuseppelerario@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e0/18/9d1bf9e8420a2b0916dcc280c6c3c0331b711ff7c09a8a5948f43e429c9b/blend-my-bot-1.0.1.tar.gz",
    "platform": null,
    "description": "# Blend My Bot\n\n<div align=\"center\">\n\n**Import your robot in Blender and create a nice render of it!**\n\nhttps://github.com/ami-iit/blend-my-bot/assets/29798643/c224cd56-1d90-42dd-aec5-960a13690ce7\n\n</div>\n\n## \ud83d\udc0d Requirements\n\n- [`python3`](<https://wiki.python.org/moin/BeginnersGuide>)\n- [`Blender 3.6`](<https://www.blender.org/download/lts/3-6/>)\n- [`iDynTree`](<https://github.com/robotology/idyntree>)\n- [`numpy`](<https://numpy.org/>)\n- [`bpy 3.6`](<https://pypi.org/project/bpy/>)\n\nNote: This library has been tested with the `appimage` version of Blender 3.6. You should use a Python version that matches the one supported by the Blender version.\n\nNote 2: This library does not define the rig of the robot. For this, you can use a library such as [`blender-robotics-utils`](https://github.com/robotology/blender-robotics-utils).\n\n## \ud83d\udcbe Installation\n\nCreate a conda environment and install the dependencies:\n\n```bash\nconda create -n blender_env python=3.10\nconda activate blender_env\n```\n\nCreate a backup of the python folder in the blender folder:\n\n```bash\nmv blender_folder/version/python blender_folder/version/python_backup\n```\n\nRun the command below in the blender python folder to create a symbolic link to the conda environment in the blender python folder:\n\n```bash\nsudo ln -s ~/mambaforge/envs/blender_env blender_folder/version/python\n```\n\nFrom the root of the repository install the package:\n\n```bash\npip install blend-my-bot\n```\n\nIf you want to run the scripts from `Visual Studio Code`, you need to install the `vscode python` extension and set the python interpreter to the already created conda environment.\n\nYou need an additional vscode extension: `Blender Development` which can be found [here](https://marketplace.visualstudio.com/items?itemName=JacquesLucke.blender-development).\n\nOnce installed, you can run Blender by typing `Ctrl+Shift+P` and then `Blender: 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 typing `Ctrl+Shift+P` and then `Blender: Run Script`.\n\nYou can add objects, lights, and cameras as well as play with render parameters directly in Blender.\nIf 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.\n\nNote that you could also write a script directly in the `Scripting` tab of Blender and run it from there.\n\nFor possible issues when running the script see the [Troubleshooting](#troubleshooting) section.\n\n## \ud83d\ude80 Usage\n\n```python\n# import the library\nfrom blend_my_bot import ModelImporter\n# import the blender python API\nimport bpy\n\n# ModelImporter needs 3 arguments:\n# - the name you want to give to your robot\n# - the path to the urdf file\n# - the list of the joints you want to move in the animation\n\nurdf_path = \"path/to/urdf\"\nrobot_name = \"my_robot\"\njoints_list = [\"joint1\", \"joint2\", \"joint3\", \"etc\"]\n\n# build the blender robot model\nmodel = ModelImporter.build_model(robot_name, urdf_path, joints_list)\n\n# you need to set the frame rate and the number of frames of the animation\n# length of the animation in seconds\nbpy.context.scene.render.fps_base = time_length\n# number of frames\nbpy.context.scene.render.fps = number_of_frames\n# when the animation starts\nbpy.context.scene.frame_start = 0\n# when the animation ends\nbpy.context.scene.frame_end = number_of_frames\n\n# in Blender the effective frame rate is fps / fps_base\n\n# you can now move the base and the joints of the robot\nfor k in range(number_of_frames):\n    # jet the joint trajectory at time k\n    s = joint_trajectory[k]\n    # get the base pose described by a 4x4 homogeneous matrix at time k\n    w_H_b = base_trajectory[k]\n    # update the robot model\n    model.update(w_H_b, s)\n    # set the frame\n    bpy.context.scene.frame_set(k)\n```\n\nHave a look at the `examples` folder for more examples.\n\nIn the `examples/jumping` folder you can find a script that generates a jumping animation of the `iCub` robot. Here the meshes are in a gray, `stl` format.\n\nHaving the meshes in an `obj` format, instead, will give a nicer and more colorful render! See the Readme of the following repository, for example!\n\n[Whole-Body Trajectory Optimization for Robot Multimodal Locomotion](<https://github.com/ami-iit/paper_lerario_2022_humanoids_planning-multimodal-locomotion>)\n\n## \ud83e\uddbf Troubleshooting\n\nIf 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 terminal **before** and then open `Visual Studio Code` from the terminal:\n\n```bash\nconda activate blender_env\ncode .\n```\n\nFor example, when using [`resolve_robotics_uri_py`](https://github.com/ami-iit/resolve-robotics-uri-py) an error like the following one appears:\n\n```\nFileNotFoundError: resolve-robotics-uri-py: No file corresponding to uri \"package://iCub/robots/iCubGazeboV2_7/model.urdf\" found\n```\n\nThis is due to the fact that environmental variables are not sourced. Activating the conda environment before opening `vscode` solves this issue!\n\n## \ud83e\uddb8\u200d\u2642\ufe0f Contributing\n\n`blend-my-bot` is an open-source project. Contributions are very welcome!\n\nOpen an issue with your feature request or if you spot a bug. Then, you can also proceed with a Pull-requests! \ud83d\ude80\n\n## \ud83d\udcdd Tips\n\nSome tips to speed up your Cycle render:\n<https://www.youtube.com/watch?v=FNiobzflmpA>\n\nFeel free to add your own tips here!\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A package to import URDF files into Blender",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [
        "robotics",
        "blender",
        "animation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e99b43b5991e84f69601cc066b2aa3eb3066f6e4221494c70da5b76a14c8bba6",
                "md5": "64e4032b1c55da8fac6d660218341554",
                "sha256": "9fcab13da3729fb20d29df8faa581164aa98f3d842c764f2ff95877a92c9dc1c"
            },
            "downloads": -1,
            "filename": "blend_my_bot-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64e4032b1c55da8fac6d660218341554",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 7385,
            "upload_time": "2024-01-29T10:11:40",
            "upload_time_iso_8601": "2024-01-29T10:11:40.319395Z",
            "url": "https://files.pythonhosted.org/packages/e9/9b/43b5991e84f69601cc066b2aa3eb3066f6e4221494c70da5b76a14c8bba6/blend_my_bot-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e0189d1bf9e8420a2b0916dcc280c6c3c0331b711ff7c09a8a5948f43e429c9b",
                "md5": "7b950019730c33f99055f44286dd2356",
                "sha256": "ac07a7b347db679933cfbb63e53ec270fb330b4c5ca94267d46c7a22fe702cc6"
            },
            "downloads": -1,
            "filename": "blend-my-bot-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7b950019730c33f99055f44286dd2356",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 71643,
            "upload_time": "2024-01-29T10:11:42",
            "upload_time_iso_8601": "2024-01-29T10:11:42.181028Z",
            "url": "https://files.pythonhosted.org/packages/e0/18/9d1bf9e8420a2b0916dcc280c6c3c0331b711ff7c09a8a5948f43e429c9b/blend-my-bot-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-29 10:11:42",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "blend-my-bot"
}
        
Elapsed time: 0.17082s