mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Factor out configuration to be passed into a scene vs. that used to run a scene
This commit is contained in:
parent
0496402c55
commit
96a4a4b76f
3 changed files with 25 additions and 26 deletions
|
@ -461,20 +461,19 @@ def get_camera_config(args: Optional[Namespace] = None, custom_config: Optional[
|
|||
return camera_config
|
||||
|
||||
|
||||
def get_configuration(args: Namespace) -> dict:
|
||||
def get_scene_config(args: Namespace) -> dict:
|
||||
"""
|
||||
Returns a dictionary to be used as key word arguments for Scene
|
||||
"""
|
||||
global_config = get_global_config()
|
||||
camera_config = get_camera_config(args, global_config)
|
||||
window_config = get_window_config(args, global_config, camera_config)
|
||||
start, end = get_animations_numbers(args)
|
||||
|
||||
return {
|
||||
"module": get_scene_module(args),
|
||||
"scene_names": args.scene_names,
|
||||
"file_writer_config": get_file_writer_config(args, global_config),
|
||||
"camera_config": camera_config,
|
||||
"window_config": window_config,
|
||||
"quiet": args.quiet or args.write_all,
|
||||
"write_all": args.write_all,
|
||||
"skip_animations": args.skip_animations,
|
||||
"start_at_animation_number": start,
|
||||
"end_at_animation_number": end,
|
||||
|
@ -482,7 +481,16 @@ def get_configuration(args: Namespace) -> dict:
|
|||
"presenter_mode": args.presenter_mode,
|
||||
"leave_progress_bars": args.leave_progress_bars,
|
||||
"show_animation_progress": args.show_animation_progress,
|
||||
"prerun": args.prerun,
|
||||
"embed_exception_mode": global_config["embed_exception_mode"],
|
||||
"embed_error_sound": global_config["embed_error_sound"],
|
||||
}
|
||||
|
||||
|
||||
def get_run_config(args: Namespace):
|
||||
return {
|
||||
"module": get_scene_module(args),
|
||||
"prerun": args.prerun,
|
||||
"scene_names": args.scene_names,
|
||||
"quiet": args.quiet or args.write_all,
|
||||
"write_all": args.write_all,
|
||||
}
|
||||
|
|
|
@ -53,14 +53,6 @@ def prompt_user_for_choice(scene_classes):
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def get_scene_config(config):
|
||||
scene_parameters = inspect.signature(Scene).parameters.keys()
|
||||
return {
|
||||
key: config[key]
|
||||
for key in set(scene_parameters).intersection(config.keys())
|
||||
}
|
||||
|
||||
|
||||
def compute_total_frames(scene_class, scene_config):
|
||||
"""
|
||||
When a scene is being written to file, a copy of the scene is run with
|
||||
|
@ -79,19 +71,19 @@ def compute_total_frames(scene_class, scene_config):
|
|||
return int(total_time * scene_config["camera_config"]["fps"])
|
||||
|
||||
|
||||
def scene_from_class(scene_class, scene_config, config):
|
||||
def scene_from_class(scene_class, scene_config, run_config):
|
||||
fw_config = scene_config["file_writer_config"]
|
||||
if fw_config["write_to_movie"] and config["prerun"]:
|
||||
if fw_config["write_to_movie"] and run_config["prerun"]:
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config)
|
||||
return scene_class(**scene_config)
|
||||
|
||||
|
||||
def get_scenes_to_render(all_scene_classes, scene_config, config):
|
||||
if config["write_all"]:
|
||||
def get_scenes_to_render(all_scene_classes, scene_config, run_config):
|
||||
if run_config["write_all"]:
|
||||
return [sc(**scene_config) for sc in all_scene_classes]
|
||||
|
||||
names_to_classes = {sc.__name__ : sc for sc in all_scene_classes}
|
||||
scene_names = config["scene_names"]
|
||||
scene_names = run_config["scene_names"]
|
||||
|
||||
for name in set.difference(set(scene_names), names_to_classes):
|
||||
log.error(f"No scene named {name} found")
|
||||
|
@ -105,7 +97,7 @@ def get_scenes_to_render(all_scene_classes, scene_config, config):
|
|||
classes_to_run = prompt_user_for_choice(all_scene_classes)
|
||||
|
||||
return [
|
||||
scene_from_class(scene_class, scene_config, config)
|
||||
scene_from_class(scene_class, scene_config, run_config)
|
||||
for scene_class in classes_to_run
|
||||
]
|
||||
|
||||
|
@ -123,13 +115,12 @@ def get_scene_classes_from_module(module):
|
|||
]
|
||||
|
||||
|
||||
def main(config):
|
||||
module = config["module"]
|
||||
scene_config = get_scene_config(config)
|
||||
def main(scene_config, run_config):
|
||||
module = run_config["module"]
|
||||
if module is None:
|
||||
# If no module was passed in, just play the blank scene
|
||||
return [BlankScene(**scene_config)]
|
||||
|
||||
all_scene_classes = get_scene_classes_from_module(module)
|
||||
scenes = get_scenes_to_render(all_scene_classes, scene_config, config)
|
||||
scenes = get_scenes_to_render(all_scene_classes, scene_config, run_config)
|
||||
return scenes
|
||||
|
|
|
@ -10,7 +10,7 @@ import numpy as np
|
|||
from functools import lru_cache
|
||||
|
||||
from manimlib.config import parse_cli
|
||||
from manimlib.config import get_configuration
|
||||
from manimlib.config import get_camera_config
|
||||
from manimlib.utils.iterables import resize_array
|
||||
from manimlib.utils.shaders import get_shader_code_from_file
|
||||
from manimlib.utils.shaders import get_shader_program
|
||||
|
@ -409,7 +409,7 @@ class VShaderWrapper(ShaderWrapper):
|
|||
which can display that texture as a simple quad onto a screen,
|
||||
along with the rgb value which is meant to be discarded.
|
||||
"""
|
||||
cam_config = get_configuration(parse_cli())['camera_config']
|
||||
cam_config = get_camera_config()
|
||||
size = (cam_config['pixel_width'], cam_config['pixel_height'])
|
||||
double_size = (2 * size[0], 2 * size[1])
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue