23
23
from ..mobject .opengl_mobject import OpenGLMobject , OpenGLPoint
24
24
from PIL import Image
25
25
from manim import config
26
+ from ..scene .scene_file_writer import SceneFileWriter
26
27
27
28
28
29
class OpenGLCamera (OpenGLMobject ):
@@ -34,7 +35,7 @@ def __init__(
34
35
euler_angles = [0 , 0 , 0 ],
35
36
focal_distance = 2 ,
36
37
light_source_position = [- 10 , 10 , 10 ],
37
- ** kwargs
38
+ ** kwargs ,
38
39
):
39
40
self .use_z_index = True
40
41
self .frame_rate = 60
@@ -185,7 +186,7 @@ def __init__(self):
185
186
self .num_plays = 0
186
187
self .skip_animations = False
187
188
188
- self .window = Window (size = (854 , 480 ))
189
+ self .window = Window (size = (1280 , 720 ))
189
190
190
191
self .camera = OpenGLCamera ()
191
192
@@ -214,7 +215,6 @@ def update_depth_test(self, context, shader_wrapper):
214
215
215
216
def get_pixel_shape (self ):
216
217
return self .frame_buffer_object .viewport [2 :4 ]
217
- # return (self.pixel_width, self.pixel_height)
218
218
219
219
def refresh_perspective_uniforms (self , camera_frame ):
220
220
pw , ph = self .get_pixel_shape ()
@@ -338,7 +338,10 @@ def set_shader_uniforms(self, shader, shader_wrapper):
338
338
pass
339
339
340
340
def init_scene (self , scene ):
341
- self .file_writer = None
341
+ self .file_writer = SceneFileWriter (
342
+ self ,
343
+ scene .__class__ .__name__ ,
344
+ )
342
345
343
346
def play (self , scene , * args , ** kwargs ):
344
347
if len (args ) == 0 :
@@ -349,7 +352,14 @@ def play(self, scene, *args, **kwargs):
349
352
if scene .compile_animation_data (* args , ** kwargs ):
350
353
self .animation_start_time = time .time ()
351
354
self .animation_elapsed_time = 0
355
+
356
+ temp_name = f"media/temp_{ self .num_plays } .mp4"
357
+ self .file_writer .begin_animation (
358
+ not self .skip_animations , file_path = temp_name
359
+ )
352
360
scene .play_internal ()
361
+ self .file_writer .end_animation (not self .skip_animations )
362
+
353
363
self .num_plays += 1
354
364
355
365
def render (self , scene , frame_offset , moving_mobjects ):
@@ -362,6 +372,9 @@ def update_frame():
362
372
363
373
window_background_color = (0.2 , 0.2 , 0.2 , 1 )
364
374
update_frame ()
375
+
376
+ self .file_writer .write_frame (self )
377
+
365
378
while self .animation_elapsed_time < frame_offset :
366
379
update_frame ()
367
380
@@ -370,3 +383,19 @@ def scene_finished(self, scene):
370
383
371
384
def save_static_frame_data (self , scene , static_mobjects ):
372
385
pass
386
+
387
+ def get_raw_frame_buffer_object_data (self , dtype = "f1" ):
388
+ # Copy blocks from the fbo_msaa to the drawn fbo using Blit
389
+ # pw, ph = self.get_pixel_shape()
390
+ # gl.glBindFramebuffer(gl.GL_READ_FRAMEBUFFER, self.fbo_msaa.glo)
391
+ # gl.glBindFramebuffer(gl.GL_DRAW_FRAMEBUFFER, self.fbo.glo)
392
+ # gl.glBlitFramebuffer(
393
+ # 0, 0, pw, ph, 0, 0, pw, ph, gl.GL_COLOR_BUFFER_BIT, gl.GL_LINEAR
394
+ # )
395
+ num_channels = 4
396
+ ret = self .frame_buffer_object .read (
397
+ viewport = self .frame_buffer_object .viewport ,
398
+ components = num_channels ,
399
+ dtype = dtype ,
400
+ )
401
+ return ret
0 commit comments