Skip to content

Commit

Permalink
mesher_backend option rename; fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mazeyu committed Sep 14, 2024
1 parent 9565932 commit 6e5ee0e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
9 changes: 6 additions & 3 deletions docs/ConfiguringInfinigen.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ We recommend this command as a starting point for generating high quality videos
```bash
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 60000 --config trailer_video high_quality_terrain
--cleanup big_files --warmup_sec 60000 --config trailer_video high_quality_terrain \
-p fine_terrain.mesher_backend="OcMesher"
```

#### Creating large-scale stereo datasets
Expand Down Expand Up @@ -219,7 +220,8 @@ python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 30000 --config trailer_video high_quality_terrain \
--overrides camera.camera_pose_proposal.altitude=["uniform", 20, 30]
--overrides camera.camera_pose_proposal.altitude=["uniform", 20, 30] \
-p fine_terrain.mesher_backend="OcMesher"
```

:bulb: The command shown is overriding `infinigen_examples/configs_nature/base.gin`'s default setting of `camera.camera_pose_proposal.altitude`. You can use a similar syntax to override any number of .gin config entries. Separate multiple entries with spaces.
Expand All @@ -229,7 +231,8 @@ python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 30000 --config trailer_video high_quality_terrain \
--pipeline_overrides iterate_scene_tasks.frame_range=[1,25]
--pipeline_overrides iterate_scene_tasks.frame_range=[1,25] \
-p fine_terrain.mesher_backend="OcMesher"
```

:bulb: This command uses `--pipeline_overrides` rather than `--overrides` since it is providing a gin override to the `manage_jobs.py` process, not some part of the main `infinigen_examples/generate_nature.py` driver.
55 changes: 29 additions & 26 deletions infinigen/terrain/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ def cleanup(self):
for e in self.elements:
self.elements[e].cleanup()

