Skip to content
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

Script and tutorial for generating procedural datasets with Blender #1412

Merged
merged 30 commits into from
Oct 21, 2022
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8fb5f17
Add script for creation of procedural datasets with Blender
AndrejOrsula Mar 25, 2022
800eda6
Add tutorial for creation of procedural datasets with Blender
AndrejOrsula Mar 25, 2022
a54be30
Add Future Work section for procedural datasets with Blender
AndrejOrsula Apr 7, 2022
61b6689
Use absolute links in tutorial for prodedural datasets with Blender
AndrejOrsula Apr 7, 2022
e54a450
Improve phrasing in tutorial for procedural datasets with Blender
AndrejOrsula Apr 7, 2022
adec670
Fix error in case an object has no modifiers
AndrejOrsula Apr 7, 2022
cc210d1
Indicate in main() how to export a single model
AndrejOrsula Apr 7, 2022
f9f2133
Place all default parameters at the beginning of script
AndrejOrsula May 23, 2022
c2b6de2
Enable ignore of some objects during export of visual/collision mesh
AndrejOrsula May 23, 2022
08800a5
Add support for simple generation of thumbnails
AndrejOrsula May 23, 2022
9a2ca45
Add Wavefront (.obj) exporter
AndrejOrsula May 23, 2022
3dbc7c2
Add option to specify kwargs
AndrejOrsula May 23, 2022
b565c50
Update script in the example blend file
AndrejOrsula May 23, 2022
a2574f6
Remove finished items from Future Work
AndrejOrsula May 23, 2022
8930433
Fix forward axis for Wavefront (.obj) exporter
AndrejOrsula May 24, 2022
630ae54
Bump LAST_TESTED_VERSION to Blender 3.1.2
AndrejOrsula May 25, 2022
c0c5b81
Set default export directory relative to .blend file
AndrejOrsula May 25, 2022
b8c9498
Support headless generation of datasets
AndrejOrsula May 25, 2022
7abb656
Merge branch 'ign-gazebo6' into blender_procedural_datasets
mabelzhang Jul 14, 2022
e92554e
Apply suggestions from code review
AndrejOrsula Aug 27, 2022
2ab07d4
Add parsing of CLI args and simplify usage
AndrejOrsula Aug 27, 2022
2780dd2
Print cmd to set GZ_SIM_RESOURCE_PATH after the export is finished
AndrejOrsula Aug 27, 2022
d7ebd3a
Default to Wavefront (.obj) file format for visual geometry
AndrejOrsula Aug 28, 2022
dd9480c
Update rock.blend project
AndrejOrsula Aug 29, 2022
5076d9c
Add garden.blend project
AndrejOrsula Aug 29, 2022
bd6b89d
Make script executable
AndrejOrsula Aug 29, 2022
f33a54b
Update tutorial
AndrejOrsula Aug 29, 2022
1ca8e55
Rename `garden.blend` to `woodland.blend`
AndrejOrsula Aug 30, 2022
6c81587
Add attribution for assets used in `woodland.blend`
AndrejOrsula Aug 30, 2022
26686cf
Merge remote-tracking branch 'origin/ign-gazebo6' into blender_proced…
mjcarroll Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Default to Wavefront (.obj) file format for visual geometry
Signed-off-by: Andrej Orsula <orsula.andrej@gmail.com>
  • Loading branch information
AndrejOrsula committed Oct 10, 2022
commit d7ebd3a0f0ab701a40c5a01c5970a41d2de0a44d
112 changes: 55 additions & 57 deletions examples/scripts/blender/procedural_dataset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
$ blender [blender options] file.blend --python external_script.py -- [script options]

Show the help message of this script ([script options]):
$ blender file.blend --python-text script.py -- -h
$ blender file.blend --python external_script.py -- -h
$ blender -b file.blend --python-text script.py -- -h
$ blender -b file.blend --python external_script.py -- -h

