|
@@ -580,6 +580,14 @@ def set_cryptomatte_objects(collection_name, node_name):
|
|
|
# -------------------------------------------------------------------
|
|
|
# Utilities
|
|
|
# -------------------------------------------------------------------
|
|
|
+def get_all_objects_in_collection(collection):
|
|
|
+ """Recursively get all objects in the given collection and its subcollections."""
|
|
|
+ objects = []
|
|
|
+ for obj in collection.objects:
|
|
|
+ objects.append(obj)
|
|
|
+ for subcollection in collection.children:
|
|
|
+ objects.extend(get_all_objects_in_collection(subcollection))
|
|
|
+ return objects
|
|
|
|
|
|
|
|
|
def remove_collection_and_objects(collection_name):
|
|
@@ -867,60 +875,60 @@ def export_scene_to_glb(self):
|
|
|
bpy.ops.object.select_all(action="DESELECT")
|
|
|
|
|
|
# Select all objects in the NonConfigurable collection and its subcollections
|
|
|
- collection_name = "WebGL"
|
|
|
- if collection_name in bpy.data.collections:
|
|
|
- collection = bpy.data.collections[collection_name]
|
|
|
- select_objects_in_collection(collection)
|
|
|
+ collection_name = "Web"
|
|
|
+ for collection in bpy.data.collections:
|
|
|
+ if collection_name == collection.name:
|
|
|
+ select_objects_in_collection(collection)
|
|
|
+ if not check_if_selected_objects_have_parent(self):
|
|
|
+ return
|
|
|
+ # check if all objects selected have a parent, if not return
|
|
|
+ if not add_rig_controller_to_selection(self):
|
|
|
+ return
|
|
|
+
|
|
|
+ # # for each selected objects, check if the the material is principled, if not return
|
|
|
+ # for obj in bpy.context.selected_objects:
|
|
|
+ # if not check_if_object_has_principled_material(obj):
|
|
|
+ # message = f"Object {obj.name} has no principled material"
|
|
|
+ # self.report({"ERROR"}, message)
|
|
|
+ # return
|
|
|
+
|
|
|
+ # Export selected objects to GLB
|
|
|
+ bpy.ops.export_scene.gltf(
|
|
|
+ filepath=glb_export_path,
|
|
|
+ export_format="GLB",
|
|
|
+ use_selection=True,
|
|
|
+ export_apply=True,
|
|
|
+ export_animations=False,
|
|
|
+ export_yup=True,
|
|
|
+ export_cameras=False,
|
|
|
+ export_lights=False,
|
|
|
+ export_materials="EXPORT",
|
|
|
+ export_normals=True,
|
|
|
+ export_tangents=True,
|
|
|
+ export_morph=False,
|
|
|
+ export_skins=False,
|
|
|
+ export_draco_mesh_compression_enable=False,
|
|
|
+ export_draco_mesh_compression_level=6,
|
|
|
+ export_draco_position_quantization=14,
|
|
|
+ export_draco_normal_quantization=10,
|
|
|
+ export_draco_texcoord_quantization=12,
|
|
|
+ export_draco_color_quantization=10,
|
|
|
+ export_draco_generic_quantization=12,
|
|
|
+ export_keep_originals=False,
|
|
|
+ export_texture_dir="",
|
|
|
+ )
|
|
|
+
|
|
|
+ print(f"Exported to {glb_export_path}")
|
|
|
+
|
|
|
else:
|
|
|
print(f"Collection '{collection_name}' not found.")
|
|
|
return
|
|
|
|
|
|
- if not check_if_selected_objects_have_parent(self):
|
|
|
- return
|
|
|
- # check if all objects selected have a parent, if not return
|
|
|
- if not add_rig_controller_to_selection(self):
|
|
|
- return
|
|
|
-
|
|
|
- # # for each selected objects, check if the the material is principled, if not return
|
|
|
- # for obj in bpy.context.selected_objects:
|
|
|
- # if not check_if_object_has_principled_material(obj):
|
|
|
- # message = f"Object {obj.name} has no principled material"
|
|
|
- # self.report({"ERROR"}, message)
|
|
|
- # return
|
|
|
-
|
|
|
- # Export selected objects to GLB
|
|
|
- bpy.ops.export_scene.gltf(
|
|
|
- filepath=glb_export_path,
|
|
|
- export_format="GLB",
|
|
|
- use_selection=True,
|
|
|
- export_apply=True,
|
|
|
- export_animations=False,
|
|
|
- export_yup=True,
|
|
|
- export_cameras=False,
|
|
|
- export_lights=False,
|
|
|
- export_materials="EXPORT",
|
|
|
- export_normals=True,
|
|
|
- export_tangents=True,
|
|
|
- export_morph=False,
|
|
|
- export_skins=False,
|
|
|
- export_draco_mesh_compression_enable=False,
|
|
|
- export_draco_mesh_compression_level=6,
|
|
|
- export_draco_position_quantization=14,
|
|
|
- export_draco_normal_quantization=10,
|
|
|
- export_draco_texcoord_quantization=12,
|
|
|
- export_draco_color_quantization=10,
|
|
|
- export_draco_generic_quantization=12,
|
|
|
- export_keep_originals=False,
|
|
|
- export_texture_dir="",
|
|
|
- )
|
|
|
-
|
|
|
- print(f"Exported to {glb_export_path}")
|
|
|
-
|
|
|
|
|
|
def copy_and_relink_textures(collection_name):
|
|
|
# Ensure the target directory exists
|
|
|
target_directory = bpy.path.abspath("//..")
|
|
|
- textures_directory = os.path.join(target_directory, "0_Textures")
|
|
|
+ textures_directory = os.path.join(target_directory, "01_Textures")
|
|
|
os.makedirs(textures_directory, exist_ok=True)
|
|
|
|
|
|
# Get the collection
|
|
@@ -930,7 +938,8 @@ def copy_and_relink_textures(collection_name):
|
|
|
return
|
|
|
|
|
|
# Iterate through each object in the collection
|
|
|
- for obj in collection.objects:
|
|
|
+ objects = get_all_objects_in_collection(collection)
|
|
|
+ for obj in objects:
|
|
|
if obj.type != "MESH":
|
|
|
continue
|
|
|
|
|
@@ -956,6 +965,9 @@ def copy_and_relink_textures(collection_name):
|
|
|
# Check if the file already exists in the destination directory
|
|
|
if not os.path.exists(dest_path):
|
|
|
shutil.copy(src_path, dest_path)
|
|
|
+ print(
|
|
|
+ f"File '{filename}' copied to '{textures_directory}'"
|
|
|
+ )
|
|
|
else:
|
|
|
print(
|
|
|
f"File '{filename}' already exists in '{textures_directory}', relinking."
|
|
@@ -1040,7 +1052,7 @@ class ZSSD_OT_ExportAssets(bpy.types.Operator):
|
|
|
|
|
|
def execute(self, context):
|
|
|
copy_and_relink_textures("NonConfigurable")
|
|
|
- copy_and_relink_textures("WebGL")
|
|
|
+ copy_and_relink_textures("Web")
|
|
|
set_assets_render_output_paths()
|
|
|
export_scene_to_fbx(self)
|
|
|
export_scene_to_glb(self)
|