mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Make scene configuration part of the global configuration
This commit is contained in:
parent
bcc4235e2f
commit
f9fa8ac846
5 changed files with 49 additions and 26 deletions
|
@ -47,6 +47,7 @@ def get_global_config():
|
|||
update_window_config(config, args)
|
||||
update_camera_config(config, args)
|
||||
update_file_writer_config(config, args)
|
||||
update_scene_config(config, args)
|
||||
|
||||
return config
|
||||
|
||||
|
@ -287,6 +288,26 @@ def update_file_writer_config(config: dict, args: Namespace):
|
|||
file_writer_config["pixel_format"] = args.pix_fmt
|
||||
|
||||
|
||||
def update_scene_config(config: dict, args: Namespace):
|
||||
scene_config = config["scene"]
|
||||
start, end = get_animations_numbers(args)
|
||||
scene_config.update(
|
||||
# Note, Scene.__init__ makes use of both get_camera_config() and
|
||||
# get_file_writer_config() below, so the arguments here are just for
|
||||
# any future specifications beyond what the global configuration holds
|
||||
camera_config=dict(),
|
||||
file_writer_config=dict(),
|
||||
skip_animations=args.skip_animations,
|
||||
start_at_animation_number=start,
|
||||
end_at_animation_number=end,
|
||||
presenter_mode=args.presenter_mode,
|
||||
)
|
||||
if args.leave_progress_bars:
|
||||
scene_config["leave_progress_bars"] = True
|
||||
if args.show_animation_progress:
|
||||
scene_config["show_animation_progress"] = True
|
||||
|
||||
|
||||
# Shortcuts for retrieving portions of global configuration
|
||||
|
||||
|
||||
|
@ -302,25 +323,11 @@ def get_file_writer_config() -> dict:
|
|||
return get_global_config()["file_writer"]
|
||||
|
||||
|
||||
def get_scene_config(args: Namespace) -> dict:
|
||||
def get_scene_config() -> dict:
|
||||
"""
|
||||
Returns a dictionary to be used as key word arguments for Scene
|
||||
"""
|
||||
global_config = get_global_config()
|
||||
camera_config = get_camera_config()
|
||||
file_writer_config = get_file_writer_config()
|
||||
start, end = get_animations_numbers(args)
|
||||
|
||||
return {
|
||||
"file_writer_config": file_writer_config,
|
||||
"camera_config": camera_config,
|
||||
"skip_animations": args.skip_animations,
|
||||
"start_at_animation_number": start,
|
||||
"end_at_animation_number": end,
|
||||
"presenter_mode": args.presenter_mode,
|
||||
"leave_progress_bars": args.leave_progress_bars,
|
||||
"show_animation_progress": args.show_animation_progress,
|
||||
}
|
||||
return get_global_config()["scene"]
|
||||
|
||||
|
||||
def get_run_config(args: Namespace):
|
||||
|
|
|
@ -53,6 +53,11 @@ file_writer:
|
|||
pixel_format: "yuv420p"
|
||||
saturation: 1.0
|
||||
gamma: 1.0
|
||||
scene:
|
||||
# Most of the scene configuration will come from CLI arguments,
|
||||
# but defaults can be set here
|
||||
show_animation_progress: False
|
||||
leave_progress_bars: False
|
||||
style:
|
||||
tex_template: "default"
|
||||
font: "Consolas"
|
||||
|
|
|
@ -77,13 +77,13 @@ def compute_total_frames(scene_class, scene_config):
|
|||
pre_scene = scene_class(**pre_config)
|
||||
pre_scene.run()
|
||||
total_time = pre_scene.time - pre_scene.skip_time
|
||||
return int(total_time * scene_config["camera_config"]["fps"])
|
||||
return int(total_time * get_global_config()["camera"]["fps"])
|
||||
|
||||
|
||||
def scene_from_class(scene_class, scene_config, run_config):
|
||||
fw_config = scene_config["file_writer_config"]
|
||||
fw_config = get_global_config()["file_writer"]
|
||||
if fw_config["write_to_movie"] and run_config["prerun"]:
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config)
|
||||
scene_config["file_writer_config"]["total_frames"] = compute_total_frames(scene_class, scene_config)
|
||||
return scene_class(**scene_config)
|
||||
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class ReloadManager:
|
|||
Creates a new configuration based on the CLI args and runs the scenes.
|
||||
"""
|
||||
# Args to Config
|
||||
scene_config = manimlib.config.get_scene_config(self.args)
|
||||
scene_config = manimlib.config.get_scene_config()
|
||||
scene_config.update(reload_manager=self)
|
||||
|
||||
run_config = manimlib.config.get_run_config(self.args)
|
||||
|
|
|
@ -15,6 +15,8 @@ from tqdm.auto import tqdm as ProgressDisplay
|
|||
from manimlib.animation.animation import prepare_animation
|
||||
from manimlib.camera.camera import Camera
|
||||
from manimlib.camera.camera_frame import CameraFrame
|
||||
from manimlib.config import get_camera_config
|
||||
from manimlib.config import get_file_writer_config
|
||||
from manimlib.constants import ARROW_SYMBOLS
|
||||
from manimlib.constants import DEFAULT_WAIT_TIME
|
||||
from manimlib.event_handler import EVENT_DISPATCHER
|
||||
|
@ -29,6 +31,7 @@ from manimlib.mobject.types.vectorized_mobject import VMobject
|
|||
from manimlib.scene.scene_embed import interactive_scene_embed
|
||||
from manimlib.scene.scene_embed import CheckpointManager
|
||||
from manimlib.scene.scene_file_writer import SceneFileWriter
|
||||
from manimlib.utils.dict_ops import merge_dicts_recursively
|
||||
from manimlib.utils.family_ops import extract_mobject_family_members
|
||||
from manimlib.utils.family_ops import recursive_mobject_remove
|
||||
from manimlib.utils.iterables import batch_by_property
|
||||
|
@ -68,17 +71,17 @@ class Scene(object):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
window: Optional[Window] = None,
|
||||
reload_manager: Optional[ReloadManager] = None,
|
||||
camera_config: dict = dict(),
|
||||
file_writer_config: dict = dict(),
|
||||
skip_animations: bool = False,
|
||||
always_update_mobjects: bool = False,
|
||||
start_at_animation_number: int | None = None,
|
||||
end_at_animation_number: int | None = None,
|
||||
leave_progress_bars: bool = False,
|
||||
window: Optional[Window] = None,
|
||||
reload_manager: Optional[ReloadManager] = None,
|
||||
presenter_mode: bool = False,
|
||||
show_animation_progress: bool = False,
|
||||
leave_progress_bars: bool = False,
|
||||
presenter_mode: bool = False,
|
||||
):
|
||||
self.skip_animations = skip_animations
|
||||
self.always_update_mobjects = always_update_mobjects
|
||||
|
@ -89,8 +92,16 @@ class Scene(object):
|
|||
self.show_animation_progress = show_animation_progress
|
||||
self.reload_manager = reload_manager
|
||||
|
||||
self.camera_config = {**self.default_camera_config, **camera_config}
|
||||
self.file_writer_config = {**self.default_file_writer_config, **file_writer_config}
|
||||
self.camera_config = merge_dicts_recursively(
|
||||
get_camera_config(), # Global default
|
||||
self.default_camera_config, # Updated configuration that subclasses may specify
|
||||
camera_config, # Updated configuration from instantiation
|
||||
)
|
||||
self.file_writer_config = merge_dicts_recursively(
|
||||
get_file_writer_config(),
|
||||
self.default_file_writer_config,
|
||||
file_writer_config,
|
||||
)
|
||||
|
||||
self.window = window
|
||||
if self.window:
|
||||
|
|
Loading…
Add table
Reference in a new issue