Show the help message of Blender ([blender options]):
$ blender -h
Expand Down Expand Up @@ -75,7 +75,7 @@
IGNORE_OBJECTS_COLLISION: List[str] = []
## Default source of textures for the model
# Options: "collada" == "dae" | "wavefront" == "obj" | "stl"
FILETYPE_VISUAL: str = "collada"
FILETYPE_VISUAL: str = "wavefront"
FILETYPE_COLLISION: str = "stl"
## Default source of textures for the model
# If true, symbolic links will be created for all textures instead of copies
Expand Down Expand Up @@ -169,6 +169,7 @@ def export(self, filepath: str) -> str:
filter_collada=True,
filter_alembic=False,
filter_usd=False,
filter_obj=False,
filter_volume=False,
filter_folder=True,
filter_blenlib=False,
Expand Down Expand Up @@ -211,52 +212,39 @@ def export(self, filepath: str) -> str:
elif self.STL == self:
bpy.ops.export_mesh.stl(
filepath=filepath,
check_existing=False,
use_selection=True,
axis_forward="Y",
axis_up="Z",
global_scale=1,
use_scene_unit=False,
ascii=False,
use_mesh_modifiers=True,
)
elif self.WAVEFRONT == self:
bpy.ops.wm.obj_export(
bpy.ops.export_scene.obj(
filepath=filepath,
check_existing=False,
filter_blender=False,
filter_backup=False,
filter_image=False,
filter_movie=False,
filter_python=False,
filter_font=False,
filter_sound=False,
filter_text=False,
filter_archive=False,
filter_btx=False,
filter_collada=False,
filter_alembic=False,
filter_usd=False,
filter_obj=True,
filter_volume=False,
filter_folder=True,
filter_blenlib=False,
filemode=8,
display_type="DEFAULT",
sort_method="DEFAULT",
export_animation=False,
start_frame=-2147483648,
end_frame=2147483647,
forward_axis="Y_FORWARD",
up_axis="Z_UP",
scaling_factor=1,
apply_modifiers=True,
export_eval_mode="DAG_EVAL_VIEWPORT",
export_selected_objects=False,
export_uv=True,
export_normals=True,
export_materials=True,
export_triangulated_mesh=False,
export_curves_as_nurbs=False,
export_object_groups=False,
export_material_groups=False,
export_vertex_groups=False,
export_smooth_groups=False,
smooth_group_bitflags=False,
axis_forward="Y",
axis_up="Z",
use_selection=True,
use_animation=False,
use_mesh_modifiers=True,
use_edges=True,
use_smooth_groups=False,
use_smooth_groups_bitflags=False,
use_normals=True,
use_uvs=True,
use_materials=True,
use_triangles=True,
use_nurbs=False,
use_vertex_groups=False,
use_blen_objects=True,
group_by_object=False,
group_by_material=False,
keep_vertex_order=False,
global_scale=1,
path_mode="AUTO",
)
else:
raise ValueError(f"Filetype '{self}' is not supported for export.")
Expand Down Expand Up @@ -735,11 +723,6 @@ def export(
textures_dirpath = texture_source.get_path(texture_source_value)
textures = cls._sample_textures(textures_dirpath=textures_dirpath)
sdf_data.update(textures)
else:
cls._print_bpy(
"Warn: Models will be exported without any textures.",
file=sys.stderr,
)

# Estimate inertial properties (if enabled)
if not static:
Expand Down Expand Up @@ -1509,9 +1492,14 @@ def _pre_export_geometry_collision(
for obj in selected_meshes:
for nodes_modifier in cls._get_all_nodes_modifiers(obj):
cls._try_set_nodes_input_attribute(
nodes_modifier, cls.LOOKUP_PHRASES_RANDOM_SEED, current_seed
obj,
nodes_modifier,
cls.LOOKUP_PHRASES_RANDOM_SEED,
current_seed,
print_warning=True,
)
cls._try_set_nodes_input_attribute(
obj,
nodes_modifier,
cls.LOOKUP_PHRASES_DETAIL_LEVEL,
detail_level,
Expand Down Expand Up @@ -1540,9 +1528,14 @@ def _pre_export_geometry_visual(
for obj in selected_meshes:
for nodes_modifier in cls._get_all_nodes_modifiers(obj):
cls._try_set_nodes_input_attribute(
nodes_modifier, cls.LOOKUP_PHRASES_RANDOM_SEED, current_seed
obj,
nodes_modifier,
cls.LOOKUP_PHRASES_RANDOM_SEED,
current_seed,
print_warning=True,
)
cls._try_set_nodes_input_attribute(
obj,
nodes_modifier,
cls.LOOKUP_PHRASES_DETAIL_LEVEL,
detail_level,
Expand All @@ -1560,9 +1553,11 @@ def _get_all_nodes_modifiers(obj: bpy.types.Object) -> List[bpy.types.Modifier]:
@classmethod
def _try_set_nodes_input_attribute(
cls,
obj: bpy.types.Object,
modifier: bpy.types.NodesModifier,
lookup_phrases: Iterable[str],
value: Any,
print_warning: bool = False,
):
"""
Try to set an input attribute of a nodes system to a `value`. The attribute
Expand All @@ -1576,11 +1571,14 @@ def _try_set_nodes_input_attribute(
input_id = attribute.identifier
break
if input_id is None:
cls._print_bpy(
f"Warn: Cannot match an input attribute of '{modifier.name}' for any "
f"of the requested lookup phrases {lookup_phrases}.",
file=sys.stderr,
)
if print_warning:
cls._print_bpy(
"Warn: Unable to find a matching input attribute of the object's "
f"'{obj.name}' modifier '{modifier.name}' for any of the requested "
f"lookup phrases {lookup_phrases}. You can ignore this warning if "
"the modifier is not supposed to have the requested input.",
file=sys.stderr,
)
return

# Set the attribute
Expand Down Expand Up @@ -1658,8 +1656,8 @@ def main(**kwargs):
f"\n\t{sys.argv[0]} [blender options] file.blend --python "
"external_script.py -- [script options]"
"\nlist script options:"
f"\n\t{sys.argv[0]} file.blend --python-text script.py -- -h"
f"\n\t{sys.argv[0]} file.blend --python external_script.py -- -h"
f"\n\t{sys.argv[0]} -b file.blend --python-text script.py -- -h"
f"\n\t{sys.argv[0]} -b file.blend --python external_script.py -- -h"
"\nlist blender options:"
f"\n\t{sys.argv[0]} -h"
),
Expand Down