manim icon indicating copy to clipboard operation
manim copied to clipboard

Allow add two or more ImageMobjects and TextureSurfaces

Open zhuanvi opened this issue 1 year ago • 1 comments

Motivation

Adding two or more images with ImageMobject showing the recent image in the Scene.

The same problem also occurs in TextureSurface, and this PR is meant to solve this problem.

Proposed changes

  • image_mobject.py
  • surface.py
  • shader_wrapper.py

Test

Code:

from manimlib import *


class Video(Scene):
    
    def construct(self):
        
        image_file1 = "resources/barter-1.png"
        image_file2 = "resources/measure.png"
        image_file3 = "resources/Thales.jpg"
        image_file4 = "resources/Oheaviside.jpg"
        
        im1 = ImageMobject(image_file1)
        im2 = ImageMobject(image_file2)
        
        im1.set_width(3)
        im2.set_width(3)
        
        self.play(FadeIn(im1))
        self.play(im1.animate.shift(3*LEFT))
        
        self.play(FadeIn(im2))
        self.play(im2.animate.shift(3*RIGHT))
        
        
        surf1 = Sphere(radius=1)
        surf2 = Sphere(radius=1)
        
        surf2.move_to(np.array([2,3,1]))
        
        ts1 = TexturedSurface(surf1,image_file3)
        ts2 = TexturedSurface(surf2,image_file4)
        self.play(ShowCreation(ts1))
        self.play(ShowCreation(ts2))
        
        frame = self.camera.frame
        frame.set_euler_angles(
            theta=-30 * DEGREES,
            phi=70 * DEGREES,
        )
        
        frame.add_updater(lambda m, dt: m.increment_theta(-0.1 * dt))
        self.wait(5)

Result:

https://github.com/3b1b/manim/assets/15604323/6d222864-99dc-4ba9-b7ec-6cc469ec9807

zhuanvi avatar Aug 27 '23 05:08 zhuanvi

FWIW applying this patch solved another problem for me where when rendering multiple images some erroneous textured triangles would appear between images (as if the batching went wrong within OpenGL).

bengioe avatar Oct 18 '23 23:10 bengioe