mirror of
https://github.com/3b1b/manim.git
synced 2025-07-29 21:12:35 +08:00
added utils/output_directory_getters.py
This commit is contained in:
38
utils/output_directory_getters.py
Normal file
38
utils/output_directory_getters.py
Normal file
@ -0,0 +1,38 @@
|
||||
import inspect
|
||||
import os
|
||||
|
||||
from constants import ANIMATIONS_DIR
|
||||
|
||||
|
||||
def add_extension_if_not_present(file_name, extension):
|
||||
# This could conceivably be smarter about handling existing differing extensions
|
||||
if(file_name[-len(extension):] != extension):
|
||||
return file_name + extension
|
||||
else:
|
||||
return file_name
|
||||
|
||||
|
||||
def get_scene_output_directory(scene_class):
|
||||
file_path = os.path.abspath(inspect.getfile(scene_class))
|
||||
|
||||
# TODO, is there a better way to do this?
|
||||
parts = file_path.split(os.path.sep)
|
||||
if "manim" in parts:
|
||||
sub_parts = parts[parts.index("manim") + 1:]
|
||||
file_path = os.path.join(*sub_parts)
|
||||
file_path = file_path.replace(".pyc", "")
|
||||
file_path = file_path.replace(".py", "")
|
||||
return os.path.join(ANIMATIONS_DIR, file_path)
|
||||
|
||||
|
||||
def get_movie_output_directory(scene_class, camera_config, frame_duration):
|
||||
directory = get_scene_output_directory(scene_class)
|
||||
sub_dir = "%dp%d" % (
|
||||
camera_config["pixel_shape"][0],
|
||||
int(1.0 / frame_duration)
|
||||
)
|
||||
return os.path.join(directory, sub_dir)
|
||||
|
||||
|
||||
def get_image_output_directory(scene_class, sub_dir="images"):
|
||||
return os.path.join(get_scene_output_directory(scene_class), sub_dir)
|
Reference in New Issue
Block a user