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:
Grant Sanderson 2020-02-13 15:42:53 -08:00
parent 5df2d3db33
commit cfbcd9faa8
5 changed files with 21 additions and 46 deletions

View file

@ -12,8 +12,6 @@ from manimlib.constants import *
from manimlib.mobject.mobject import Mobject
from manimlib.utils.config_ops import digest_config
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
@ -83,6 +81,7 @@ class Camera(object):
moderngl.SRC_ALPHA, moderngl.ONE_MINUS_SRC_ALPHA,
moderngl.ONE, moderngl.ONE
)
self.background_fbo = None
# Methods associated with the frame buffer
def get_fbo(self):
@ -113,14 +112,6 @@ class Camera(object):
rgba = (*Color(self.background_color).get_rgb(), self.background_opacity)
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):
self.pixel_width = new_width
self.pixel_height = new_height
@ -208,6 +199,7 @@ class Camera(object):
])
# TODO, account for 3d
# Also, move this to CameraFrame?
def is_in_frame(self, mobject):
fc = self.get_frame_center()
fh = self.get_frame_height()
@ -220,20 +212,7 @@ class Camera(object):
])
# Rendering
def get_mobjects_to_display(self, mobjects, excluded_mobjects=None):
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)
def capture(self, *mobjects, **kwargs):
shader_infos = list(it.chain(*[
mob.get_shader_info_list()
for mob in mobjects

View file

@ -9,6 +9,7 @@ from manimlib.utils.config_ops import digest_config
# map their centers but remain otherwise undistorted (useful for labels, etc.)
# TODO, this class is deprecated
class MappingCamera(Camera):
CONFIG = {
"mapping_func": lambda p: p,

View file

@ -54,11 +54,6 @@ class MovingCamera(Camera):
def set_frame_center(self, 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
# context used for updating should be regenerated
# at each frame. So no caching.

View file

@ -41,9 +41,9 @@ class ThreeDCamera(Camera):
self.fixed_in_frame_mobjects = set()
self.reset_rotation_matrix()
def capture_mobjects(self, mobjects, **kwargs):
def capture(self, *mobjects, **kwargs):
self.reset_rotation_matrix()
Camera.capture_mobjects(self, mobjects, **kwargs)
Camera.capture(self, *mobjects, **kwargs)
def get_value_trackers(self):
return [

View file

@ -16,6 +16,7 @@ from manimlib.mobject.mobject import Mobject
from manimlib.scene.scene_file_writer import SceneFileWriter
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.iterables import list_difference_update
from manimlib.window import Window
@ -45,6 +46,7 @@ class Scene(Container):
self.camera = self.camera_class(**self.camera_config)
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
self.mobjects = []
self.displayed_mobjects = []
self.num_plays = 0
self.time = 0
self.original_skipping_status = self.skip_animations
@ -120,20 +122,14 @@ class Scene(Container):
def get_image(self):
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:
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:
self.window.clear()
self.camera.clear()
self.camera.capture_mobjects(mobjects, excluded_mobjects=excluded_mobjects)
self.camera.capture(*self.displayed_mobjects)
if self.window:
self.window.swap_buffers()
@ -168,6 +164,11 @@ class Scene(Container):
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):
# Return only those which are not in the family
@ -193,6 +194,7 @@ class Scene(Container):
"""
self.remove(*new_mobjects)
self.mobjects += new_mobjects
self.recompute_displayed_mobjects()
return self
def add_mobjects_among(self, values):
@ -211,6 +213,7 @@ class Scene(Container):
self.mobjects = restructure_list_to_exclude_certain_family_members(
self.mobjects, mobjects_to_remove
)
self.recompute_displayed_mobjects()
return self
def bring_to_front(self, *mobjects):
@ -220,10 +223,12 @@ class Scene(Container):
def bring_to_back(self, *mobjects):
self.remove(*mobjects)
self.mobjects = list(mobjects) + self.mobjects
self.recompute_displayed_mobjects()
return self
def clear(self):
self.mobjects = []
self.recompute_displayed_mobjects()
return self
def get_mobjects(self):
@ -376,9 +381,7 @@ class Scene(Container):
def progress_through_animations(self, animations):
# Paint all non-moving objects onto the screen, so they don't
# have to be rendered every frame
moving_mobjects = self.get_moving_mobjects(*animations)
self.update_frame(excluded_mobjects=moving_mobjects)
self.camera.lock_state_as_background()
# moving_mobjects = self.get_moving_mobjects(*animations)
last_t = 0
for t in self.get_animation_time_progression(animations):
dt = t - last_t
@ -388,9 +391,8 @@ class Scene(Container):
alpha = t / animation.run_time
animation.interpolate(alpha)
self.update_mobjects(dt)
self.update_frame(moving_mobjects)
self.update_frame()
self.emit_frame(dt)
self.camera.unlock_background()
def finish_animations(self, animations):
for animation in animations:
@ -447,8 +449,6 @@ class Scene(Container):
self.update_mobjects(dt=0) # Any problems with this?
if self.should_update_mobjects():
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
for t in time_progression:
dt = t - last_t