(arg)
| 415 | |
| 416 | |
| 417 | def main(arg): |
| 418 | if arg.object.endswith(".blend"): |
| 419 | delete_invisible_objects() |
| 420 | else: |
| 421 | init_scene() |
| 422 | load_object(arg.object) |
| 423 | print('[INFO] Scene initialized.') |
| 424 | |
| 425 | # normalize scene |
| 426 | scale, offset = normalize_scene() |
| 427 | print('[INFO] Scene normalized.') |
| 428 | |
| 429 | # Initialize camera and lighting |
| 430 | cam = init_camera() |
| 431 | init_uniform_lighting() |
| 432 | print('[INFO] Camera and lighting initialized.') |
| 433 | |
| 434 | # ============= Render conditional views ============= |
| 435 | init_render(engine=arg.engine, resolution=arg.cond_resolution) |
| 436 | # Create a list of views |
| 437 | to_export = { |
| 438 | "aabb": [[-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]], |
| 439 | "scale": scale, |
| 440 | "offset": [offset.x, offset.y, offset.z], |
| 441 | "frames": [] |
| 442 | } |
| 443 | views = json.loads(arg.cond_views) |
| 444 | |
| 445 | # Parameters for boundary check and radius adjustment |
| 446 | max_retry = 10 # Maximum number of retries per view |
| 447 | radius_increase_factor = 1.1 # Increase radius by 10% when too close to boundary |
| 448 | radius_decrease_factor = 0.9 # Decrease radius by 10% when too far from boundary |
| 449 | min_boundary_distance = 130 # Minimum distance to boundary in pixels |
| 450 | |
| 451 | for i, view in enumerate(views): |
| 452 | current_radius = view['radius'] |
| 453 | retry_count = 0 |
| 454 | |
| 455 | while retry_count < max_retry: |
| 456 | cam_dir = np.array([ |
| 457 | np.cos(view['yaw']) * np.cos(view['pitch']), |
| 458 | np.sin(view['yaw']) * np.cos(view['pitch']), |
| 459 | np.sin(view['pitch']) |
| 460 | ]) |
| 461 | init_random_lighting(cam_dir) |
| 462 | cam.location = ( |
| 463 | current_radius * cam_dir[0], |
| 464 | current_radius * cam_dir[1], |
| 465 | current_radius * cam_dir[2] |
| 466 | ) |
| 467 | cam.data.lens = 16 / np.tan(view['fov'] / 2) |
| 468 | |
| 469 | output_path = os.path.join(arg.cond_output_folder, f'{i:03d}.png') |
| 470 | bpy.context.scene.render.filepath = output_path |
| 471 | |
| 472 | # Render the scene |
| 473 | bpy.ops.render.render(write_still=True) |
| 474 | bpy.context.view_layer.update() |
no test coverage detected