mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Allow scene extraction from a special file which contains an ALL_SCENE_CLASSES list and an OUTPUT_DIRECTORY. This is part of a move to make the output file organization independent from the sourcecode organization
This commit is contained in:
parent
900e6ac837
commit
0255627922
2 changed files with 42 additions and 23 deletions
|
@ -155,6 +155,7 @@ def get_module(file_name):
|
||||||
|
|
||||||
|
|
||||||
def get_configuration(args):
|
def get_configuration(args):
|
||||||
|
module = get_module(args.file)
|
||||||
file_writer_config = {
|
file_writer_config = {
|
||||||
# By default, write to file
|
# By default, write to file
|
||||||
"write_to_movie": args.write_to_movie or not args.save_last_frame,
|
"write_to_movie": args.write_to_movie or not args.save_last_frame,
|
||||||
|
@ -165,8 +166,10 @@ def get_configuration(args):
|
||||||
"movie_file_extension": ".mov" if args.transparent else ".mp4",
|
"movie_file_extension": ".mov" if args.transparent else ".mp4",
|
||||||
"file_name": args.file_name,
|
"file_name": args.file_name,
|
||||||
}
|
}
|
||||||
|
if hasattr(module, "OUTPUT_DIRECTORY"):
|
||||||
|
file_writer_config["output_directory"] = module.OUTPUT_DIRECTORY
|
||||||
config = {
|
config = {
|
||||||
"module": get_module(args.file),
|
"module": module,
|
||||||
"scene_names": args.scene_names,
|
"scene_names": args.scene_names,
|
||||||
"open_video_upon_completion": args.preview,
|
"open_video_upon_completion": args.preview,
|
||||||
"show_file_in_finder": args.show_file_in_finder,
|
"show_file_in_finder": args.show_file_in_finder,
|
||||||
|
|
|
@ -67,16 +67,16 @@ def is_child_scene(obj, module):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def prompt_user_for_choice(name_to_obj):
|
def prompt_user_for_choice(scene_classes):
|
||||||
num_to_name = {}
|
num_to_class = {}
|
||||||
names = sorted(name_to_obj.keys())
|
for count, scene_class in zip(it.count(1), scene_classes):
|
||||||
for count, name in zip(it.count(1), names):
|
name = scene_class.__name__
|
||||||
print("%d: %s" % (count, name))
|
print("%d: %s" % (count, name))
|
||||||
num_to_name[count] = name
|
num_to_class[count] = scene_class
|
||||||
try:
|
try:
|
||||||
user_input = input(manimlib.constants.CHOOSE_NUMBER_MESSAGE)
|
user_input = input(manimlib.constants.CHOOSE_NUMBER_MESSAGE)
|
||||||
return [
|
return [
|
||||||
name_to_obj[num_to_name[int(num_str)]]
|
num_to_class[int(num_str)]
|
||||||
for num_str in user_input.split(",")
|
for num_str in user_input.split(",")
|
||||||
]
|
]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -84,54 +84,70 @@ def prompt_user_for_choice(name_to_obj):
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
user_input = input(manimlib.constants.CHOOSE_NUMBER_MESSAGE)
|
user_input = input(manimlib.constants.CHOOSE_NUMBER_MESSAGE)
|
||||||
return [
|
return [
|
||||||
name_to_obj[num_to_name[int(num_str)]]
|
num_to_class[int(num_str)]
|
||||||
for num_str in user_input.split(",")
|
for num_str in user_input.split(",")
|
||||||
]
|
]
|
||||||
except EOFError:
|
except EOFError:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_scene_classes(scene_names_to_classes, config):
|
def get_scenes_to_render(scene_classes, config):
|
||||||
if len(scene_names_to_classes) == 0:
|
if len(scene_classes) == 0:
|
||||||
print(manimlib.constants.NO_SCENE_MESSAGE)
|
print(manimlib.constants.NO_SCENE_MESSAGE)
|
||||||
return []
|
return []
|
||||||
if config["write_all"]:
|
if config["write_all"]:
|
||||||
return list(scene_names_to_classes.values())
|
return scene_classes
|
||||||
scene_classes = []
|
result = []
|
||||||
for scene_name in config["scene_names"]:
|
for scene_name in config["scene_names"]:
|
||||||
if scene_name in scene_names_to_classes:
|
found = False
|
||||||
scene_classes.append(scene_names_to_classes[scene_name])
|
for scene_class in scene_classes:
|
||||||
elif scene_name != "":
|
if scene_class.__name__ == scene_name:
|
||||||
|
result.append(scene_class)
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found and (scene_name != ""):
|
||||||
print(
|
print(
|
||||||
manimlib.constants.SCENE_NOT_FOUND_MESSAGE.format(
|
manimlib.constants.SCENE_NOT_FOUND_MESSAGE.format(
|
||||||
scene_name
|
scene_name
|
||||||
),
|
),
|
||||||
file=sys.stderr
|
file=sys.stderr
|
||||||
)
|
)
|
||||||
if scene_classes:
|
if result:
|
||||||
return scene_classes
|
return result
|
||||||
return prompt_user_for_choice(scene_names_to_classes)
|
return prompt_user_for_choice(scene_classes)
|
||||||
|
|
||||||
|
|
||||||
|
def get_scene_classes_from_module(module):
|
||||||
|
if hasattr(module, "ALL_SCENE_CLASSES"):
|
||||||
|
return module.ALL_SCENE_CLASSES
|
||||||
|
else:
|
||||||
|
return [
|
||||||
|
member[1]
|
||||||
|
for member in inspect.getmembers(
|
||||||
|
module,
|
||||||
|
lambda x: is_child_scene(x, module)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main(config):
|
def main(config):
|
||||||
module = config["module"]
|
module = config["module"]
|
||||||
scene_names_to_classes = dict(
|
all_scene_classes = get_scene_classes_from_module(module)
|
||||||
inspect.getmembers(module, lambda x: is_child_scene(x, module))
|
scene_classes_to_render = get_scenes_to_render(all_scene_classes, config)
|
||||||
)
|
|
||||||
|
|
||||||
scene_kwargs = dict([
|
scene_kwargs = dict([
|
||||||
(key, config[key])
|
(key, config[key])
|
||||||
for key in [
|
for key in [
|
||||||
"camera_config",
|
"camera_config",
|
||||||
"skip_animations",
|
|
||||||
"file_writer_config",
|
"file_writer_config",
|
||||||
|
"skip_animations",
|
||||||
"start_at_animation_number",
|
"start_at_animation_number",
|
||||||
"end_at_animation_number",
|
"end_at_animation_number",
|
||||||
"leave_progress_bars",
|
"leave_progress_bars",
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
|
|
||||||
for SceneClass in get_scene_classes(scene_names_to_classes, config):
|
for SceneClass in scene_classes_to_render:
|
||||||
try:
|
try:
|
||||||
# By invoking, this renders the full scene
|
# By invoking, this renders the full scene
|
||||||
scene = SceneClass(**scene_kwargs)
|
scene = SceneClass(**scene_kwargs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue