Skip to content

Commit 38ab914

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents f4a56ec + 1eedec2 commit 38ab914

File tree

16 files changed

+58
-83
lines changed

16 files changed

+58
-83
lines changed

docs/source/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Fixes
1818
Configuration
1919
^^^^^^^^^^^^^
2020

21+
#. Removed the ``skip_animations`` config option and added the
22+
``Renderer.skip_animations`` attribute instead (via :pr:`696`).
23+
2124
#. The global ``config`` dict has been replaced by a global ``config`` instance
2225
of the new class :class:`~.ManimConfig`. This class has a dict-like API, so
2326
this should not break user code, only make it more robust. See the

docs/source/manim_directive.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def construct(self):
7878

7979
import shutil
8080

81+
from manim import QUALITIES
82+
8183
classnamedict = {}
8284

8385

@@ -150,29 +152,13 @@ def run(self):
150152
else:
151153
ref_block = ""
152154

153-
frame_rate = 30
154-
pixel_height = 480
155-
pixel_width = 854
156-
157155
if "quality" in self.options:
158-
quality = self.options["quality"]
159-
if quality == "low":
160-
pixel_height = 480
161-
pixel_width = 854
162-
frame_rate = 15
163-
elif quality == "medium":
164-
pixel_height = 720
165-
pixel_width = 1280
166-
frame_rate = 30
167-
elif quality == "high":
168-
pixel_height = 1440
169-
pixel_width = 2560
170-
frame_rate = 60
171-
elif quality == "fourk":
172-
pixel_height = 2160
173-
pixel_width = 3840
174-
frame_rate = 60
175-
156+
quality = f'{self.options["quality"]}_quality'
157+
else:
158+
quality = "example_quality"
159+
frame_rate = QUALITIES[quality]["frame_rate"]
160+
pixel_height = QUALITIES[quality]["pixel_height"]
161+
pixel_width = QUALITIES[quality]["pixel_width"]
176162
qualitydir = f"{pixel_height}p{frame_rate}"
177163

178164
state_machine = self.state_machine

manim/_config/main_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ def _parse_args_no_subcmd(args):
317317
parser.add_argument(
318318
"-q",
319319
"--quality",
320-
choices=[constants.QUALITIES[q]["flag"] for q in constants.QUALITIES],
320+
choices=[
321+
constants.QUALITIES[q]["flag"]
322+
for q in constants.QUALITIES
323+
if constants.QUALITIES[q]["flag"]
324+
],
321325
default=constants.DEFAULT_QUALITY_SHORT,
322326
help="Render at specific quality, short form of the --*_quality flags",
323327
)

manim/_config/utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def _determine_quality(args):
126126
pass
127127
elif getattr(args, quality, None) or (
128128
hasattr(args, "quality")
129+
and args.quality is not None
129130
and args.quality == constants.QUALITIES[quality]["flag"]
130131
):
131132
return quality
@@ -278,7 +279,6 @@ class MyScene(Scene):
278279
"save_pngs",
279280
"scene_names",
280281
"show_in_file_browser",
281-
"skip_animations",
282282
"sound",
283283
"tex_dir",
284284
"tex_template_file",
@@ -506,7 +506,6 @@ def digest_parser(self, parser):
506506
"disable_caching",
507507
"flush_cache",
508508
"custom_folders",
509-
"skip_animations",
510509
"use_js_renderer",
511510
]:
512511
setattr(self, key, parser["CLI"].getboolean(key, fallback=False))
@@ -906,12 +905,6 @@ def verbosity(self, val):
906905
doc="Stop rendering animations at this nmber. Use -1 to avoid skipping (-n).",
907906
)
908907

909-
skip_animations = property(
910-
lambda self: self._d["skip_animations"],
911-
lambda self, val: self._set_boolean("skip_animations", val),
912-
doc="Whether to skip the next animation. Internal use only.",
913-
)
914-
915908
max_files_cached = property(
916909
lambda self: self._d["max_files_cached"],
917910
lambda self, val: self._set_pos_number("max_files_cached", val, True),

manim/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ class MyText(Text):
171171
"pixel_width": 854,
172172
"frame_rate": 15,
173173
},
174+
"example_quality": {
175+
"flag": None,
176+
"pixel_height": 480,
177+
"pixel_width": 854,
178+
"frame_rate": 30,
179+
},
174180
}
175181

176182
DEFAULT_QUALITY = "high_quality"

