Skip to content

Commit

Permalink
Merge pull request 3b1b#1864 from 3b1b/video-work
Browse files Browse the repository at this point in the history
Video work
  • Loading branch information
3b1b committed Sep 13, 2022
2 parents d2e570e + 88f2ae6 commit abe52a6
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
4 changes: 0 additions & 4 deletions manimlib/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ def set_ctx_blending(self, enable: bool = True) -> None:
self.ctx.enable(moderngl.BLEND)
else:
self.ctx.disable(moderngl.BLEND)
self.ctx.blend_func = (
moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA,
# moderngl.ONE, moderngl.ONE
)

def set_ctx_depth_test(self, enable: bool = True) -> None:
if enable:
Expand Down
15 changes: 11 additions & 4 deletions manimlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from manimlib.logger import log
from manimlib.utils.config_ops import merge_dicts_recursively
from manimlib.utils.init_config import init_customization
from manimlib.constants import FRAME_HEIGHT


__config_file__ = "custom_config.yml"
Expand Down Expand Up @@ -228,10 +229,10 @@ def insert_embed_line(file_name: str, scene_name: str, line_marker: str):
n_spaces = get_indent(line) + 4
elif in_construct:
if len(line.strip()) > 0 and get_indent(line) < n_spaces:
prev_line_num = index - 2
prev_line_num = index - 1
break
if prev_line_num is None:
prev_line_num = len(lines) - 2
prev_line_num = len(lines) - 1
elif line_marker.isdigit():
# Treat the argument as a line number
prev_line_num = int(line_marker) - 1
Expand Down Expand Up @@ -392,10 +393,11 @@ def get_configuration(args):
monitors = get_monitors()
mon_index = custom_config["window_monitor"]
monitor = monitors[min(mon_index, len(monitors) - 1)]
aspect_ratio = config["camera_config"]["pixel_width"] / config["camera_config"]["pixel_height"]
window_width = monitor.width
if not (args.full_screen or custom_config["full_screen"]):
window_width //= 2
window_height = window_width * 9 // 16
window_height = int(window_width / aspect_ratio)
config["window_config"] = {
"size": (window_width, window_height),
}
Expand All @@ -416,7 +418,9 @@ def get_configuration(args):
def get_camera_configuration(args, custom_config):
camera_config = {}
camera_resolutions = get_custom_config()["camera_resolutions"]
if args.low_quality:
if args.resolution:
resolution = args.resolution
elif args.low_quality:
resolution = camera_resolutions["low"]
elif args.medium_quality:
resolution = camera_resolutions["med"]
Expand All @@ -439,6 +443,9 @@ def get_camera_configuration(args, custom_config):
camera_config.update({
"pixel_width": width,
"pixel_height": height,
"frame_config": {
"frame_shape": ((width / height) * FRAME_HEIGHT, FRAME_HEIGHT),
},
"fps": fps,
})

