def set_default_parameters(): """ Loads and sets default parameters defined in DefaultConfig.py """ # Set default intrinsics CameraUtility.set_intrinsics_from_blender_params( DefaultConfig.fov, DefaultConfig.resolution_x, DefaultConfig.resolution_y, DefaultConfig.clip_start, DefaultConfig.clip_end, DefaultConfig.pixel_aspect_x, DefaultConfig.pixel_aspect_y, DefaultConfig.shift_x, DefaultConfig.shift_y, DefaultConfig.lens_unit) CameraUtility.set_stereo_parameters( DefaultConfig.stereo_convergence_mode, DefaultConfig.stereo_convergence_distance, DefaultConfig.stereo_interocular_distance) # Init renderer RendererUtility._render_init() RendererUtility.set_samples(DefaultConfig.samples) addon_utils.enable("render_auto_tile_size") RendererUtility.toggle_auto_tile_size(True) # Set number of cpu cores used for rendering (1 thread is always used for coordination => 1 # cpu thread means GPU-only rendering) RendererUtility.set_cpu_threads(0) RendererUtility.set_denoiser(DefaultConfig.denoiser) RendererUtility.set_simplify_subdivision_render( DefaultConfig.simplify_subdivision_render) RendererUtility.set_light_bounces( DefaultConfig.diffuse_bounces, DefaultConfig.glossy_bounces, DefaultConfig.ao_bounces_render, DefaultConfig.max_bounces, DefaultConfig.transmission_bounces, DefaultConfig.transparency_bounces, DefaultConfig.volume_bounces) RendererUtility.set_output_format(DefaultConfig.file_format, DefaultConfig.color_depth, DefaultConfig.enable_transparency, DefaultConfig.jpg_quality)
def _set_cam_intrinsics(self, cam, config): """ Sets camera intrinsics from a source with following priority 1. from config function parameter if defined 2. from custom properties of cam if set in Loader 3. default config: resolution_x/y: 512 pixel_aspect_x: 1 clip_start: : 0.1 clip_end : 1000 fov : 0.691111 :param cam: The camera which contains only camera specific attributes. :param config: A configuration object with cam intrinsics. """ if config.is_empty(): return width = config.get_int("resolution_x", bpy.context.scene.render.resolution_x) height = config.get_int("resolution_y", bpy.context.scene.render.resolution_y) # Clipping clip_start = config.get_float("clip_start", cam.clip_start) clip_end = config.get_float("clip_end", cam.clip_end) if config.has_param("cam_K"): if config.has_param("fov"): print( 'WARNING: FOV defined in config is ignored. Mutually exclusive with cam_K' ) if config.has_param("pixel_aspect_x"): print( 'WARNING: pixel_aspect_x defined in config is ignored. Mutually exclusive with cam_K' ) cam_K = np.array(config.get_list("cam_K")).reshape(3, 3).astype( np.float32) CameraUtility.set_intrinsics_from_K_matrix(cam_K, width, height, clip_start, clip_end) else: # Set FOV fov = config.get_float("fov", cam.angle) # Set Pixel Aspect Ratio pixel_aspect_x = config.get_float( "pixel_aspect_x", bpy.context.scene.render.pixel_aspect_x) pixel_aspect_y = config.get_float( "pixel_aspect_y", bpy.context.scene.render.pixel_aspect_y) # Set camera shift shift_x = config.get_float("shift_x", cam.shift_x) shift_y = config.get_float("shift_y", cam.shift_y) CameraUtility.set_intrinsics_from_blender_params(fov, width, height, clip_start, clip_end, pixel_aspect_x, pixel_aspect_y, shift_x, shift_y, lens_unit="FOV") CameraUtility.set_stereo_parameters( config.get_string("stereo_convergence_mode", cam.stereo.convergence_mode), config.get_float("convergence_distance", cam.stereo.convergence_distance), config.get_float("interocular_distance", cam.stereo.interocular_distance)) if config.has_param("depth_of_field"): depth_of_field_config = Config( config.get_raw_dict("depth_of_field")) fstop_value = depth_of_field_config.get_float("fstop", 2.4) aperture_blades = depth_of_field_config.get_int( "aperture_blades", 0) aperture_ratio = depth_of_field_config.get_float( "aperture_ratio", 1.0) aperture_rotation = depth_of_field_config.get_float( "aperture_rotation_in_rad", 0.0) if depth_of_field_config.has_param( "depth_of_field_dist") and depth_of_field_config.has_param( "focal_object"): raise RuntimeError( "You can only use either depth_of_field_dist or a focal_object but not both!" ) if depth_of_field_config.has_param("depth_of_field_dist"): depth_of_field_dist = depth_of_field_config.get_float( "depth_of_field_dist") CameraUtility.add_depth_of_field(cam, None, fstop_value, aperture_blades, aperture_rotation, aperture_ratio, depth_of_field_dist) elif depth_of_field_config.has_param("focal_object"): focal_object = depth_of_field_config.get_list("focal_object") if len(focal_object) != 1: raise RuntimeError( f"There has to be exactly one focal object, use 'random_samples: 1' or change " f"the selector. Found {len(focal_object)}.") CameraUtility.add_depth_of_field(Entity(focal_object[0]), fstop_value, aperture_blades, aperture_rotation, aperture_ratio) else: raise RuntimeError( "The depth_of_field dict must contain either a focal_object definition or " "a depth_of_field_dist")