manim/grpc/impl/frame_server_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def GetFrameAtTime(self, request, context):
124124
frame_response.frame_pending = True
125125
selected_scene.renderer_waiting = True
126126
return frame_response
127-
elif selected_scene.skip_animations:
127+
elif selected_scene.renderer.skip_animations:
128128
# Do nothing
129129
return
130130
else:

manim/mobject/svg/tex_mobject.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def construct(self):
2727
2828
class HelloTex(Scene):
2929
def construct(self):
30-
tex = Tex(r'$\xrightarrow{Hello}$ \LaTeX').scale(3)
30+
tex = Tex(r'$\xrightarrow{x^2y^3}$ \LaTeX').scale(3)
3131
self.add(tex)
3232
3333
Whereas in a :class:`~.MathTex` mobject everything is math-mode by default.
@@ -61,14 +61,14 @@ def construct(self):
6161
6262
LaTeX commands and keyword arguments
6363
++++++++++++++++++++++++++++++++++++
64-
We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` text type.
64+
We can use any standard LaTeX commands in the AMS maths packages. For example the ``mathtt`` math-text type, or the ``looparrowright`` arrow.
6565
6666
.. manim:: AMSLaTeX
6767
:save_last_frame:
6868
6969
class AMSLaTeX(Scene):
7070
def construct(self):
71-
tex = Tex(r'$\mathtt{Hello}$ \LaTeX').scale(3)
71+
tex = Tex(r'$\mathtt{H} \looparrowright$ \LaTeX').scale(3)
7272
self.add(tex)
7373
7474
On the manim side, the :class:`~.Tex` class also accepts attributes to change the appearance of the output.
@@ -125,7 +125,7 @@ def construct(self):
125125
126126
class LaTeXMathFonts(Scene):
127127
def construct(self):
128-
tex = Tex(r'$f: A \rightarrow B$', tex_template=TexFontTemplates.french_cursive).scale(3)
128+
tex = Tex(r'$x^2 + y^2 = z^2$', tex_template=TexFontTemplates.french_cursive).scale(3)
129129
self.add(tex)
130130
131131
Manim also has a :class:`~.TexTemplateLibrary` containing the TeX templates used by 3Blue1Brown. One example

manim/renderer/cairo_renderer.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ def handle_play_like_call(func):
3737
"""
3838

3939
def wrapper(self, scene, *args, **kwargs):
40-
allow_write = not config["skip_animations"]
41-
self.file_writer.begin_animation(allow_write)
40+
self.file_writer.begin_animation(not self.skip_animations)
4241
func(self, scene, *args, **kwargs)
43-
self.file_writer.end_animation(allow_write)
42+
self.file_writer.end_animation(not self.skip_animations)
4443
self.num_plays += 1
4544

4645
return wrapper
@@ -53,7 +52,7 @@ class CairoRenderer:
5352
time: time elapsed since initialisation of scene.
5453
"""
5554

56-
def __init__(self, camera_class=None, **kwargs):
55+
def __init__(self, camera_class=None, skip_animations=False, **kwargs):
5756
# All of the following are set to EITHER the value passed via kwargs,
5857
# OR the value stored in the global config dict at the time of
5958
# _instance construction_. Before, they were in the CONFIG dict, which
@@ -72,7 +71,8 @@ def __init__(self, camera_class=None, **kwargs):
7271
self.video_quality_config[attr] = kwargs.get(attr, config[attr])
7372
camera_cls = camera_class if camera_class is not None else Camera
7473
self.camera = camera_cls(self.video_quality_config)
75-
self.original_skipping_status = config["skip_animations"]
74+
self.original_skipping_status = skip_animations
75+
self.skip_animations = skip_animations
7676
self.animations_hashes = []
7777
self.num_plays = 0
7878
self.time = 0
@@ -116,7 +116,7 @@ def update_frame( # TODO Description in Docstring
116116
**kwargs
117117
118118
"""
119-
if config["skip_animations"] and not ignore_skipping:
119+
if self.skip_animations and not ignore_skipping:
120120
return
121121
if mobjects is None:
122122
mobjects = list_update(
@@ -156,7 +156,7 @@ def add_frame(self, frame, num_frames=1):
156156
"""
157157
dt = 1 / self.camera.frame_rate
158158
self.time += num_frames * dt
159-
if config["skip_animations"]:
159+
if self.skip_animations:
160160
return
161161
for _ in range(num_frames):
162162
self.file_writer.write_frame(frame)
@@ -179,29 +179,14 @@ def update_skipping_status(self):
179179
"""
180180
if config["from_animation_number"]:
181181
if self.num_plays < config["from_animation_number"]:
182-
config["skip_animations"] = True
182+
self.skip_animations = True
183183
if config["upto_animation_number"]:
184184
if self.num_plays > config["upto_animation_number"]:
185-
config["skip_animations"] = True
185+
self.skip_animations = True
186186
raise EndSceneEarlyException()
187187

188-
def revert_to_original_skipping_status(self):
189-
"""
190-
Forces the scene to go back to its original skipping status,
191-
by setting skip_animations to whatever it reads
192-
from original_skipping_status.
193-
194-
Returns
195-
-------
196-
Scene
197-
The Scene, with the original skipping status.
198-
"""
199-
if hasattr(self, "original_skipping_status"):
200-
config["skip_animations"] = self.original_skipping_status
201-
return self
202-
203188
def finish(self, scene):
204-
config["skip_animations"] = False
189+
self.skip_animations = self.original_skipping_status
205190
self.file_writer.finish()
206191
if config["save_last_frame"]:
207192
self.update_frame(scene, ignore_skipping=False)

manim/scene/scene.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ def construct(self):
5858

5959
CONFIG = {
6060
"camera_class": Camera,
61-
"skip_animations": False,
6261
"always_update_mobjects": False,
6362
"random_seed": 0,
6463
}
6564

6665
def __init__(self, renderer=None, **kwargs):
6766
Container.__init__(self, **kwargs)
6867
if renderer is None:
69-
self.renderer = CairoRenderer(camera_class=self.camera_class)
68+
self.renderer = CairoRenderer(
69+
camera_class=self.camera_class,
70+
skip_animations=kwargs.get("skip_animations", False),
71+
)
7072
else:
7173
self.renderer = renderer
7274
self.renderer.init(self)
@@ -78,8 +80,6 @@ def __init__(self, renderer=None, **kwargs):
7880
random.seed(self.random_seed)
7981
np.random.seed(self.random_seed)
8082

81-
self.setup()
82-
8383
@property
8484
def camera(self):
8585
return self.renderer.camera
@@ -88,14 +88,12 @@ def render(self):
8888
"""
8989
Render this Scene.
9090
"""
91-
self.original_skipping_status = config["skip_animations"]
91+
self.setup()
9292
try:
9393
self.construct()
9494
except EndSceneEarlyException:
9595
pass
9696
self.tear_down()
97-
# We have to reset these settings in case of multiple renders.
98-
config["skip_animations"] = self.original_skipping_status
9997
self.renderer.finish(self)
10098
logger.info(
10199
f"Rendered {str(self)}\nPlayed {self.renderer.num_plays} animations"
@@ -642,7 +640,7 @@ def get_time_progression(
642640
ProgressDisplay
643641
The CommandLine Progress Bar.
644642
"""
645-
if config["skip_animations"] and not override_skip_animations:
643+
if self.renderer.skip_animations and not override_skip_animations:
646644
times = [run_time]
647645
else:
648646
step = 1 / self.renderer.camera.frame_rate
@@ -858,7 +856,7 @@ def add_sound(self, sound_file, time_offset=0, gain=None, **kwargs):
858856
gain :
859857
860858
"""
861-
if config["skip_animations"]:
859+
if self.renderer.skip_animations:
862860
return
863861
time = self.time + time_offset
864862
self.renderer.file_writer.add_sound(sound_file, time, gain, **kwargs)

manim/utils/caching.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def handle_caching_play(func):
1919
"""
2020

2121
def wrapper(self, scene, *args, **kwargs):
22-
self.revert_to_original_skipping_status()
22+
self.skip_animations = self.original_skipping_status
2323
self.update_skipping_status()
2424
animations = scene.compile_play_args_to_animation_list(*args, **kwargs)
2525
scene.add_mobjects_from_animations(animations)
26-
if config["skip_animations"]:
26+
if self.skip_animations:
2727
logger.debug(f"Skipping animation {self.num_plays}")
2828
func(self, scene, *args, **kwargs)
2929
# If the animation is skipped, we mark its hash as None.
@@ -41,7 +41,7 @@ def wrapper(self, scene, *args, **kwargs):
4141
f"Animation {self.num_plays} : Using cached data (hash : %(hash_play)s)",
4242
{"hash_play": hash_play},
4343
)
44-
config["skip_animations"] = True
44+
self.skip_animations = True
4545
else:
4646
hash_play = "uncached_{:05}".format(self.num_plays)
4747
self.animations_hashes.append(hash_play)

0 commit comments

Comments
 (0)