mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Remove distinction between moving mobjects and static mobjects...computations to figure this out may now outweigh the actual render times they save
This commit is contained in:
parent
5df2d3db33
commit
cfbcd9faa8
5 changed files with 21 additions and 46 deletions
|
@ -12,8 +12,6 @@ from manimlib.constants import *
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.iterables import batch_by_property
|
from manimlib.utils.iterables import batch_by_property
|
||||||
from manimlib.utils.iterables import list_difference_update
|
|
||||||
from manimlib.utils.family_ops import extract_mobject_family_members
|
|
||||||
from manimlib.utils.simple_functions import fdiv
|
from manimlib.utils.simple_functions import fdiv
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +81,7 @@ class Camera(object):
|
||||||
moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA,
|
moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA,
|
||||||
moderngl.ONE, moderngl.ONE
|
moderngl.ONE, moderngl.ONE
|
||||||
)
|
)
|
||||||
|
self.background_fbo = None
|
||||||
|
|
||||||
# Methods associated with the frame buffer
|
# Methods associated with the frame buffer
|
||||||
def get_fbo(self):
|
def get_fbo(self):
|
||||||
|
@ -113,14 +112,6 @@ class Camera(object):
|
||||||
rgba = (*Color(self.background_color).get_rgb(), self.background_opacity)
|
rgba = (*Color(self.background_color).get_rgb(), self.background_opacity)
|
||||||
self.fbo.clear(*rgba)
|
self.fbo.clear(*rgba)
|
||||||
|
|
||||||
def lock_state_as_background(self):
|
|
||||||
# TODO, somehow do this by creating a Texture
|
|
||||||
# and adding it to the queue like an image mobject
|
|
||||||
pass
|
|
||||||
|
|
||||||
def unlock_background(self):
|
|
||||||
pass # TODO
|
|
||||||
|
|
||||||
def reset_pixel_shape(self, new_width, new_height):
|
def reset_pixel_shape(self, new_width, new_height):
|
||||||
self.pixel_width = new_width
|
self.pixel_width = new_width
|
||||||
self.pixel_height = new_height
|
self.pixel_height = new_height
|
||||||
|
@ -208,6 +199,7 @@ class Camera(object):
|
||||||
])
|
])
|
||||||
|
|
||||||
# TODO, account for 3d
|
# TODO, account for 3d
|
||||||
|
# Also, move this to CameraFrame?
|
||||||
def is_in_frame(self, mobject):
|
def is_in_frame(self, mobject):
|
||||||
fc = self.get_frame_center()
|
fc = self.get_frame_center()
|
||||||
fh = self.get_frame_height()
|
fh = self.get_frame_height()
|
||||||
|
@ -220,20 +212,7 @@ class Camera(object):
|
||||||
])
|
])
|
||||||
|
|
||||||
# Rendering
|
# Rendering
|
||||||
def get_mobjects_to_display(self, mobjects, excluded_mobjects=None):
|
def capture(self, *mobjects, **kwargs):
|
||||||
mobjects = extract_mobject_family_members(
|
|
||||||
mobjects, only_those_with_points=True,
|
|
||||||
)
|
|
||||||
if excluded_mobjects:
|
|
||||||
all_excluded = extract_mobject_family_members(excluded_mobjects)
|
|
||||||
mobjects = list_difference_update(mobjects, all_excluded)
|
|
||||||
return mobjects
|
|
||||||
|
|
||||||
def capture_mobject(self, mobject, **kwargs):
|
|
||||||
return self.capture_mobjects([mobject], **kwargs)
|
|
||||||
|
|
||||||
def capture_mobjects(self, mobjects, **kwargs):
|
|
||||||
mobjects = self.get_mobjects_to_display(mobjects, **kwargs)
|
|
||||||
shader_infos = list(it.chain(*[
|
shader_infos = list(it.chain(*[
|
||||||
mob.get_shader_info_list()
|
mob.get_shader_info_list()
|
||||||
for mob in mobjects
|
for mob in mobjects
|
||||||
|
|
|
@ -9,6 +9,7 @@ from manimlib.utils.config_ops import digest_config
|
||||||
# map their centers but remain otherwise undistorted (useful for labels, etc.)
|
# map their centers but remain otherwise undistorted (useful for labels, etc.)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO, this class is deprecated
|
||||||
class MappingCamera(Camera):
|
class MappingCamera(Camera):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"mapping_func": lambda p: p,
|
"mapping_func": lambda p: p,
|
||||||
|
|
|
@ -54,11 +54,6 @@ class MovingCamera(Camera):
|
||||||
def set_frame_center(self, frame_center):
|
def set_frame_center(self, frame_center):
|
||||||
self.frame.move_to(frame_center)
|
self.frame.move_to(frame_center)
|
||||||
|
|
||||||
def capture_mobjects(self, mobjects, **kwargs):
|
|
||||||
# self.reset_frame_center()
|
|
||||||
# self.realign_frame_shape()
|
|
||||||
Camera.capture_mobjects(self, mobjects, **kwargs)
|
|
||||||
|
|
||||||
# Since the frame can be moving around, the cairo
|
# Since the frame can be moving around, the cairo
|
||||||
# context used for updating should be regenerated
|
# context used for updating should be regenerated
|
||||||
# at each frame. So no caching.
|
# at each frame. So no caching.
|
||||||
|
|
|
@ -41,9 +41,9 @@ class ThreeDCamera(Camera):
|
||||||
self.fixed_in_frame_mobjects = set()
|
self.fixed_in_frame_mobjects = set()
|
||||||
self.reset_rotation_matrix()
|
self.reset_rotation_matrix()
|
||||||
|
|
||||||
def capture_mobjects(self, mobjects, **kwargs):
|
def capture(self, *mobjects, **kwargs):
|
||||||
self.reset_rotation_matrix()
|
self.reset_rotation_matrix()
|
||||||
Camera.capture_mobjects(self, mobjects, **kwargs)
|
Camera.capture(self, *mobjects, **kwargs)
|
||||||
|
|
||||||
def get_value_trackers(self):
|
def get_value_trackers(self):
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -16,6 +16,7 @@ from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.scene.scene_file_writer import SceneFileWriter
|
from manimlib.scene.scene_file_writer import SceneFileWriter
|
||||||
from manimlib.utils.family_ops import extract_mobject_family_members
|
from manimlib.utils.family_ops import extract_mobject_family_members
|
||||||
from manimlib.utils.family_ops import restructure_list_to_exclude_certain_family_members
|
from manimlib.utils.family_ops import restructure_list_to_exclude_certain_family_members
|
||||||
|
from manimlib.utils.iterables import list_difference_update
|
||||||
from manimlib.window import Window
|
from manimlib.window import Window
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ class Scene(Container):
|
||||||
self.camera = self.camera_class(**self.camera_config)
|
self.camera = self.camera_class(**self.camera_config)
|
||||||
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
|
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
|
||||||
self.mobjects = []
|
self.mobjects = []
|
||||||
|
self.displayed_mobjects = []
|
||||||
self.num_plays = 0
|
self.num_plays = 0
|
||||||
self.time = 0
|
self.time = 0
|
||||||
self.original_skipping_status = self.skip_animations
|
self.original_skipping_status = self.skip_animations
|
||||||
|
@ -120,20 +122,14 @@ class Scene(Container):
|
||||||
def get_image(self):
|
def get_image(self):
|
||||||
return self.camera.get_image()
|
return self.camera.get_image()
|
||||||
|
|
||||||
def update_frame(self, mobjects=None, ignore_skipping=False, excluded_mobjects=None):
|
def update_frame(self, ignore_skipping=False):
|
||||||
if self.skip_animations and not ignore_skipping:
|
if self.skip_animations and not ignore_skipping:
|
||||||
return
|
return
|
||||||
if mobjects is None:
|
|
||||||
mobjects = self.mobjects
|
|
||||||
|
|
||||||
## REMOVE, this is just temporary while camera.lock_background doesn't work
|
|
||||||
mobjects = self.mobjects
|
|
||||||
##
|
|
||||||
|
|
||||||
if self.window:
|
if self.window:
|
||||||
self.window.clear()
|
self.window.clear()
|
||||||
self.camera.clear()
|
self.camera.clear()
|
||||||
self.camera.capture_mobjects(mobjects, excluded_mobjects=excluded_mobjects)
|
self.camera.capture(*self.displayed_mobjects)
|
||||||
if self.window:
|
if self.window:
|
||||||
self.window.swap_buffers()
|
self.window.swap_buffers()
|
||||||
|
|
||||||
|
@ -168,6 +164,11 @@ class Scene(Container):
|
||||||
self.time += d_time
|
self.time += d_time
|
||||||
|
|
||||||
###
|
###
|
||||||
|
def recompute_displayed_mobjects(self):
|
||||||
|
self.displayed_mobjects = extract_mobject_family_members(
|
||||||
|
self.mobjects,
|
||||||
|
only_those_with_points=True,
|
||||||
|
)
|
||||||
|
|
||||||
def get_top_level_mobjects(self):
|
def get_top_level_mobjects(self):
|
||||||
# Return only those which are not in the family
|
# Return only those which are not in the family
|
||||||
|
@ -193,6 +194,7 @@ class Scene(Container):
|
||||||
"""
|
"""
|
||||||
self.remove(*new_mobjects)
|
self.remove(*new_mobjects)
|
||||||
self.mobjects += new_mobjects
|
self.mobjects += new_mobjects
|
||||||
|
self.recompute_displayed_mobjects()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_mobjects_among(self, values):
|
def add_mobjects_among(self, values):
|
||||||
|
@ -211,6 +213,7 @@ class Scene(Container):
|
||||||
self.mobjects = restructure_list_to_exclude_certain_family_members(
|
self.mobjects = restructure_list_to_exclude_certain_family_members(
|
||||||
self.mobjects, mobjects_to_remove
|
self.mobjects, mobjects_to_remove
|
||||||
)
|
)
|
||||||
|
self.recompute_displayed_mobjects()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def bring_to_front(self, *mobjects):
|
def bring_to_front(self, *mobjects):
|
||||||
|
@ -220,10 +223,12 @@ class Scene(Container):
|
||||||
def bring_to_back(self, *mobjects):
|
def bring_to_back(self, *mobjects):
|
||||||
self.remove(*mobjects)
|
self.remove(*mobjects)
|
||||||
self.mobjects = list(mobjects) + self.mobjects
|
self.mobjects = list(mobjects) + self.mobjects
|
||||||
|
self.recompute_displayed_mobjects()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.mobjects = []
|
self.mobjects = []
|
||||||
|
self.recompute_displayed_mobjects()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_mobjects(self):
|
def get_mobjects(self):
|
||||||
|
@ -376,9 +381,7 @@ class Scene(Container):
|
||||||
def progress_through_animations(self, animations):
|
def progress_through_animations(self, animations):
|
||||||
# Paint all non-moving objects onto the screen, so they don't
|
# Paint all non-moving objects onto the screen, so they don't
|
||||||
# have to be rendered every frame
|
# have to be rendered every frame
|
||||||
moving_mobjects = self.get_moving_mobjects(*animations)
|
# moving_mobjects = self.get_moving_mobjects(*animations)
|
||||||
self.update_frame(excluded_mobjects=moving_mobjects)
|
|
||||||
self.camera.lock_state_as_background()
|
|
||||||
last_t = 0
|
last_t = 0
|
||||||
for t in self.get_animation_time_progression(animations):
|
for t in self.get_animation_time_progression(animations):
|
||||||
dt = t - last_t
|
dt = t - last_t
|
||||||
|
@ -388,9 +391,8 @@ class Scene(Container):
|
||||||
alpha = t / animation.run_time
|
alpha = t / animation.run_time
|
||||||
animation.interpolate(alpha)
|
animation.interpolate(alpha)
|
||||||
self.update_mobjects(dt)
|
self.update_mobjects(dt)
|
||||||
self.update_frame(moving_mobjects)
|
self.update_frame()
|
||||||
self.emit_frame(dt)
|
self.emit_frame(dt)
|
||||||
self.camera.unlock_background()
|
|
||||||
|
|
||||||
def finish_animations(self, animations):
|
def finish_animations(self, animations):
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
|
@ -447,8 +449,6 @@ class Scene(Container):
|
||||||
self.update_mobjects(dt=0) # Any problems with this?
|
self.update_mobjects(dt=0) # Any problems with this?
|
||||||
if self.should_update_mobjects():
|
if self.should_update_mobjects():
|
||||||
time_progression = self.get_wait_time_progression(duration, stop_condition)
|
time_progression = self.get_wait_time_progression(duration, stop_condition)
|
||||||
# TODO, be smart about locking the camera background
|
|
||||||
# the same way Scene.play does
|
|
||||||
last_t = 0
|
last_t = 0
|
||||||
for t in time_progression:
|
for t in time_progression:
|
||||||
dt = t - last_t
|
dt = t - last_t
|
||||||
|
|
Loading…
Add table
Reference in a new issue