From 2899e97d2f426468e61aa774cfb5f458edcf95ce Mon Sep 17 00:00:00 2001 From: DavidYan-1 Date: Thu, 3 Oct 2024 22:00:49 -0400 Subject: [PATCH] Fix empty scenes during export --- infinigen/tools/export.py | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/infinigen/tools/export.py b/infinigen/tools/export.py index d865d4e0..654eb863 100644 --- a/infinigen/tools/export.py +++ b/infinigen/tools/export.py @@ -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", @@ -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"] @@ -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 @@ -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): @@ -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,