Skip to content

Commit

Permalink
Merge pull request princeton-vl#290 from princeton-vl/export_patch
Browse files Browse the repository at this point in the history
Fix empty scenes during export
  • Loading branch information
pvl-bot authored Oct 8, 2024
2 parents 3877fbd + 2899e97 commit 4555520
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions infinigen/tools/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import bpy
import gin

from infinigen.core.util import blender as butil

FORMAT_CHOICES = ["fbx", "obj", "usdc", "usda", "stl", "ply"]
BAKE_TYPES = {
"DIFFUSE": "Base Color",
Expand Down Expand Up @@ -104,6 +106,8 @@ def handle_geo_modifiers(obj, export_usd):
def split_glass_mats():
split_objs = []
for obj in bpy.data.objects:
if obj.hide_render or obj.hide_viewport:
continue
if any(
exclude in obj.name
for exclude in ["BowlFactory", "CupFactory", "OvenFactory", "BottleFactory"]
Expand Down Expand Up @@ -251,6 +255,7 @@ def update_visibility():
obj_view[obj] = obj.hide_render
obj.hide_viewport = True
obj.hide_render = True
obj.hide_set(0)

return collection_view, obj_view

Expand Down Expand Up @@ -647,28 +652,23 @@ def bake_object(obj, dest, img_size, export_usd):
return

bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)

for slot in obj.material_slots:
mat = slot.material
if mat is not None:
slot.material = (
mat.copy()
) # we duplicate in the case of distinct meshes sharing materials

process_glass_materials(obj, export_usd)

bake_metal(obj, dest, img_size, export_usd)
bake_normals(obj, dest, img_size, export_usd)

paramDict = process_interfering_params(obj)

for bake_type in BAKE_TYPES:
bake_pass(obj, dest, img_size, bake_type, export_usd)
with butil.SelectObjects(obj):
for slot in obj.material_slots:
mat = slot.material
if mat is not None:
slot.material = (
mat.copy()
) # we duplicate in the case of distinct meshes sharing materials

apply_baked_tex(obj, paramDict)
process_glass_materials(obj, export_usd)
bake_metal(obj, dest, img_size, export_usd)
bake_normals(obj, dest, img_size, export_usd)
paramDict = process_interfering_params(obj)
for bake_type in BAKE_TYPES:
bake_pass(obj, dest, img_size, bake_type, export_usd)

obj.select_set(False)
apply_baked_tex(obj, paramDict)


def bake_scene(folderPath: Path, image_res, vertex_colors, export_usd):
Expand Down Expand Up @@ -989,6 +989,8 @@ def main(args):
print(f"Skipping non-blend file {blendfile}")
continue

bpy.ops.wm.open_mainfile(filepath=str(blendfile))

folder = export_scene(
blendfile,
args.output_folder,
Expand Down

0 comments on commit 4555520

Please sign in to comment.