2019-01-09 12:49:43 -08:00
|
|
|
#!/usr/bin/env python
|
2015-12-23 12:31:22 -08:00
|
|
|
import inspect
|
|
|
|
import os
|
2018-03-31 15:11:35 -07:00
|
|
|
import sys
|
2019-01-09 12:49:43 -08:00
|
|
|
import importlib
|
2018-03-31 15:11:35 -07:00
|
|
|
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.constants import PRODUCTION_QUALITY_CAMERA_CONFIG
|
|
|
|
from manimlib.constants import PRODUCTION_QUALITY_FRAME_DURATION
|
2019-01-09 12:49:43 -08:00
|
|
|
from manimlib.config import get_module
|
|
|
|
from manimlib.extract_scene import is_child_scene
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.utils.output_directory_getters import get_movie_output_directory
|
2015-12-23 12:31:22 -08:00
|
|
|
|
|
|
|
|
2018-04-29 10:47:53 -07:00
|
|
|
def get_sorted_scene_classes(module_name):
|
2015-12-23 12:31:22 -08:00
|
|
|
module = get_module(module_name)
|
2019-01-09 12:49:43 -08:00
|
|
|
importlib.import_module(module.__name__)
|
2015-12-23 12:31:22 -08:00
|
|
|
line_to_scene = {}
|
2019-01-09 12:49:43 -08:00
|
|
|
name_scene_list = inspect.getmembers(
|
|
|
|
module,
|
|
|
|
lambda obj: is_child_scene(obj, module)
|
|
|
|
)
|
|
|
|
for name, scene_class in name_scene_list:
|
|
|
|
if inspect.getmodule(scene_class).__name__ != module.__name__:
|
2018-04-29 10:47:53 -07:00
|
|
|
continue
|
2015-12-23 12:31:22 -08:00
|
|
|
lines, line_no = inspect.getsourcelines(scene_class)
|
2018-04-29 10:47:53 -07:00
|
|
|
line_to_scene[line_no] = scene_class
|
2015-12-23 12:31:22 -08:00
|
|
|
return [
|
2018-04-29 10:47:53 -07:00
|
|
|
line_to_scene[index]
|
|
|
|
for index in sorted(line_to_scene.keys())
|
2015-12-23 12:31:22 -08:00
|
|
|
]
|
|
|
|
|
2018-04-29 10:47:53 -07:00
|
|
|
|
2018-01-25 23:51:36 -08:00
|
|
|
def stage_animations(module_name):
|
2018-04-29 10:47:53 -07:00
|
|
|
scene_classes = get_sorted_scene_classes(module_name)
|
|
|
|
if len(scene_classes) == 0:
|
|
|
|
print("There are no rendered animations from this module")
|
|
|
|
return
|
|
|
|
animation_dir = get_movie_output_directory(
|
|
|
|
scene_classes[0],
|
|
|
|
PRODUCTION_QUALITY_CAMERA_CONFIG,
|
|
|
|
PRODUCTION_QUALITY_FRAME_DURATION,
|
2015-12-23 12:31:22 -08:00
|
|
|
)
|
2018-01-12 13:38:25 -08:00
|
|
|
files = os.listdir(animation_dir)
|
2015-12-23 12:31:22 -08:00
|
|
|
sorted_files = []
|
2018-04-29 10:47:53 -07:00
|
|
|
for scene_class in scene_classes:
|
|
|
|
scene_name = scene_class.__name__
|
2018-08-09 17:56:05 -07:00
|
|
|
for clip in [f for f in files if f.startswith(scene_name + ".")]:
|
2018-04-29 10:47:53 -07:00
|
|
|
sorted_files.append(os.path.join(animation_dir, clip))
|
|
|
|
|
|
|
|
animation_subdir = os.path.dirname(animation_dir)
|
2018-01-25 23:51:36 -08:00
|
|
|
count = 0
|
|
|
|
while True:
|
|
|
|
staged_scenes_dir = os.path.join(
|
2018-04-29 10:47:53 -07:00
|
|
|
animation_subdir, "staged_scenes_%d" % count
|
2018-01-25 23:51:36 -08:00
|
|
|
)
|
|
|
|
if not os.path.exists(staged_scenes_dir):
|
|
|
|
os.makedirs(staged_scenes_dir)
|
|
|
|
break
|
2018-04-29 10:47:53 -07:00
|
|
|
# Otherwise, keep trying new names until
|
|
|
|
# there is a free one
|
2018-01-25 23:51:36 -08:00
|
|
|
count += 1
|
|
|
|
for count, f in enumerate(sorted_files):
|
2016-01-11 15:55:36 -08:00
|
|
|
symlink_name = os.path.join(
|
2018-01-25 23:51:36 -08:00
|
|
|
staged_scenes_dir,
|
2018-04-29 10:47:53 -07:00
|
|
|
"Scene_%03d" % count + f.split(os.sep)[-1]
|
2016-01-11 15:55:36 -08:00
|
|
|
)
|
|
|
|
os.symlink(f, symlink_name)
|
2015-12-23 12:31:22 -08:00
|
|
|
|
2018-04-29 10:47:53 -07:00
|
|
|
|
2015-12-23 12:31:22 -08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) < 2:
|
2016-05-03 23:14:40 -07:00
|
|
|
raise Exception("No module given.")
|
2015-12-23 12:31:22 -08:00
|
|
|
module_name = sys.argv[1]
|
2018-04-29 10:47:53 -07:00
|
|
|
stage_animations(module_name)
|