mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Add scale_stroke_with_zoom option to VMobject
This commit is contained in:
parent
e19ceaaff0
commit
54c8a9014b
2 changed files with 17 additions and 4 deletions
|
@ -94,6 +94,7 @@ class VMobject(Mobject):
|
|||
# Could also be "no_joint", "bevel", "miter"
|
||||
joint_type: str = "auto",
|
||||
flat_stroke: bool = False,
|
||||
scale_stroke_with_zoom: bool = False,
|
||||
use_simple_quadratic_approx: bool = False,
|
||||
# Measured in pixel widths
|
||||
anti_alias_width: float = 1.5,
|
||||
|
@ -110,6 +111,7 @@ class VMobject(Mobject):
|
|||
self.long_lines = long_lines
|
||||
self.joint_type = joint_type
|
||||
self.flat_stroke = flat_stroke
|
||||
self.scale_stroke_with_zoom = scale_stroke_with_zoom
|
||||
self.use_simple_quadratic_approx = use_simple_quadratic_approx
|
||||
self.anti_alias_width = anti_alias_width
|
||||
self.fill_border_width = fill_border_width
|
||||
|
@ -126,9 +128,12 @@ class VMobject(Mobject):
|
|||
|
||||
def init_uniforms(self):
|
||||
super().init_uniforms()
|
||||
self.uniforms["anti_alias_width"] = self.anti_alias_width
|
||||
self.uniforms["joint_type"] = JOINT_TYPE_MAP[self.joint_type]
|
||||
self.uniforms["flat_stroke"] = float(self.flat_stroke)
|
||||
self.uniforms.update(
|
||||
anti_alias_width=self.anti_alias_width,
|
||||
joint_type=JOINT_TYPE_MAP[self.joint_type],
|
||||
flat_stroke=float(self.flat_stroke),
|
||||
scale_stroke_with_zoom=float(self.scale_stroke_with_zoom)
|
||||
)
|
||||
|
||||
def add(self, *vmobjects: VMobject) -> Self:
|
||||
if not all((isinstance(m, VMobject) for m in vmobjects)):
|
||||
|
@ -399,6 +404,13 @@ class VMobject(Mobject):
|
|||
def get_flat_stroke(self) -> bool:
|
||||
return self.uniforms["flat_stroke"] == 1.0
|
||||
|
||||
def set_scale_stroke_with_zoom(self, scale_stroke_with_zoom: bool = True, recurse: bool = True) -> Self:
|
||||
self.set_uniform(recurse, scale_stroke_with_zoom=float(scale_stroke_with_zoom))
|
||||
pass
|
||||
|
||||
def get_scale_stroke_with_zoom(self) -> bool:
|
||||
return self.uniforms["flat_stroke"] == 1.0
|
||||
|
||||
def set_joint_type(self, joint_type: str, recurse: bool = True) -> Self:
|
||||
for mob in self.get_family(recurse):
|
||||
mob.uniforms["joint_type"] = JOINT_TYPE_MAP[joint_type]
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
uniform float frame_scale;
|
||||
uniform float is_fixed_in_frame;
|
||||
uniform float scale_stroke_with_zoom;
|
||||
|
||||
in vec3 point;
|
||||
in vec4 stroke_rgba;
|
||||
|
@ -22,7 +23,7 @@ const float STROKE_WIDTH_CONVERSION = 0.01;
|
|||
void main(){
|
||||
verts = point;
|
||||
v_color = stroke_rgba;
|
||||
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * mix(frame_scale, 1, is_fixed_in_frame);
|
||||
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * mix(frame_scale, 1, scale_stroke_with_zoom);
|
||||
v_joint_angle = joint_angle;
|
||||
v_unit_normal = unit_normal;
|
||||
}
|
Loading…
Add table
Reference in a new issue