Skip to content

Commit

Permalink
Merge pull request DLR-RM#401 from DLR-RM/develop
Browse files Browse the repository at this point in the history
Version 2.2.0 PR
  • Loading branch information
themasterlink authored Dec 17, 2021
2 parents 6b703a6 + 95ada1c commit b9e751a
Show file tree
Hide file tree
Showing 97 changed files with 1,670 additions and 498 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blenderprochelper.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: BlenderProcHelper

on: [push, pull_request, workflow_dispatch]
on: [pull_request, workflow_dispatch]

jobs:
Run-BlenderProcHelper:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ blender
.vscode/
output/
debug/
resources/AMASS
resources/cctextures*
resources/scenenet/*zip
resources/scenenet/SceneNetData
Expand Down
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ blenderproc vis hdf5 output/0.hdf5

Thats it! You rendered your first image with BlenderProc!

### Debugging
### Debugging in the Blender GUI

To understand what is actually going on, BlenderProc has the great feature of visualizing everything inside the blender UI.
To do so, simply call your script with the `debug` instead of `run` subcommand:
Expand All @@ -122,6 +122,68 @@ As in the normal mode, print statements are still printed to the terminal.

The pipeline can be run multiple times, as in the beginning of each run the scene is cleared.

### Breakpoint-Debugging in IDEs

As blenderproc runs in blenders separate python environment, debugging your blenderproc script cannot be done in the same way as with any other python script.
Therefore, remote debugging is necessary, which is explained for vscode and PyCharm in the following:

#### Debugging with vscode

First, install the `debugpy` package in blenders python environment.

```
blenderproc pip install debugpy
```

Now add the following configuration to your vscode [launch.json](https://code.visualstudio.com/docs/python/debugging#_initialize-configurations).

```json
{
"name": "Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
```

Finally, add the following lines to the top (after the imports) of your blenderproc script which you want to debug.

```python
import debugpy
debugpy.listen(5678)
debugpy.wait_for_client()
```

Now run your blenderproc script as usual via the CLI and then start the added "Attach" configuration in vscode.
You are now able to add breakpoints and go through the execution step by step.

#### Debugging with PyCharm Professional

In Pycharm, go to `Edit configurations...` and create a [new configuration](https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config) based on `Python Debug Server`.
The configuration will show you, specifically for your version, which pip package to install and which code to add into the script.
The following assumes Pycharm 2021.3:

First, install the `pydevd-pycharm` package in blenders python environment.
Unfortunately, the package cannot be installed into our custom separate packages folder, therefore, make sure to add `--not-use-custom-package-path`.

```
blenderproc pip install pydevd-pycharm~=212.5457.59 --not-use-custom-package-path
```

Now, add the following code to the top (after the imports) of your blenderproc script which you want to debug.

```python
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=12345, stdoutToServer=True, stderrToServer=True)
```

Then, first run your `Python Debug Server` configuration in PyCharm and then run your blenderproc script as usual via the CLI.
PyCharm should then go in debug mode, blocking the next code line.
You are now able to add breakpoints and go through the execution step by step.

## What to do next?

As you now ran your first BlenderProc script, your ready to learn the basics:
Expand Down
5 changes: 5 additions & 0 deletions README_BlenderProc4BOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ The cameras are positioned to cover the distribution of the ground-truth object
* [bop_object_pose_sampling](examples/datasets/bop_object_pose_sampling): Loads BOP objects and samples the camera, light poses and object poses in a free space.


## Results

Results of the BOP Challenge 2020 and the superiority of training with BlenderProc images over ordinary OpenGL images is shown in our paper `BOP Challenge 2020 on 6D Object Localization` [5].

## References

[1] Hodaň, Michel et al.: [BOP: Benchmark for 6D Object Pose Estimation](http://cmp.felk.cvut.cz/~hodanto2/data/hodan2018bop.pdf), ECCV 2018.
[2] Hodaň et al.: [Photorealistic Image Synthesis for Object Instance Detection](https://arxiv.org/abs/1902.03334), ICIP 2019.
[3] Denninger, Sundermeyer et al.: [BlenderProc](https://arxiv.org/pdf/1911.01911.pdf), arXiv 2019.
[4] Pitteri, Ramamonjisoa et al.: [On Object Symmetries and 6D Pose Estimation from Images](https://arxiv.org/abs/1908.07640), CVPR 2020.
[5] Hodan, Sundermeyer et al.: [BOP Challenge 2020 on 6D Object Localization](https://arxiv.org/pdf/2009.07378.pdf), ECCVW2020
12 changes: 6 additions & 6 deletions blenderproc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ Config file:
"config": {
"global": {
"output_dir": "/tmp/",
"auto_tile_size": False
"max_bounces": False
}
}
},
{
"module": "renderer.NewRenderer",
"config": {
"auto_tile_size": True,
"max_bounces": True,
"cycles": {
"samples": 255
"value": 255
}
}
}
Expand All @@ -87,7 +87,7 @@ Config file:
Inside the `renderer.NewRenderer` module:

```python
self.get_int("cycles/samples", 42)
self.get_int("cycles/value", 42)
# -> 255

self.get_float("pixel_aspect_x")
Expand All @@ -96,13 +96,13 @@ self.get_float("pixel_aspect_x")
self.get_string("output_dir", "output/")
# -> /tmp/ this value is drawn from the GlobalStorage

self.get_bool("auto_tile_size")
self.get_bool("max_bounces")
# -> True

self.config.get_int("resolution_x", 512)
# -> 512

self.config.get_int("tile_x")
self.config.get_int("example_value")
# -> throws an error
```

Expand Down
2 changes: 1 addition & 1 deletion blenderproc/api/loader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from blenderproc.python.loader.AMASSLoader import load_AMASS
from blenderproc.python.loader.BlendLoader import load_blend
from blenderproc.python.loader.BopLoader import load_bop
from blenderproc.python.loader.BopLoader import load_bop_objs, load_bop_scene, load_bop_intrinsics
from blenderproc.python.loader.CCMaterialLoader import load_ccmaterials
from blenderproc.python.loader.Front3DLoader import load_front3d
from blenderproc.python.loader.HavenMaterialLoader import load_haven_mat
Expand Down
6 changes: 3 additions & 3 deletions blenderproc/api/renderer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from blenderproc.python.renderer.RendererUtility import set_denoiser, set_light_bounces, toggle_auto_tile_size, \
set_tile_size, set_cpu_threads, toggle_stereo, set_simplify_subdivision_render, set_adaptive_sampling, \
set_samples, enable_distance_output, enable_depth_output, enable_normals_output, enable_diffuse_color_output,\
from blenderproc.python.renderer.RendererUtility import set_denoiser, set_light_bounces, \
set_cpu_threads, toggle_stereo, set_simplify_subdivision_render, set_noise_threshold, \
set_max_amount_of_samples, enable_distance_output, enable_depth_output, enable_normals_output, enable_diffuse_color_output,\
map_file_format_to_file_ending, render, set_output_format, enable_motion_blur, set_world_background
from blenderproc.python.renderer.SegMapRendererUtility import render_segmap
from blenderproc.python.renderer.FlowRendererUtility import render_optical_flow
Expand Down
3 changes: 2 additions & 1 deletion blenderproc/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def cli():
format_dict = lambda d : '\n'.join("{}: {}".format(key, value) for key, value in d.items())
parser_pip.add_argument('pip_mode', choices=options['pip'], help=format_dict(options['pip']))
parser_pip.add_argument('pip_packages', metavar='pip_packages', nargs='*', help='A list of pip packages that should be installed/uninstalled. Packages versions can be determined via the `==` notation.')
parser_pip.add_argument('--not-use-custom-package-path', dest='not_use_custom_package_path', action='store_true', help='If set, the pip packages will not be installed into the separate custom package folder, but into blenders python site-packages folder. This should only be used, if a specific pip package cannot be installed into a custom package path.')

# Setup all common arguments of run and debug mode
for subparser in [parser_run, parser_debug]:
Expand Down Expand Up @@ -177,7 +178,7 @@ def handle_sigterm(signum, frame):
blender_path = os.path.dirname(blender_bin)

if args.pip_mode == "install":
SetupUtility.setup_pip(user_required_packages=args.pip_packages, blender_path=blender_path, major_version=major_version)
SetupUtility.setup_pip(user_required_packages=args.pip_packages, blender_path=blender_path, major_version=major_version, use_custom_package_path=not args.not_use_custom_package_path, install_default_packages=False)
elif args.pip_mode == "uninstall":
SetupUtility.uninstall_pip_packages(args.pip_packages, blender_path=blender_path, major_version=major_version)
else:
Expand Down
8 changes: 6 additions & 2 deletions blenderproc/debug_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
text.filepath = str(Path(__file__).with_name("debug_temp.py").absolute())
else:
# Just load python script into blender text object
text = bpy.data.texts.load(argv[0])
text = bpy.data.texts.load(os.path.abspath(argv[0]))


# Declare operator that runs the blender proc script
Expand All @@ -51,7 +51,11 @@ def execute(self, context):
sys.path.append(import_path)

# Run the script
bpy.ops.text.run_script()
try:
bpy.ops.text.run_script()
except RuntimeError:
# Skip irrelevant error messages (The relevant stacktrace+error has already been printed at this point)
pass
return {"FINISHED"}

bpy.utils.register_class(RunBlenderProcOperator)
Expand Down
8 changes: 3 additions & 5 deletions blenderproc/python/lighting/SuncgLighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def _make_lamp_emissive(obj: MeshObject, light: Tuple[List[str], List[str]],
# If the material corresponds to a lampshade
emission_strength = lampshade_emission_strength

m.make_emissive(emission_strength, keep_using_base_color=False,
emission_color=m.blender_obj.diffuse_color)
m.make_emissive(emission_strength, emission_color=m.blender_obj.diffuse_color)
collection_of_mats["lamp"][old_mat_name] = m

@staticmethod
Expand Down Expand Up @@ -119,7 +118,7 @@ def _make_window_emissive(obj: MeshObject, collection_of_mats: Dict[str, Dict[st
transparent_node = m.new_node('ShaderNodeBsdfDiffuse')
transparent_node.inputs['Color'].default_value[:3] = (0.285, 0.5, 0.48)

m.make_emissive(emission_strength=10, keep_using_base_color=False, emission_color=[1, 1, 1, 1],
m.make_emissive(emission_strength=10, emission_color=[1, 1, 1, 1],
non_emissive_color_socket=transparent_node.outputs['BSDF'])

collection_of_mats["window"][mat_name] = m
Expand Down Expand Up @@ -149,6 +148,5 @@ def _make_ceiling_emissive(obj: MeshObject, collection_of_mats: Dict[str, Dict[s
m.set_name(m.get_name() + "_emission")

if not m.get_nodes_with_type("Emission") and m.get_nodes_with_type("BsdfPrincipled"):
m.make_emissive(emission_strength=ceiling_emission_strength, emission_color=[1, 1, 1, 1],
keep_using_base_color=False)
m.make_emissive(emission_strength=ceiling_emission_strength, emission_color=[1, 1, 1, 1])
collection_of_mats["ceiling"][mat_name] = m
9 changes: 3 additions & 6 deletions blenderproc/python/lighting/SurfaceLighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from blenderproc.python.types.MeshObjectUtility import MeshObject


def light_surface(objects: List[MeshObject], emission_strength: float = 10.0,
keep_using_base_color: bool = False, emission_color: list = None):
def light_surface(objects: List[MeshObject], emission_strength: float = 10.0, emission_color: list = None):
""" Add emission shader to the materials of the given objects.
:param objects: A list of mesh objects whose materials should emit light.
:param emission_strength: The strength of the emitted light.
:param keep_using_base_color: If True, the base color of the material will be used as emission color.
:param emission_color: The color of the light to emit. Is ignored if keep_using_base_color is set to True.
:param emission_color: The color of the light to emit. Default: Color of the surface.
"""
empty_material = None

Expand Down Expand Up @@ -39,8 +37,7 @@ def light_surface(objects: List[MeshObject], emission_strength: float = 10.0,
# add a custom property to later identify these materials
material.set_cp("is_lamp", True)

material.make_emissive(emission_strength=emission_strength, emission_color=emission_color,
keep_using_base_color=keep_using_base_color)
material.make_emissive(emission_strength=emission_strength, emission_color=emission_color)



Expand Down
Loading

0 comments on commit b9e751a

Please sign in to comment.