Skip to content

Commit

Permalink
Copy in terrain onthefly diskusage improvements, update infinigen_gpl…
Browse files Browse the repository at this point in the history
… to add .gitignore

Co-authored-by: Zeyu Ma <[email protected]>
  • Loading branch information
araistrick and mazeyu committed Jul 27, 2023
1 parent 0ff02d6 commit ee36d88
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
39 changes: 26 additions & 13 deletions worldgen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,36 @@ def execute_tasks(

group_collections()

if Task.Coarse in task or Task.Populate in task or Task.FineTerrain in task:
bpy.context.preferences.system.scrollback = 100
bpy.context.preferences.edit.undo_steps = 100
with Timer(f'Writing output blendfile to {output_folder / output_blend_name}'):
bpy.ops.wm.save_mainfile(filepath=str(output_folder / output_blend_name))
tag_system.save_tag(path=str(output_folder / "MaskTag.json"))

with (output_folder/ "version.txt").open('w') as f:
scene_version = get_scene_tag('VERSION')
f.write(f"{scene_version}\n")

with (output_folder/'polycounts.txt').open('w') as f:
save_polycounts(f)
if task == [Task.FineTerrain]:
os.symlink(input_folder / output_blend_name, output_folder / output_blend_name)
os.symlink(input_folder / "MaskTag.json", output_folder / "MaskTag.json")
os.symlink(input_folder / "version.txt", output_folder / "version.txt")
os.symlink(input_folder / 'polycounts.txt', output_folder / 'polycounts.txt')
else:
if input_folder is not None:
for mesh in os.listdir(input_folder):
if (mesh.endswith(".glb") or mesh.endswith(".b_displacement.npy")) and not os.path.islink(output_folder / mesh):
os.symlink(input_folder / mesh, output_folder / mesh)
if Task.Coarse in task or Task.Populate in task or Task.FineTerrain in task:
bpy.context.preferences.system.scrollback = 100
bpy.context.preferences.edit.undo_steps = 100
with Timer(f'Writing output blendfile to {output_folder / output_blend_name}'):
bpy.ops.wm.save_mainfile(filepath=str(output_folder / output_blend_name))
tag_system.save_tag(path=str(output_folder / "MaskTag.json"))

with (output_folder/ "version.txt").open('w') as f:
scene_version = get_scene_tag('VERSION')
f.write(f"{scene_version}\n")

with (output_folder/'polycounts.txt').open('w') as f:
save_polycounts(f)

for col in bpy.data.collections['unique_assets'].children:
col.hide_viewport = False

if Task.Render in task or Task.GroundTruth in task or Task.MeshSave in task:
terrain.load_glb(output_folder)

if Task.Render in task or Task.GroundTruth in task:
render(scene_seed, output_folder=output_folder, camera_id=camera_id, resample_idx=resample_idx)

Expand Down
2 changes: 1 addition & 1 deletion worldgen/infinigen_gpl
21 changes: 15 additions & 6 deletions worldgen/terrain/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,30 +251,39 @@ def coarse_terrain(self):
self.tag_terrain(self.terrain_objs[name])
return main_obj

def fine_terrain(self, fine_folder):
def fine_terrain(self, output_folder):
# redo sampling to achieve attribute -> surface correspondance
self.sample_surface_templates()
if (self.on_the_fly_asset_folder / Assets.Ocean).exists():
with FixedSeed(int_hash(["Ocean", self.seed])):
ocean_asset(fine_folder / Assets.Ocean, bpy.context.scene.frame_start, bpy.context.scene.frame_end, link_folder=self.on_the_fly_asset_folder / Assets.Ocean)
ocean_asset(output_folder / Assets.Ocean, bpy.context.scene.frame_start, bpy.context.scene.frame_end, link_folder=self.on_the_fly_asset_folder / Assets.Ocean)
self.surfaces_into_sdf()
fine_meshes, _ = self.export(spherical=True, cameras=[bpy.context.scene.camera])
for mesh_name in fine_meshes:
object_to_copy_to = fine_meshes[mesh_name].export_blender(mesh_name + "_fine")
obj = fine_meshes[mesh_name].export_blender(mesh_name + "_fine")
if mesh_name not in hidden_in_viewport: self.tag_terrain(obj)
Mesh(obj=obj).save(output_folder / f"{mesh_name}.glb")
np.save(output_folder / f"{mesh_name}.b_displacement", fine_meshes[mesh_name].blender_displacements)
delete(obj)

def load_glb(self, output_folder):
for mesh_name in os.listdir(output_folder):
if not mesh_name.endswith(".glb"): continue
mesh_name = mesh_name[:-4]
object_to_copy_to = Mesh(path=output_folder/f"{mesh_name}.glb").export_blender(mesh_name + "_fine")

object_to_copy_from = bpy.data.objects[mesh_name]
mat = object_to_copy_from.data.materials[0]
object_to_copy_to.data.materials.append(mat)
mesh_name_unapplied = mesh_name
if mesh_name + "_unapplied" in bpy.data.objects.keys():
mesh_name_unapplied = mesh_name + "_unapplied"
for mod_name in fine_meshes[mesh_name].blender_displacements:
for mod_name in np.load(output_folder / f"{mesh_name}.b_displacement.npy"):
move_modifier(object_to_copy_to, bpy.data.objects[mesh_name_unapplied].modifiers[mod_name])
object_to_copy_from.hide_render = True
object_to_copy_from.hide_viewport = True
if mesh_name in hidden_in_viewport:
object_to_copy_to.hide_viewport = True
else:
self.tag_terrain(object_to_copy_to)

def compute_camera_space_sdf(self, XYZ):
sdf = np.ones(len(XYZ), dtype=np.float32) * 1e9
Expand Down

0 comments on commit ee36d88

Please sign in to comment.