mirror of
https://github.com/3b1b/manim.git
synced 2025-08-21 05:44:04 +00:00
Make it so that simply typing 'python -m manim' will embed you in a blank scene to work with
This commit is contained in:
parent
7b3f4d08f5
commit
93fe783b80
4 changed files with 31 additions and 15 deletions
|
@ -25,6 +25,7 @@ tex:
|
||||||
# executable: "xelatex -no-pdf"
|
# executable: "xelatex -no-pdf"
|
||||||
# template_file: "ctex_template.tex"
|
# template_file: "ctex_template.tex"
|
||||||
# intermediate_filetype: "xdv"
|
# intermediate_filetype: "xdv"
|
||||||
|
universal_import_line: "from manimlib.imports import *"
|
||||||
style:
|
style:
|
||||||
background_color: "#333333"
|
background_color: "#333333"
|
||||||
quality:
|
quality:
|
||||||
|
|
|
@ -143,15 +143,17 @@ def get_manim_dir():
|
||||||
|
|
||||||
|
|
||||||
def get_module(file_name):
|
def get_module(file_name):
|
||||||
if file_name == "-":
|
# if file_name == "-":
|
||||||
module = types.ModuleType("input_scenes")
|
# module = types.ModuleType("input_scenes")
|
||||||
code = "from manimlib.imports import *\n\n" + sys.stdin.read()
|
# code = "from manimlib.imports import *\n\n" + sys.stdin.read()
|
||||||
try:
|
# try:
|
||||||
exec(code, module.__dict__)
|
# exec(code, module.__dict__)
|
||||||
return module
|
# return module
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
print(f"Failed to render scene: {str(e)}")
|
# print(f"Failed to render scene: {str(e)}")
|
||||||
sys.exit(2)
|
# sys.exit(2)
|
||||||
|
if file_name is None:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
module_name = file_name.replace(os.sep, ".").replace(".py", "")
|
module_name = file_name.replace(os.sep, ".").replace(".py", "")
|
||||||
spec = importlib.util.spec_from_file_location(module_name, file_name)
|
spec = importlib.util.spec_from_file_location(module_name, file_name)
|
||||||
|
@ -187,7 +189,7 @@ def get_configuration(args):
|
||||||
"mirror_module_path": custom_defaults["directories"]["mirror_module_path"],
|
"mirror_module_path": custom_defaults["directories"]["mirror_module_path"],
|
||||||
"output_directory": args.video_dir or custom_defaults["directories"]["output"],
|
"output_directory": args.video_dir or custom_defaults["directories"]["output"],
|
||||||
"file_name": args.file_name,
|
"file_name": args.file_name,
|
||||||
"input_file_path": args.file,
|
"input_file_path": args.file or "",
|
||||||
"open_file_upon_completion": args.open,
|
"open_file_upon_completion": args.open,
|
||||||
"show_file_location_upon_completion": args.finder,
|
"show_file_location_upon_completion": args.finder,
|
||||||
"quiet": args.quiet,
|
"quiet": args.quiet,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import inspect
|
import inspect
|
||||||
import itertools as it
|
import itertools as it
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
from manimlib.scene.scene import Scene
|
from manimlib.scene.scene import Scene
|
||||||
|
from manimlib.scene.scene import BlankScene
|
||||||
import manimlib.constants
|
import manimlib.constants
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,10 +45,6 @@ def prompt_user_for_choice(scene_classes):
|
||||||
|
|
||||||
|
|
||||||
def get_scenes_to_render(scene_classes, config):
|
def get_scenes_to_render(scene_classes, config):
|
||||||
if len(scene_classes) == 0:
|
|
||||||
print(manimlib.constants.NO_SCENE_MESSAGE)
|
|
||||||
return []
|
|
||||||
|
|
||||||
scene_kwargs = dict([
|
scene_kwargs = dict([
|
||||||
(key, config[key])
|
(key, config[key])
|
||||||
for key in [
|
for key in [
|
||||||
|
@ -61,6 +59,10 @@ def get_scenes_to_render(scene_classes, config):
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
if len(config["scene_names"]) == 0:
|
||||||
|
# If no module or scenes were passed in, just run the blank scene
|
||||||
|
return [BlankScene(**scene_kwargs)]
|
||||||
|
|
||||||
if config["write_all"]:
|
if config["write_all"]:
|
||||||
return [sc(**scene_kwargs) for sc in scene_classes]
|
return [sc(**scene_kwargs) for sc in scene_classes]
|
||||||
|
|
||||||
|
@ -74,7 +76,8 @@ def get_scenes_to_render(scene_classes, config):
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found and (scene_name != ""):
|
if not found and (scene_name != ""):
|
||||||
print(
|
logging.log(
|
||||||
|
logging.ERROR,
|
||||||
manimlib.constants.SCENE_NOT_FOUND_MESSAGE.format(
|
manimlib.constants.SCENE_NOT_FOUND_MESSAGE.format(
|
||||||
scene_name
|
scene_name
|
||||||
),
|
),
|
||||||
|
@ -87,6 +90,9 @@ def get_scenes_to_render(scene_classes, config):
|
||||||
|
|
||||||
|
|
||||||
def get_scene_classes_from_module(module):
|
def get_scene_classes_from_module(module):
|
||||||
|
if module is None:
|
||||||
|
# If no module was passed in, just run the blank scene
|
||||||
|
return []
|
||||||
if hasattr(module, "SCENES_IN_ORDER"):
|
if hasattr(module, "SCENES_IN_ORDER"):
|
||||||
return module.SCENES_IN_ORDER
|
return module.SCENES_IN_ORDER
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from manimlib.animation.animation import Animation
|
||||||
from manimlib.animation.transform import MoveToTarget
|
from manimlib.animation.transform import MoveToTarget
|
||||||
from manimlib.mobject.mobject import Point
|
from manimlib.mobject.mobject import Point
|
||||||
from manimlib.camera.camera import Camera
|
from manimlib.camera.camera import Camera
|
||||||
|
from manimlib.config import get_custom_defaults
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.container.container import Container
|
from manimlib.container.container import Container
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
|
@ -574,3 +575,9 @@ class Scene(Container):
|
||||||
|
|
||||||
class EndSceneEarlyException(Exception):
|
class EndSceneEarlyException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BlankScene(Scene):
|
||||||
|
def construct(self):
|
||||||
|
exec(get_custom_defaults()["universal_import_line"])
|
||||||
|
self.embed()
|
||||||
|
|
Loading…
Add table
Reference in a new issue