mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
reorganize media file tree
This commit is contained in:
parent
c203f8e8c0
commit
caa4577cd1
8 changed files with 36 additions and 52 deletions
0
manim.py
Normal file → Executable file
0
manim.py
Normal file → Executable file
|
@ -20,28 +20,19 @@ if not os.path.isdir(MEDIA_DIR):
|
|||
"this behavior by writing a different directory to media_dir.txt."
|
||||
)
|
||||
|
||||
VIDEO_DIR = os.path.join(MEDIA_DIR, "videos")
|
||||
RASTER_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "raster_images")
|
||||
SVG_IMAGE_DIR = os.path.join(MEDIA_DIR, "designs", "svg_images")
|
||||
SOUND_DIR = os.path.join(MEDIA_DIR, "designs", "sounds")
|
||||
###
|
||||
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
FILE_DIR = os.path.join(os.getenv("FILE_DIR", default="."), "files")
|
||||
TEX_DIR = os.path.join(FILE_DIR, "Tex")
|
||||
# These two may be depricated now.
|
||||
MOBJECT_DIR = os.path.join(FILE_DIR, "mobjects")
|
||||
IMAGE_MOBJECT_DIR = os.path.join(MOBJECT_DIR, "image")
|
||||
VIDEO_DIR = os.path.join(MEDIA_DIR, "video")
|
||||
ASSETS_DIR = os.path.join(MEDIA_DIR, "assets")
|
||||
TEX_DIR = os.path.join(MEDIA_DIR, "Tex")
|
||||
|
||||
for folder in [FILE_DIR, RASTER_IMAGE_DIR, SVG_IMAGE_DIR, VIDEO_DIR,
|
||||
TEX_DIR, MOBJECT_DIR, IMAGE_MOBJECT_DIR]:
|
||||
for folder in [VIDEO_DIR, ASSETS_DIR, TEX_DIR]:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
TEX_USE_CTEX = False
|
||||
TEX_TEXT_TO_REPLACE = "YourTextHere"
|
||||
TEMPLATE_TEX_FILE = os.path.join(
|
||||
THIS_DIR, "tex_template.tex" if not TEX_USE_CTEX
|
||||
else "ctex_template.tex"
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
"tex_template.tex" if not TEX_USE_CTEX else "ctex_template.tex"
|
||||
)
|
||||
with open(TEMPLATE_TEX_FILE, "r") as infile:
|
||||
TEMPLATE_TEXT_FILE_BODY = infile.read()
|
||||
|
|
|
@ -15,11 +15,11 @@ from manimlib.utils.config_ops import digest_config
|
|||
from manimlib.utils.space_ops import get_norm
|
||||
from manimlib.utils.space_ops import normalize
|
||||
|
||||
pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "designs", "PiCreature")
|
||||
pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "assets", "PiCreature")
|
||||
if os.path.exists(pi_creature_dir_maybe):
|
||||
PI_CREATURE_DIR = pi_creature_dir_maybe
|
||||
else:
|
||||
PI_CREATURE_DIR = os.path.join(FILE_DIR)
|
||||
PI_CREATURE_DIR = os.path.join("assets")
|
||||
|
||||
PI_CREATURE_SCALE_FACTOR = 0.5
|
||||
|
||||
|
|
|
@ -50,9 +50,9 @@ class SVGMobject(VMobject):
|
|||
if self.file_name is None:
|
||||
raise Exception("Must specify file for SVGMobject")
|
||||
possible_paths = [
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name),
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name + ".svg"),
|
||||
os.path.join(SVG_IMAGE_DIR, self.file_name + ".xdv"),
|
||||
os.path.join(os.path.join("assets", "svg_images"), self.file_name),
|
||||
os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".svg"),
|
||||
os.path.join(os.path.join("assets", "svg_images"), self.file_name + ".xdv"),
|
||||
self.file_name,
|
||||
]
|
||||
for path in possible_paths:
|
||||
|
|
|
@ -13,7 +13,7 @@ from manimlib.constants import STREAMING_PORT
|
|||
from manimlib.constants import STREAMING_PROTOCOL
|
||||
from manimlib.constants import VIDEO_DIR
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.file_ops import guarantee_existance
|
||||
from manimlib.utils.file_ops import guarantee_existence
|
||||
from manimlib.utils.file_ops import add_extension_if_not_present
|
||||
from manimlib.utils.file_ops import get_sorted_integer_files
|
||||
from manimlib.utils.sounds import get_full_sound_file_path
|
||||
|
@ -35,7 +35,6 @@ class SceneFileWriter(object):
|
|||
# TODO, address this in extract_scene et. al.
|
||||
"file_name": None,
|
||||
"output_directory": None,
|
||||
"file_name": None,
|
||||
}
|
||||
|
||||
def __init__(self, scene, **kwargs):
|
||||
|
@ -47,66 +46,62 @@ class SceneFileWriter(object):
|
|||
|
||||
# Output directories and files
|
||||
def init_output_directories(self):
|
||||
output_directory = self.output_directory or self.get_default_output_directory()
|
||||
file_name = self.file_name or self.get_default_file_name()
|
||||
module_directory = self.output_directory or self.get_default_module_directory()
|
||||
scene_name = self.file_name or self.get_default_scene_name()
|
||||
if self.save_last_frame:
|
||||
image_dir = guarantee_existance(os.path.join(
|
||||
image_dir = guarantee_existence(os.path.join(
|
||||
VIDEO_DIR,
|
||||
output_directory,
|
||||
self.get_image_directory(),
|
||||
module_directory,
|
||||
scene_name,
|
||||
"images",
|
||||
))
|
||||
self.image_file_path = os.path.join(
|
||||
image_dir,
|
||||
add_extension_if_not_present(file_name, ".png")
|
||||
add_extension_if_not_present(scene_name, ".png")
|
||||
)
|
||||
if self.write_to_movie:
|
||||
movie_dir = guarantee_existance(os.path.join(
|
||||
movie_dir = guarantee_existence(os.path.join(
|
||||
VIDEO_DIR,
|
||||
output_directory,
|
||||
self.get_movie_directory(),
|
||||
module_directory,
|
||||
scene_name,
|
||||
self.get_resolution_directory(),
|
||||
))
|
||||
self.movie_file_path = os.path.join(
|
||||
movie_dir,
|
||||
add_extension_if_not_present(
|
||||
file_name, self.movie_file_extension
|
||||
scene_name, self.movie_file_extension
|
||||
)
|
||||
)
|
||||
self.gif_file_path = os.path.join(
|
||||
movie_dir,
|
||||
add_extension_if_not_present(
|
||||
file_name, self.gif_file_extension
|
||||
scene_name, self.gif_file_extension
|
||||
)
|
||||
)
|
||||
self.partial_movie_directory = guarantee_existance(os.path.join(
|
||||
self.partial_movie_directory = guarantee_existence(os.path.join(
|
||||
movie_dir,
|
||||
self.get_partial_movie_directory(),
|
||||
file_name,
|
||||
"partial_movie_files",
|
||||
scene_name,
|
||||
))
|
||||
|
||||
def get_default_output_directory(self):
|
||||
def get_default_module_directory(self):
|
||||
filename = os.path.basename(self.input_file_path)
|
||||
root, ext = os.path.splitext(filename)
|
||||
return root if root else ext[1:]
|
||||
root, _ = os.path.splitext(filename)
|
||||
return root
|
||||
|
||||
def get_default_file_name(self):
|
||||
def get_default_scene_name(self):
|
||||
if self.file_name is None:
|
||||
return self.scene.__class__.__name__
|
||||
else:
|
||||
return self.file_name
|
||||
|
||||
def get_movie_directory(self):
|
||||
def get_resolution_directory(self):
|
||||
pixel_height = self.scene.camera.pixel_height
|
||||
frame_rate = self.scene.camera.frame_rate
|
||||
return "{}p{}".format(
|
||||
pixel_height, frame_rate
|
||||
)
|
||||
|
||||
def get_image_directory(self):
|
||||
return "images"
|
||||
|
||||
def get_partial_movie_directory(self):
|
||||
return "partial_movie_files"
|
||||
|
||||
# Directory getters
|
||||
def get_image_file_path(self):
|
||||
return self.image_file_path
|
||||
|
|
|
@ -10,7 +10,7 @@ def add_extension_if_not_present(file_name, extension):
|
|||
return file_name
|
||||
|
||||
|
||||
def guarantee_existance(path):
|
||||
def guarantee_existence(path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
return os.path.abspath(path)
|
||||
|
|
|
@ -3,14 +3,13 @@ import os
|
|||
|
||||
from PIL import Image
|
||||
|
||||
from manimlib.constants import RASTER_IMAGE_DIR
|
||||
from manimlib.utils.file_ops import seek_full_path_from_defaults
|
||||
|
||||
|
||||
def get_full_raster_image_path(image_file_name):
|
||||
return seek_full_path_from_defaults(
|
||||
image_file_name,
|
||||
default_dir=RASTER_IMAGE_DIR,
|
||||
default_dir=os.path.join("assets", "raster_images"),
|
||||
extensions=[".jpg", ".png", ".gif"]
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
from manimlib.constants import SOUND_DIR
|
||||
from manimlib.utils.file_ops import seek_full_path_from_defaults
|
||||
|
||||
|
||||
|
@ -35,6 +34,6 @@ def play_finish_sound():
|
|||
def get_full_sound_file_path(sound_file_name):
|
||||
return seek_full_path_from_defaults(
|
||||
sound_file_name,
|
||||
default_dir=SOUND_DIR,
|
||||
default_dir=os.path.join("assets", "sounds"),
|
||||
extensions=[".wav", ".mp3"]
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue