From 0ce972991be01a59d9186071ac03230887160c82 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 8 Feb 2023 19:39:22 -0800 Subject: [PATCH 1/9] Remove num_axis_pieces arg from ThreeDAxes --- manimlib/mobject/coordinate_systems.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/manimlib/mobject/coordinate_systems.py b/manimlib/mobject/coordinate_systems.py index e1f1d961..f1b43a32 100644 --- a/manimlib/mobject/coordinate_systems.py +++ b/manimlib/mobject/coordinate_systems.py @@ -508,7 +508,6 @@ class ThreeDAxes(Axes): z_axis_config: dict = dict(), z_normal: Vect3 = DOWN, depth: float = 6.0, - num_axis_pieces: int = 20, **kwargs ): Axes.__init__(self, x_range, y_range, **kwargs) @@ -533,8 +532,6 @@ class ThreeDAxes(Axes): self.axes.add(self.z_axis) self.add(self.z_axis) - for axis in self.axes: - axis.insert_n_curves(num_axis_pieces - 1) def get_all_ranges(self) -> list[Sequence[float]]: return [self.x_range, self.y_range, self.z_range] From 169e7a302b45c6887550c296f03b578ecf942a83 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 8 Feb 2023 19:39:37 -0800 Subject: [PATCH 2/9] Give ThreeDAxes flat stroke by default --- manimlib/mobject/coordinate_systems.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manimlib/mobject/coordinate_systems.py b/manimlib/mobject/coordinate_systems.py index f1b43a32..615eed7d 100644 --- a/manimlib/mobject/coordinate_systems.py +++ b/manimlib/mobject/coordinate_systems.py @@ -508,6 +508,7 @@ class ThreeDAxes(Axes): z_axis_config: dict = dict(), z_normal: Vect3 = DOWN, depth: float = 6.0, + flat_stroke: bool = False, **kwargs ): Axes.__init__(self, x_range, y_range, **kwargs) @@ -532,6 +533,7 @@ class ThreeDAxes(Axes): self.axes.add(self.z_axis) self.add(self.z_axis) + self.set_flat_stroke(flat_stroke) def get_all_ranges(self) -> list[Sequence[float]]: return [self.x_range, self.y_range, self.z_range] From f2c07afe748fdb7b0734b43f7caf5d9bc0aacf72 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 8 Feb 2023 19:39:49 -0800 Subject: [PATCH 3/9] add 'return self' --- manimlib/mobject/types/vectorized_mobject.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manimlib/mobject/types/vectorized_mobject.py b/manimlib/mobject/types/vectorized_mobject.py index 8d60f019..dc5e6efa 100644 --- a/manimlib/mobject/types/vectorized_mobject.py +++ b/manimlib/mobject/types/vectorized_mobject.py @@ -541,6 +541,7 @@ class VMobject(Mobject): else: new_handle = self.get_reflection_of_last_handle() self.add_cubic_bezier_curve_to(new_handle, handle, point) + return self def has_new_path_started(self) -> bool: points = self.get_points() From ded06c1f888b389c9d31769bda661300f4af3f64 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 8 Feb 2023 19:41:07 -0800 Subject: [PATCH 4/9] Give SceneFileWriter an option for saturation, and set default to 1.7 The colors in a scene can look a little different in a preview window vs. in the rendered file written by ffmpeg. This is mean to bring them closer together. --- manimlib/scene/scene_file_writer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index fdcabb8f..3b5a32bc 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -49,6 +49,7 @@ class SceneFileWriter(object): progress_description_len: int = 40, video_codec: str = "libx264", pixel_format: str = "yuv420p", + saturation: float = 1.7 ): self.scene: Scene = scene self.write_to_movie = write_to_movie @@ -67,6 +68,7 @@ class SceneFileWriter(object): self.progress_description_len = progress_description_len self.video_codec = video_codec self.pixel_format = pixel_format + self.saturation = saturation # State during file writing self.writing_process: sp.Popen | None = None @@ -262,7 +264,7 @@ class SceneFileWriter(object): '-pix_fmt', 'rgba', '-r', str(fps), # frames per second '-i', '-', # The input comes from a pipe - '-vf', 'vflip', + '-vf', f'eq=saturation={self.saturation},vflip', '-an', # Tells FFMPEG not to expect any audio '-loglevel', 'error', ] From 3e3e4de5e9d819658e9d9b39556f38d42b65208d Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 8 Feb 2023 20:09:33 -0800 Subject: [PATCH 5/9] Add option for gamma correction to SceneFileWriter --- manimlib/scene/scene_file_writer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index 3b5a32bc..53bbb589 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -49,7 +49,8 @@ class SceneFileWriter(object): progress_description_len: int = 40, video_codec: str = "libx264", pixel_format: str = "yuv420p", - saturation: float = 1.7 + saturation: float = 1.7, + gamma: float = 1.2, ): self.scene: Scene = scene self.write_to_movie = write_to_movie @@ -69,6 +70,7 @@ class SceneFileWriter(object): self.video_codec = video_codec self.pixel_format = pixel_format self.saturation = saturation + self.gamma = gamma # State during file writing self.writing_process: sp.Popen | None = None @@ -264,7 +266,7 @@ class SceneFileWriter(object): '-pix_fmt', 'rgba', '-r', str(fps), # frames per second '-i', '-', # The input comes from a pipe - '-vf', f'eq=saturation={self.saturation},vflip', + '-vf', f'vflip,eq=saturation={self.saturation}:gamma={self.gamma}', '-an', # Tells FFMPEG not to expect any audio '-loglevel', 'error', ] From b39fbb62f41fa2f813ac44efb57e45427b306830 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 9 Feb 2023 15:16:10 -0800 Subject: [PATCH 6/9] Ensure joint_products are refreshed for _AnimationBuilder --- manimlib/animation/transform.py | 2 +- manimlib/mobject/types/vectorized_mobject.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/manimlib/animation/transform.py b/manimlib/animation/transform.py index fdc262a9..1281ddc2 100644 --- a/manimlib/animation/transform.py +++ b/manimlib/animation/transform.py @@ -63,7 +63,7 @@ class Transform(Animation): # preserved, since calling align_data will potentially # change the structure of both arguments self.target_copy = self.target_mobject.copy() - self.mobject.align_data_and_family(self.target_copy) + self.mobject.align_data_and_family(self.target_copy) super().begin() if not self.mobject.has_updaters: self.mobject.lock_matching_data( diff --git a/manimlib/mobject/types/vectorized_mobject.py b/manimlib/mobject/types/vectorized_mobject.py index dc5e6efa..72b287af 100644 --- a/manimlib/mobject/types/vectorized_mobject.py +++ b/manimlib/mobject/types/vectorized_mobject.py @@ -899,6 +899,8 @@ class VMobject(Mobject): self.has_same_shape_as(vmobject) if match_tris: vmobject.triangulation = self.triangulation + for mob in [self, vmobject]: + mob.get_joint_products() return self for mob in self, vmobject: From ad409999dcd06fae8d2c26bd5c40947133ae97af Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 9 Feb 2023 15:16:33 -0800 Subject: [PATCH 7/9] Small tweak --- manimlib/mobject/mobject.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.py index 2f974389..9f4f2a18 100644 --- a/manimlib/mobject/mobject.py +++ b/manimlib/mobject/mobject.py @@ -2178,7 +2178,7 @@ class _AnimationBuilder: if (self.is_chaining and has_overridden_animation) or self.overridden_animation: raise NotImplementedError( - "Method chaining is currently not supported for " + "Method chaining is currently not supported for " + \ "overridden animations" ) @@ -2213,7 +2213,7 @@ class _AnimationBuilder: if not self.can_pass_args: raise ValueError( - "Animation arguments can only be passed by calling ``animate`` " + "Animation arguments can only be passed by calling ``animate`` " + \ "or ``set_anim_args`` and can only be passed once", ) From 01c51dbc6d7bf66d380bddd0e82679442fd513f8 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 9 Feb 2023 15:16:51 -0800 Subject: [PATCH 8/9] animation.update_config -> animation.update_rate_info --- manimlib/mobject/mobject_update_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manimlib/mobject/mobject_update_utils.py b/manimlib/mobject/mobject_update_utils.py index 4fdcfecd..d47270ff 100644 --- a/manimlib/mobject/mobject_update_utils.py +++ b/manimlib/mobject/mobject_update_utils.py @@ -93,7 +93,7 @@ def turn_animation_into_updater( the updater will be popped uplon completion """ mobject = animation.mobject - animation.update_config(**kwargs) + animation.update_rate_info(**kwargs) animation.suspend_mobject_updating = False animation.begin() animation.total_time = 0 From 557cb66c52d3cabe19a8013e5edfcd24f86231b8 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 15 Feb 2023 09:38:35 -0800 Subject: [PATCH 9/9] Fix transparent background videos --- manimlib/config.py | 3 ++- manimlib/scene/scene_file_writer.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/manimlib/config.py b/manimlib/config.py index bb5e57ef..1de7bbd7 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -420,11 +420,12 @@ def get_file_writer_config(args: Namespace, custom_config: dict) -> dict: result["video_codec"] = args.vcodec elif args.transparent: result["video_codec"] = 'prores_ks' + result["pixel_format"] = '' elif args.gif: result["video_codec"] = '' if args.pix_fmt: - result["pix_fmt"] = args.pix_fmt + result["pixel_format"] = args.pix_fmt return result diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index 53bbb589..47698d0d 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -258,6 +258,10 @@ class SceneFileWriter(object): fps = self.scene.camera.fps width, height = self.scene.camera.get_pixel_shape() + vf_arg = 'vflip' + if self.pixel_format.startswith("yuv"): + vf_arg += f',eq=saturation={self.saturation}:gamma={self.gamma}' + command = [ FFMPEG_BIN, '-y', # overwrite output file if it exists @@ -266,7 +270,7 @@ class SceneFileWriter(object): '-pix_fmt', 'rgba', '-r', str(fps), # frames per second '-i', '-', # The input comes from a pipe - '-vf', f'vflip,eq=saturation={self.saturation}:gamma={self.gamma}', + '-vf', vf_arg, '-an', # Tells FFMPEG not to expect any audio '-loglevel', 'error', ]