From 7474ae17b054f3f2f56480d093afde19906ff29a Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 20 Aug 2024 11:52:05 -0500 Subject: [PATCH] Change default to flat stroke, except in 3d situations --- manimlib/mobject/coordinate_systems.py | 2 ++ manimlib/mobject/geometry.py | 2 -- manimlib/mobject/three_dimensions.py | 2 ++ manimlib/mobject/types/vectorized_mobject.py | 4 ++-- manimlib/scene/scene.py | 4 +++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/manimlib/mobject/coordinate_systems.py b/manimlib/mobject/coordinate_systems.py index eb0c0b83..0c91492d 100644 --- a/manimlib/mobject/coordinate_systems.py +++ b/manimlib/mobject/coordinate_systems.py @@ -530,6 +530,7 @@ class ThreeDAxes(Axes): z_axis_config: dict = dict(), z_normal: Vect3 = DOWN, depth: float | None = None, + flat_stroke: bool = False, **kwargs ): Axes.__init__(self, x_range, y_range, **kwargs) @@ -553,6 +554,7 @@ class ThreeDAxes(Axes): self.z_axis.shift(self.x_axis.n2p(0)) 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] diff --git a/manimlib/mobject/geometry.py b/manimlib/mobject/geometry.py index e1151aed..2f1a4730 100644 --- a/manimlib/mobject/geometry.py +++ b/manimlib/mobject/geometry.py @@ -642,7 +642,6 @@ class Arrow(Line): end: Vect3 | Mobject, stroke_color: ManimColor = GREY_A, stroke_width: float = 5, - flat_stroke: bool = True, buff: float = 0.25, tip_width_ratio: float = 5, tip_len_to_width: float = 0.0075, @@ -660,7 +659,6 @@ class Arrow(Line): start, end, stroke_color=stroke_color, stroke_width=stroke_width, - flat_stroke=flat_stroke, buff=buff, **kwargs ) diff --git a/manimlib/mobject/three_dimensions.py b/manimlib/mobject/three_dimensions.py index d29b7ec2..73daa58a 100644 --- a/manimlib/mobject/three_dimensions.py +++ b/manimlib/mobject/three_dimensions.py @@ -38,6 +38,7 @@ class SurfaceMesh(VGroup): normal_nudge: float = 1e-2, depth_test: bool = True, joint_type: str = 'no_joint', + flat_stroke: bool = False, **kwargs ): self.uv_surface = uv_surface @@ -49,6 +50,7 @@ class SurfaceMesh(VGroup): stroke_width=stroke_width, depth_test=depth_test, joint_type=joint_type, + flat_stroke=flat_stroke, **kwargs ) diff --git a/manimlib/mobject/types/vectorized_mobject.py b/manimlib/mobject/types/vectorized_mobject.py index dc2d8e9d..3ead48a8 100644 --- a/manimlib/mobject/types/vectorized_mobject.py +++ b/manimlib/mobject/types/vectorized_mobject.py @@ -90,7 +90,7 @@ class VMobject(Mobject): long_lines: bool = False, # Could also be "no_joint", "bevel", "miter" joint_type: str = "auto", - flat_stroke: bool = False, + flat_stroke: bool = True, use_simple_quadratic_approx: bool = False, # Measured in pixel widths anti_alias_width: float = 1.5, @@ -393,7 +393,7 @@ class VMobject(Mobject): return self.get_stroke_opacity() def set_flat_stroke(self, flat_stroke: bool = True, recurse: bool = True) -> Self: - self.set_uniform(recurse, flat_stroke=flat_stroke) + self.set_uniform(recurse, flat_stroke=float(flat_stroke)) return self def get_flat_stroke(self) -> bool: diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index c2a05bb7..ea9caf5c 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -1049,8 +1049,10 @@ class ThreeDScene(Scene): default_frame_orientation = (-30, 70) always_depth_test = True - def add(self, *mobjects: Mobject, set_depth_test: bool = True): + def add(self, *mobjects: Mobject, set_depth_test: bool = True, perp_stroke: bool = True): for mob in mobjects: if set_depth_test and not mob.is_fixed_in_frame() and self.always_depth_test: mob.apply_depth_test() + if isinstance(mob, VMobject) and mob.has_stroke() and perp_stroke: + mob.set_flat_stroke(False) super().add(*mobjects)