mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 13:34:19 +08:00
Added script to stage animations in nicely sorted order
This commit is contained in:
@ -63,13 +63,15 @@ FILE_DIR = os.path.join(THIS_DIR, os.pardir, "animation_files")
|
|||||||
IMAGE_DIR = os.path.join(FILE_DIR, "images")
|
IMAGE_DIR = os.path.join(FILE_DIR, "images")
|
||||||
GIF_DIR = os.path.join(FILE_DIR, "gifs")
|
GIF_DIR = os.path.join(FILE_DIR, "gifs")
|
||||||
MOVIE_DIR = os.path.join(FILE_DIR, "movies")
|
MOVIE_DIR = os.path.join(FILE_DIR, "movies")
|
||||||
|
STAGED_SCENES_DIR = os.path.join(FILE_DIR, "staged_scenes")
|
||||||
TEX_DIR = os.path.join(FILE_DIR, "Tex")
|
TEX_DIR = os.path.join(FILE_DIR, "Tex")
|
||||||
TEX_IMAGE_DIR = os.path.join(IMAGE_DIR, "Tex")
|
TEX_IMAGE_DIR = os.path.join(IMAGE_DIR, "Tex")
|
||||||
MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects")
|
MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects")
|
||||||
IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image")
|
IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image")
|
||||||
|
|
||||||
for folder in [IMAGE_DIR, GIF_DIR, MOVIE_DIR, TEX_DIR,
|
for folder in [IMAGE_DIR, GIF_DIR, MOVIE_DIR, TEX_DIR,
|
||||||
TEX_IMAGE_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR]:
|
TEX_IMAGE_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR,
|
||||||
|
STAGED_SCENES_DIR]:
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
os.mkdir(folder)
|
os.mkdir(folder)
|
||||||
|
|
||||||
|
45
stage_animations.py
Normal file
45
stage_animations.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import sys
|
||||||
|
import inspect
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from extract_scene import is_scene, get_module
|
||||||
|
from constants import MOVIE_DIR, STAGED_SCENES_DIR
|
||||||
|
|
||||||
|
|
||||||
|
def get_sorted_scene_names(module_name):
|
||||||
|
module = get_module(module_name)
|
||||||
|
line_to_scene = {}
|
||||||
|
for name, scene_class in inspect.getmembers(module, is_scene):
|
||||||
|
lines, line_no = inspect.getsourcelines(scene_class)
|
||||||
|
line_to_scene[line_no] = name
|
||||||
|
return [
|
||||||
|
line_to_scene[line_no]
|
||||||
|
for line_no in sorted(line_to_scene.keys())
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def stage_animaions(module_name):
|
||||||
|
scene_names = get_sorted_scene_names(module_name)
|
||||||
|
movie_dir = os.path.join(
|
||||||
|
MOVIE_DIR, module_name.replace(".py", "")
|
||||||
|
)
|
||||||
|
files = os.listdir(movie_dir)
|
||||||
|
sorted_files = []
|
||||||
|
for scene in scene_names:
|
||||||
|
for clip in filter(lambda f : f.startswith(scene), files):
|
||||||
|
sorted_files.append(
|
||||||
|
os.path.join(movie_dir, clip)
|
||||||
|
)
|
||||||
|
for f in os.listdir(STAGED_SCENES_DIR):
|
||||||
|
os.remove(os.path.join(STAGED_SCENES_DIR, f))
|
||||||
|
for f in sorted_files:
|
||||||
|
shutil.copy(f, STAGED_SCENES_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
raise Exception("No module give.")
|
||||||
|
module_name = sys.argv[1]
|
||||||
|
stage_animaions(module_name)
|
Reference in New Issue
Block a user