New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 183: "t values issue that causes the animations to not be finished entirely" #698
Changes from all commits
d831aa6
02fe66c
a1a7fa5
116429b
15f033a
1d0858b
bfe7f4f
ab5e04e
07b6144
d64eba2
69f5465
5dfd51a
207afdb
2582b38
3444992
bd19fa2
d7fa9bd
0876e31
b9d8f46
0e06786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,11 @@ def handle_play_like_call(func): | |
""" | ||
|
||
def wrapper(self, scene, *args, **kwargs): | ||
self.file_writer.begin_animation(not self.skip_animations) | ||
func(self, scene, *args, **kwargs) | ||
self.file_writer.end_animation(not self.skip_animations) | ||
allow_write = not self.skip_animations | ||
self.file_writer.end_animation(allow_write) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion : Could you add ao comment saying this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you are asking here 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @huguesdevimeux means to add a comment saying "Close any open pipes" |
||
self.num_plays += 1 | ||
self.file_writer.begin_animation(allow_write) | ||
func(self, scene, *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
@@ -74,7 +75,7 @@ def __init__(self, camera_class=None, skip_animations=False, **kwargs): | |
self.original_skipping_status = skip_animations | ||
self.skip_animations = skip_animations | ||
self.animations_hashes = [] | ||
self.num_plays = 0 | ||
self.num_plays = -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you do this and then change the comparison in update_skipping_status()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the first time that So, I could implement a bunch of logic in multiple places to avoid incrementing the counter that first time only. OR I can just start the count at -1 😅 Accordingly, For the record, I think this is hacky af and I hate it. But also I'm getting tired of this PR 👀 and I think this can maybe be merged now since it doesn't break any other tests and we can deal with the nasty details later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why increment the counter after the pipe is closed? Couldn't you just do it at the end of play()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On paper, that sounds like a good idea. I just tried it, but it's just bugging out 🤷 If anyone can figure out a way of implementing @eulertour 's suggestion, please go ahead. Otherwise, I'm going to add some tests to this and call it. |
||
self.time = 0 | ||
|
||
def init(self, scene): | ||
|
@@ -93,6 +94,7 @@ def play(self, scene, *args, **kwargs): | |
def update_frame( # TODO Description in Docstring | ||
self, | ||
scene, | ||
dt, | ||
mobjects=None, | ||
background=None, | ||
include_submobjects=True, | ||
|
@@ -123,6 +125,8 @@ def update_frame( # TODO Description in Docstring | |
scene.mobjects, | ||
scene.foreground_mobjects, | ||
) | ||
scene.update_mobjects(dt, mobjects) | ||
|
||
if background is not None: | ||
self.camera.set_frame_to_background(background) | ||
else: | ||
|
@@ -178,16 +182,24 @@ def update_skipping_status(self): | |
raises an EndSceneEarlyException if they don't correspond. | ||
""" | ||
if config["from_animation_number"]: | ||
if self.num_plays < config["from_animation_number"]: | ||
if self.num_plays < config["from_animation_number"] - 1: | ||
self.skip_animations = True | ||
if config["upto_animation_number"]: | ||
if self.num_plays > config["upto_animation_number"]: | ||
if self.num_plays > config["upto_animation_number"] - 1: | ||
self.skip_animations = True | ||
raise EndSceneEarlyException() | ||
|
||
def finish(self, scene): | ||
self.skip_animations = self.original_skipping_status | ||
|
||
# if there was an animation being played, render the last frame | ||
if hasattr(self.file_writer, "writing_process"): | ||
self.update_frame(scene, self.camera.frame_rate, ignore_skipping=False) | ||
self.add_frame(self.camera.pixel_array) | ||
|
||
self.file_writer.end_animation(not self.skip_animations) | ||
self.num_plays += 1 | ||
|
||
self.file_writer.finish() | ||
if config["save_last_frame"]: | ||
self.update_frame(scene, ignore_skipping=False) | ||
self.file_writer.save_final_image(self.camera.get_image()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
import manim as mn | ||
from manim import color as C | ||
from ..utils.testing_utils import get_scenes_to_test | ||
from ..utils.GraphicalUnitTester import GraphicalUnitTester | ||
|
||
|
||
class LastFrame(mn.Scene): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment/issue : I'm worry that it won't test anything, as graphical unit tests are run with the equivalent of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this tests the change either... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going through older issues/PRs again and recall @kolibril13 mentioning a way to test video which is VERY applicable here as a way to test this PR. #1035 I recommend we test in this manner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the record, in #1019 I Implemented such tests on t values, so no need to implement this here. |
||
def construct(self): | ||
tick_start = 1.0 | ||
tick_end = 3.0 | ||
val_tracker = mn.ValueTracker(tick_start) | ||
square = mn.Square(fill_opacity=1).set_stroke(width=0) | ||
self.add(square) | ||
num_colors = 1000 | ||
cols = mn.color_gradient([C.RED, C.WHITE, C.BLUE], num_colors) | ||
|
||
def col_uptater(mob): | ||
integ = int( | ||
(val_tracker.get_value() - tick_start) | ||
/ (tick_end - tick_start) | ||
* (num_colors - 1) | ||
) | ||
mob.set_color(cols[integ]) | ||
|
||
square.add_updater(col_uptater) | ||
self.play(val_tracker.set_value, tick_end, rate_func=mn.linear, run_time=3) | ||
|
||
|
||
MODULE_NAME = "last_frame" | ||
|
||
|
||
@pytest.mark.parametrize("scene_to_test", get_scenes_to_test(__name__), indirect=False) | ||
def test_scene(scene_to_test, tmpdir, show_diff): | ||
GraphicalUnitTester(scene_to_test[1], MODULE_NAME, tmpdir).test(show_diff=show_diff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close any open pipes