Expand Down
1 change: 1 addition & 0 deletions manimlib/mobject/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def get_riemann_rectangles(
x_range = [*x_range, dx]

rects = []
x_range[1] = x_range[1] + dx
xs = np.arange(*x_range)
for x0, x1 in zip(xs, xs[1:]):
if input_sample_type == "left":
Expand Down
9 changes: 7 additions & 2 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def reverse_points(self):
for mob in self.get_family():
for key in mob.data:
mob.data[key] = mob.data[key][::-1]
self.refresh_unit_normal()
return self

def apply_points_function(
Expand Down Expand Up @@ -634,13 +633,19 @@ def become(self, mobject: Mobject):
to another mobject
"""
self.align_family(mobject)
for sm1, sm2 in zip(self.get_family(), mobject.get_family()):
family1 = self.get_family()
family2 = mobject.get_family()
for sm1, sm2 in zip(family1, family2):
sm1.set_data(sm2.data)
sm1.set_uniforms(sm2.uniforms)
sm1.shader_folder = sm2.shader_folder
sm1.texture_paths = sm2.texture_paths
sm1.depth_test = sm2.depth_test
sm1.render_primitive = sm2.render_primitive
# Make sure named family members carry over
for attr, value in list(mobject.__dict__.items()):
if isinstance(value, Mobject) and value in family2:
setattr(self, attr, family1[family2.index(value)])
self.refresh_bounding_box(recurse_down=True)
self.match_updaters(mobject)
return self
Expand Down
36 changes: 19 additions & 17 deletions manimlib/mobject/svg/drawings.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ class Bubble(SVGMobject):
CONFIG = {
"direction": LEFT,
"center_point": ORIGIN,
"content_scale_factor": 0.75,
"content_scale_factor": 0.7,
"height": 5,
"width": 8,
"max_height": None,
"max_width": None,
"bubble_center_adjustment_factor": 1. / 8,
"file_name": None,
"fill_color": BLACK,
Expand All @@ -313,8 +315,12 @@ def __init__(self, **kwargs):
raise Exception("Must invoke Bubble subclass")
SVGMobject.__init__(self, self.file_name, **kwargs)
self.center()
self.stretch_to_fit_height(self.height)
self.stretch_to_fit_width(self.width)
self.set_height(self.height, stretch=True)
self.set_width(self.width, stretch=True)
if self.max_height:
self.set_max_height(self.max_height)
if self.max_width:
self.set_max_width(self.max_width)
if self.direction[0] > 0:
self.flip()
if "direction" in kwargs:
Expand Down Expand Up @@ -360,12 +366,9 @@ def pin_to(self, mobject):
return self

def position_mobject_inside(self, mobject):
scaled_width = self.content_scale_factor * self.get_width()
if mobject.get_width() > scaled_width:
mobject.set_width(scaled_width)
mobject.shift(
self.get_bubble_center() - mobject.get_center()
)
mobject.set_max_width(self.content_scale_factor * self.get_width())
mobject.set_max_height(self.content_scale_factor * self.get_height() / 1.5)
mobject.shift(self.get_bubble_center() - mobject.get_center())
return mobject

def add_content(self, mobject):
Expand All @@ -377,15 +380,14 @@ def write(self, *text):
self.add_content(TexText(*text))
return self

def resize_to_content(self):
target_width = self.content.get_width()
target_width += max(MED_LARGE_BUFF, 2)
target_height = self.content.get_height()
target_height += 2.5 * LARGE_BUFF
def resize_to_content(self, buff=0.75):
width = self.content.get_width()
height = self.content.get_height()
target_width = width + min(buff, height)
target_height = 1.35 * (self.content.get_height() + buff)
tip_point = self.get_tip()
self.stretch_to_fit_width(target_width)
self.stretch_to_fit_height(target_height)
self.move_tip_to(tip_point)
self.stretch_to_fit_width(target_width, about_point=tip_point)
self.stretch_to_fit_height(target_height, about_point=tip_point)
self.position_mobject_inside(self.content)

def clear(self):
Expand Down
5 changes: 5 additions & 0 deletions manimlib/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ def refresh_unit_normal(self):
mob.get_unit_normal(recompute=True)
return self

def reverse_points(self):
super().reverse_points()
self.refresh_unit_normal()
return self

# Alignment
def align_points(self, vmobject: VMobject):
if self.get_num_points() == len(vmobject.get_points()):
Expand Down
2 changes: 1 addition & 1 deletion manimlib/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def on_key_press(
return

if char == RESET_FRAME_KEY:
self.camera.frame.to_default_state()
self.play(self.camera.frame.animate.to_default_state())
elif char == "z" and modifiers == COMMAND_MODIFIER:
self.undo()
elif char == "z" and modifiers == COMMAND_MODIFIER | SHIFT_MODIFIER:
Expand Down
2 changes: 1 addition & 1 deletion manimlib/shaders/quadratic_bezier_stroke/vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ void main(){
next_bp = position_point_into_frame(next_point);
v_global_unit_normal = rotate_point_into_frame(unit_normal);

v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width;
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * frame_shape[1] / 8.0;
v_color = color;
}

0 comments on commit abe52a6

Please sign in to comment.