예제 #1
0
def set_animation(scene: bpy.types.Scene,
                  fps: int = 24,
                  frame_start: int = 1,
                  frame_end: int = 48,
                  frame_current: int = 1) -> None:
    scene.render.fps = fps
    scene.frame_start = frame_start
    scene.frame_end = frame_end
    scene.frame_current = frame_current
예제 #2
0
    def init_scene(scene: bpy.types.Scene) -> None:
        """Initialize the given scene with default values.

        Arguments:
            scene {scene} -- current scene
        """
        logger.info("Initializing scene: %s", scene.name)

        scene.render.engine = 'CYCLES'  # switch to path tracing render engine
        scene.unit_settings.system = 'METRIC'  # switch to metric units

        # --- Render option
        if bpy.context.preferences.addons[
                'cycles'].preferences.compute_device_type is not None:
            # CUDA or OpenCL
            scene.cycles.device = 'GPU'
        else:
            # CPU only
            scene.cycles.device = 'CPU'
        # images size and aspect ratio
        scene.render.pixel_aspect_x = 1.0
        scene.render.pixel_aspect_y = 1.0
        scene.render.resolution_x = 1920  # width
        scene.render.resolution_y = 1080  # height
        scene.render.resolution_percentage = 100  # rendering scale
        scene.render.use_border = False
        scene.render.use_crop_to_border = False
        # images metadata
        scene.render.use_stamp_time = True
        scene.render.use_stamp_date = True
        scene.render.use_stamp_render_time = True
        scene.render.use_stamp_frame = True
        scene.render.use_stamp_scene = True
        scene.render.use_stamp_memory = True
        scene.render.use_stamp_camera = True
        scene.render.use_stamp_lens = True
        scene.render.use_stamp_filename = True
        # image format
        scene.render.image_settings.color_mode = 'RGB'
        scene.render.image_settings.file_format = 'JPEG'
        scene.render.use_file_extension = True
        scene.render.use_overwrite = True  # force overwrite, be careful!
        scene.render.image_settings.quality = 90  # image compression
        # post processing
        scene.render.use_compositing = True
        scene.render.use_sequencer = False
        # sampling
        scene.cycles.progressive = 'BRANCHED_PATH'
        scene.cycles.seed = 0
        scene.cycles.sample_clamp_direct = 0
        scene.cycles.sample_clamp_indirect = 0
        scene.cycles.light_sampling_threshold = 0.01
        scene.cycles.aa_samples = 32
        scene.cycles.preview_aa_samples = 4
        scene.cycles.sample_all_lights_direct = True
        scene.cycles.sample_all_lights_indirect = True
        scene.cycles.diffuse_samples = 3
        scene.cycles.glossy_samples = 2
        scene.cycles.transmission_samples = 2
        scene.cycles.ao_samples = 1
        scene.cycles.mesh_light_samples = 2
        scene.cycles.subsurface_samples = 2
        scene.cycles.volume_samples = 2
        scene.cycles.sampling_pattern = 'SOBOL'
        scene.cycles.use_layer_samples = 'USE'
        # light paths
        scene.cycles.transparent_max_bounces = 8
        scene.cycles.transparent_min_bounces = 8
        scene.cycles.use_transparent_shadows = True
        scene.cycles.max_bounces = 8
        scene.cycles.min_bounces = 3
        scene.cycles.diffuse_bounces = 2
        scene.cycles.glossy_bounces = 4
        scene.cycles.transmission_bounces = 8
        scene.cycles.volume_bounces = 2
        scene.cycles.caustics_reflective = False
        scene.cycles.caustics_refractive = False
        scene.cycles.blur_glossy = 0.00
        # performances
        scene.render.threads_mode = 'AUTO'
        scene.cycles.debug_bvh_type = 'DYNAMIC_BVH'
        scene.cycles.preview_start_resolution = 64
        scene.cycles.tile_order = 'HILBERT_SPIRAL'
        scene.render.tile_x = 64
        scene.render.tile_y = 64
        scene.cycles.use_progressive_refine = False
        scene.render.use_save_buffers = False
        scene.render.use_persistent_data = False
        scene.cycles.debug_use_spatial_splits = False
        scene.cycles.debug_use_hair_bvh = True
        scene.cycles.debug_bvh_time_steps = 0

        # -- Color Management
        scene.view_settings.view_transform = "Standard"

        # -- Animation options
        scene.frame_start = 1
        scene.frame_end = 1
        scene.frame_step = 1
        scene.frame_current = 1

        # -- World options
        world = scene.world
        if world is None:
            world = bpy.data.worlds.new("World")
            world.use_sky_paper = True
            scene.world = world
        # noise reduction
        world.cycles.sample_as_light = True
        world.cycles.sample_map_resolution = 2048
        world.cycles.samples = 1
        world.cycles.max_bounces = 1024
        world.cycles.volume_sampling = 'EQUIANGULAR'
        world.cycles.volume_interpolation = 'LINEAR'
        world.cycles.homogeneous_volume = False

        logger.info("Scene initialized")