Loads a model with a supported file extension into the scene. Args: object_path (str): Path to the model file. Raises: ValueError: If the file extension is not supported. Returns: None
(object_path: str)
| 182 | |
| 183 | |
| 184 | def load_object(object_path: str) -> None: |
| 185 | """Loads a model with a supported file extension into the scene. |
| 186 | |
| 187 | Args: |
| 188 | object_path (str): Path to the model file. |
| 189 | |
| 190 | Raises: |
| 191 | ValueError: If the file extension is not supported. |
| 192 | |
| 193 | Returns: |
| 194 | None |
| 195 | """ |
| 196 | file_extension = object_path.split(".")[-1].lower() |
| 197 | if file_extension is None: |
| 198 | raise ValueError(f"Unsupported file type: {object_path}") |
| 199 | |
| 200 | if file_extension == "usdz": |
| 201 | # install usdz io package |
| 202 | dirname = os.path.dirname(os.path.realpath(__file__)) |
| 203 | usdz_package = os.path.join(dirname, "io_scene_usdz.zip") |
| 204 | bpy.ops.preferences.addon_install(filepath=usdz_package) |
| 205 | # enable it |
| 206 | addon_name = "io_scene_usdz" |
| 207 | bpy.ops.preferences.addon_enable(module=addon_name) |
| 208 | # import the usdz |
| 209 | from io_scene_usdz.import_usdz import import_usdz |
| 210 | |
| 211 | import_usdz(context, filepath=object_path, materials=True, animations=True) |
| 212 | return None |
| 213 | |
| 214 | # load from existing import functions |
| 215 | import_function = IMPORT_FUNCTIONS[file_extension] |
| 216 | |
| 217 | print(f"Loading object from {object_path}") |
| 218 | if file_extension == "blend": |
| 219 | import_function(directory=object_path, link=False) |
| 220 | elif file_extension in {"glb", "gltf"}: |
| 221 | import_function(filepath=object_path, merge_vertices=True, import_shading='NORMALS') |
| 222 | else: |
| 223 | import_function(filepath=object_path) |
| 224 | |
| 225 | |
| 226 | def delete_invisible_objects() -> None: |