@gin.configurable()
def export(
self,
dynamic=False,
spherical=True, # false for OcMesher
mesher_backend="SphericalMesher",
cameras=None,
main_terrain_only=False,
remove_redundant_attrs=True,
Expand All @@ -221,13 +219,14 @@ def export(
]
if opaque_elements != []:
attributes_dict[TerrainNames.OpaqueTerrain] = set()
if dynamic:
if spherical:
mesher = OpaqueSphericalMesher(cameras, self.bounds)
else:
if mesher_backend == "SphericalMesher":
mesher = OpaqueSphericalMesher(cameras, self.bounds)
elif mesher_backend == "OcMesher":
mesher = OcMesher(cameras, self.bounds)
else:
elif mesher_backend == "UniformMesher":
mesher = UniformMesher(self.populated_bounds)
else:
raise ValueError("unrecognized mesher_backend")
with Timer(f"meshing {TerrainNames.OpaqueTerrain}"):
mesh = mesher([element for element in opaque_elements])
meshes_dict[TerrainNames.OpaqueTerrain] = mesh
Expand All @@ -243,12 +242,12 @@ def export(
]
for element in individual_transparent_elements:
if not main_terrain_only or element.__class__.name == self.main_terrain:
if dynamic:
if mesher_backend in ["SphericalMesher", "OcMesher"]:
special_args = {}
if element.__class__.name == ElementNames.Atmosphere:
special_args["pixels_per_cube"] = 100
special_args["inv_scale"] = 1
if spherical:
if mesher_backend == "SphericalMesher":
mesher = TransparentSphericalMesher(
cameras, self.bounds, **special_args
)
Expand All @@ -259,8 +258,10 @@ def export(
simplify_occluded=False,
**special_args,
)
else:
elif mesher_backend == "UniformMesher":
mesher = UniformMesher(self.populated_bounds, enclosed=True)
else:
raise ValueError("unrecognized mesher_backend")
with Timer(f"meshing {element.__class__.name}"):
mesh = mesher([element])
meshes_dict[element.__class__.name] = mesh
Expand All @@ -277,15 +278,16 @@ def export(
]
if collective_transparent_elements != []:
attributes_dict[TerrainNames.CollectiveTransparentTerrain] = set()
if dynamic:
if spherical:
mesher = TransparentSphericalMesher(cameras, self.bounds)
else:
mesher = CollectiveOcMesher(
cameras, self.bounds, simplify_occluded=False
)
else:
if mesher_backend == "SphericalMesher":
mesher = TransparentSphericalMesher(cameras, self.bounds)
elif mesher_backend == "OcMesher":
mesher = CollectiveOcMesher(
cameras, self.bounds, simplify_occluded=False
)
elif mesher_backend == "UniformMesher":
mesher = UniformMesher(self.populated_bounds)
else:
raise ValueError("unrecognized mesher_backend")
with Timer(f"meshing {TerrainNames.CollectiveTransparentTerrain}"):
mesh = mesher(
[element for element in collective_transparent_elements]
Expand All @@ -296,7 +298,7 @@ def export(
element.attributes
)

if main_terrain_only or dynamic:
if main_terrain_only or cameras is not None:
for mesh_name in meshes_dict:
mesh_name_unapplied = mesh_name
if mesh_name + "_unapplied" in bpy.data.objects.keys():
Expand Down Expand Up @@ -327,7 +329,7 @@ def export(
surface.mod_name
)

if dynamic:
if cameras is not None:
if remove_redundant_attrs:
for mesh_name in meshes_dict:
if len(attributes_dict[mesh_name]) == 1:
Expand Down Expand Up @@ -404,7 +406,7 @@ def surfaces_into_sdf(self):

@gin.configurable
def coarse_terrain(self):
coarse_meshes, attributes_dict = self.export()
coarse_meshes, attributes_dict = self.export(mesher_backend="UniformMesher")
terrain_objs = {}
for name in coarse_meshes:
obj = coarse_meshes[name].export_blender(name)
Expand All @@ -416,8 +418,8 @@ def coarse_terrain(self):
self.apply_surface_templates(attributes_dict)
self.surfaces_into_sdf()

# do second time to avoid surface application difference resulting in cloating rocks
coarse_meshes, _ = self.export(main_terrain_only=True)
# do second time to avoid surface application difference resulting in floating rocks
coarse_meshes, _ = self.export(main_terrain_only=True, mesher_backend="UniformMesher")
main_mesh = coarse_meshes[self.main_terrain]

# WaterCovered annotation
Expand All @@ -444,7 +446,8 @@ def coarse_terrain(self):
self.tag_terrain(self.terrain_objs[name])
return main_obj

def fine_terrain(self, output_folder, cameras, optimize_terrain_diskusage=True):
@gin.configurable
def fine_terrain(self, output_folder, cameras, optimize_terrain_diskusage=True, mesher_backend="SphericalMesher"):
# redo sampling to achieve attribute -> surface correspondance
self.sample_surface_templates()
if (self.on_the_fly_asset_folder / Assets.Ocean).exists():
Expand All @@ -456,7 +459,7 @@ def fine_terrain(self, output_folder, cameras, optimize_terrain_diskusage=True):
link_folder=self.on_the_fly_asset_folder / Assets.Ocean,
)
self.surfaces_into_sdf()
fine_meshes, _ = self.export(dynamic=True, cameras=cameras)
fine_meshes, _ = self.export(mesher_backend=mesher_backend, cameras=cameras)
for mesh_name in fine_meshes:
obj = fine_meshes[mesh_name].export_blender(mesh_name + "_fine")
if mesh_name not in hidden_in_viewport:
Expand Down
2 changes: 1 addition & 1 deletion infinigen/terrain/mesher/spherical_mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
cams = full_info[0]
assert (
self.fov[0] < np.pi / 2 and self.fov[1] < np.pi / 2
), "the algorithm does not support larger-than-90-degree fov yet"
), "`mesher_backend=SphericalMesher` does not support larger-than-90-degree fov yet. Please add `fine_terrain.mesher_backend = \"OcMesher\"` to your gin config."
self.r_min = r_min
self.complete_depth_test = complete_depth_test
self.bounds = bounds
Expand Down
2 changes: 1 addition & 1 deletion infinigen_examples/configs_indoor/base_indoors.gin
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ animate_cameras.follow_poi_chance=0.0
camera.camera_pose_proposal.altitude = ("clip_gaussian", 1.5, 0.8, 0.5, 2.2)
camera.camera_pose_proposal.pitch = ("clip_gaussian", 90, 15, 60, 95)
camera.camera_pose_proposal.focal_length = 15
export.spherical = False # spherical mesher doesnt support short focal length / wide fov
fine_terrain.mesher_backend = "OcMesher" # spherical mesher doesnt support short focal length / wide fov

camera.spawn_camera_rigs.n_camera_rigs = 1
camera.spawn_camera_rigs.camera_rig_config = [
Expand Down
2 changes: 1 addition & 1 deletion infinigen_examples/configs_nature/noisy_video.gin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export.spherical = False # use OcMesher
fine_terrain.mesher_backend = "OcMesher"
AnimPolicyRandomWalkLookaround.speed = ("uniform", 3, 10)
AnimPolicyRandomWalkLookaround.yaw_sampler = ("uniform", -50, 50)
AnimPolicyRandomWalkLookaround.step_range = ('clip_gaussian', 1, 3, 0.6, 5)
2 changes: 1 addition & 1 deletion infinigen_examples/configs_nature/trailer_video.gin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export.spherical = False # use OcMesher
fine_terrain.mesher_backend = "OcMesher"
AnimPolicyRandomWalkLookaround.speed = ('uniform', 0.5, 1)
AnimPolicyRandomWalkLookaround.step_speed_mult = 1
AnimPolicyRandomWalkLookaround.yaw_sampler = ('uniform',-20, 20)
Expand Down

0 comments on commit 6e5ee0e

Please sign in to comment.