mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 12:07:45 +00:00
Enable recording during a Scene embed
This commit is contained in:
parent
e2421a650c
commit
8a6deb4068
5 changed files with 46 additions and 13 deletions
|
|
@ -507,11 +507,10 @@ class Camera(object):
|
|||
view_matrix = frame.get_view_matrix()
|
||||
light_pos = self.light_source.get_location()
|
||||
cam_pos = self.frame.get_implied_camera_location()
|
||||
frame_shape = frame.get_shape()
|
||||
|
||||
self.perspective_uniforms.update(
|
||||
frame_shape=frame_shape,
|
||||
pixel_size=frame_shape[0] / self.get_pixel_shape()[0],
|
||||
frame_shape=frame.get_shape(),
|
||||
pixel_size=self.get_pixel_size(),
|
||||
view=tuple(view_matrix.T.flatten()),
|
||||
camera_position=tuple(cam_pos),
|
||||
light_position=tuple(light_pos),
|
||||
|
|
|
|||
|
|
@ -415,6 +415,7 @@ def get_window_config(args: Namespace, custom_config: dict, camera_config: dict)
|
|||
window_width //= 2
|
||||
window_height = int(window_width / aspect_ratio)
|
||||
return dict(
|
||||
full_size=(camera_config["pixel_width"], camera_config["pixel_height"]),
|
||||
size=(window_width, window_height),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -711,7 +711,7 @@ class Scene(object):
|
|||
self.restore_state(self.redo_stack.pop())
|
||||
self.refresh_static_mobjects()
|
||||
|
||||
def checkpoint_paste(self, skip: bool = False):
|
||||
def checkpoint_paste(self, skip: bool = False, record: bool = False):
|
||||
"""
|
||||
Used during interactive development to run (or re-run)
|
||||
a block of scene code.
|
||||
|
|
@ -721,7 +721,7 @@ class Scene(object):
|
|||
was called on a block of code starting with that comment.
|
||||
"""
|
||||
shell = get_ipython()
|
||||
if shell is None:
|
||||
if shell is None or self.window is None:
|
||||
raise Exception(
|
||||
"Scene.checkpoint_paste cannot be called outside of " +
|
||||
"an ipython shell"
|
||||
|
|
@ -738,8 +738,20 @@ class Scene(object):
|
|||
prev_skipping = self.skip_animations
|
||||
self.skip_animations = skip
|
||||
|
||||
if record:
|
||||
# Resize window so rendering happens at the appropriate size
|
||||
self.window.size = self.camera.get_pixel_shape()
|
||||
self.window.swap_buffers()
|
||||
self.update_frame()
|
||||
self.file_writer.begin_insert()
|
||||
|
||||
shell.run_cell(pasted)
|
||||
|
||||
if record:
|
||||
self.file_writer.end_insert()
|
||||
# Put window back to how it started
|
||||
self.window.to_default_position()
|
||||
|
||||
self.skip_animations = prev_skipping
|
||||
|
||||
def checkpoint(self, key: str):
|
||||
|
|
|
|||
|
|
@ -288,6 +288,25 @@ class SceneFileWriter(object):
|
|||
)
|
||||
self.set_progress_display_description()
|
||||
|
||||
def begin_insert(self):
|
||||
# Begin writing process
|
||||
self.write_to_movie = True
|
||||
self.init_output_directories()
|
||||
movie_path = self.get_movie_file_path()
|
||||
folder, file = os.path.split(movie_path)
|
||||
scene_name, ext = file.split(".")
|
||||
n_inserts = len(list(filter(
|
||||
lambda f: f.startswith(scene_name + "_insert"),
|
||||
os.listdir(folder)
|
||||
)))
|
||||
self.inserted_file_path = movie_path.replace(".", f"_insert_{n_inserts}.")
|
||||
self.open_movie_pipe(self.inserted_file_path)
|
||||
|
||||
def end_insert(self):
|
||||
self.close_movie_pipe()
|
||||
self.write_to_movie = False
|
||||
self.print_file_ready_message(self.inserted_file_path)
|
||||
|
||||
def has_progress_display(self):
|
||||
return self.progress_display is not None
|
||||
|
||||
|
|
|
|||
|
|
@ -26,10 +26,14 @@ class Window(PygletWindow):
|
|||
self,
|
||||
scene: Scene,
|
||||
size: tuple[int, int] = (1280, 720),
|
||||
full_size: tuple[int, int] = (1920, 1080),
|
||||
samples = 0
|
||||
):
|
||||
super().__init__(size=size, samples=samples)
|
||||
super().__init__(size=full_size, samples=samples)
|
||||
|
||||
self.full_size = full_size
|
||||
self.default_size = size
|
||||
self.default_position = self.find_initial_position(size)
|
||||
self.scene = scene
|
||||
self.pressed_keys = set()
|
||||
self.title = str(scene)
|
||||
|
|
@ -40,13 +44,11 @@ class Window(PygletWindow):
|
|||
self.config = mglw.WindowConfig(ctx=self.ctx, wnd=self, timer=self.timer)
|
||||
self.timer.start()
|
||||
|
||||
# No idea why, but when self.position is set once
|
||||
# it sometimes doesn't actually change the position
|
||||
# to the specified tuple on the rhs, but doing it
|
||||
# twice seems to make it work. ¯\_(ツ)_/¯
|
||||
initial_position = self.find_initial_position(size)
|
||||
self.position = initial_position
|
||||
self.position = initial_position
|
||||
self.to_default_position()
|
||||
|
||||
def to_default_position(self):
|
||||
self.size = self.default_size
|
||||
self.position = self.default_position
|
||||
|
||||
def find_initial_position(self, size: tuple[int, int]) -> tuple[int, int]:
|
||||
custom_position = get_customization()["window_position"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue