Giter Club home page Giter Club logo

Comments (4)

phinate avatar phinate commented on June 17, 2024

More info: I'm running manim -qm --renderer=opengl -p manim.py SurfaceExample, where manim.py contains just the code from that example (trimmed down a little to just make the sphere). I'm using these textures: https://github.com/ManimCommunity/manim/tree/04bfa221075166a00eaa11fc9e9f0757f56625d2/example_scenes/assets. Here's my code:

from pathlib import Path

import manim.utils.opengl as opengl
from manim import *
from manim.opengl import *  # type: ignore

class SurfaceExample(Scene):
    def construct(self):

        sphere = Sphere(radius=3, resolution=Torus(major_radius=1, minor_radius=1).resolution)
        # You can texture a surface with up to two images, which will
        # be interpreted as the side towards the light, and away from
        # the light.  These can be either urls, or paths to a local file
        # in whatever you've set as the image directory in
        # the custom_config.yml file

        script_location = Path(__file__).resolve().parent
        day_texture = (
            script_location / "assets" / "1280px-Whole_world_-_land_and_oceans.jpg"
        )
        night_texture = script_location / "assets" / "1280px-The_earth_at_night.jpg"

         # <-- fails here
        textured_earth = OpenGLTexturedSurface(sphere, day_texture, night_texture) 


        textured_earth.shift(IN)
        textured_earth.mesh = OpenGLSurfaceMesh(textured_earth)
        textured_earth.mesh.set_stroke(BLUE, 1, opacity=0.5)

        # Set perspective
        frame = self.renderer.camera
        frame.set_euler_angles(
            theta=-30 * DEGREES,
            phi=70 * DEGREES,
        )

        

        self.play(
            FadeIn(textured_earth),
            Create(textured_earth.mesh, lag_ratio=0.01, run_time=3),
        )
        textured_earth.add(textured_earth.mesh)
        textured_earth.save_state()
        self.play(Rotate(textured_earth, PI / 2), run_time=2)

        # self.play(Transform(surface, surfaces[1]), run_time=3)

        # self.play(
        #     Transform(surface, surfaces[2]),
        #     # Move camera frame during the transition
        #     frame.animate.increment_phi(-10 * DEGREES),
        #     frame.animate.increment_theta(-20 * DEGREES),
        #     run_time=3,
        # )
        # Add ambient rotation
        frame.add_updater(lambda m, dt: m.increment_theta(-0.1 * dt))

        # Play around with where the light is
        # light_text = Text("You can move around the light source")
        # light_text.move_to(surface_text)
        # light_text.fix_in_frame()

        # self.play(FadeTransform(surface_text, light_text))
        light = self.camera.light_source
        self.add(light)
        light.save_state()
        self.play(light.animate.move_to(3 * IN), run_time=5)
        self.play(light.animate.shift(10 * OUT), run_time=5)

from manim.

uwezi avatar uwezi commented on June 17, 2024

try to rename your file to something else than "manim.py" and make sure to remove any file called "manim.py"

from manim.

phinate avatar phinate commented on June 17, 2024

try to rename your file to something else than "manim.py" and make sure to remove any file called "manim.py"

Right, that was an accidental top-level library name pollution, but it didn't impact running this particular example, which I can replicate regardless of filename in a blank directory, and also in a Jupyter notebook.

from manim.

uwezi avatar uwezi commented on June 17, 2024

as a help to debug the cause of the new problem in 0.18.0.post0: the following code works, i.e. explicitly defining an OpenGLSurface while the internal overloading of a Surface or Sphere does not work and gives an error because uv_func is not defined....

from manim import *
from manim.opengl import *  # type: ignore

class SurfaceExample(Scene):
    def construct(self):

        sphere = OpenGLSurface(
            lambda u,v: [3*np.sin(u)*np.cos(v), 3*np.sin(u)*np.sin(v), 3*np.cos(u)],
            u_range=[0,PI],
            v_range=[-PI,PI]
        )

        # You can texture a surface with up to two images, which will
        # be interpreted as the side towards the light, and away from
        # the light.  These can be either urls, or paths to a local file
        # in whatever you've set as the image directory in
        # the custom_config.yml file

        day_texture = "bilder/1280px-Whole_world_-_land_and_oceans.jpg"

        night_texture = "bilder/1280px-The_earth_at_night.jpg"

         # <-- fails here
        textured_earth = OpenGLTexturedSurface(sphere, day_texture, night_texture)


        textured_earth.shift(IN)
        textured_earth.mesh = OpenGLSurfaceMesh(textured_earth)
        textured_earth.mesh.set_stroke(BLUE, 1, opacity=0.5)

        # Set perspective
        frame = self.renderer.camera
        frame.set_euler_angles(
            theta=-30 * DEGREES,
            phi=70 * DEGREES,
        )



        self.play(
            FadeIn(textured_earth),
            Create(textured_earth.mesh, lag_ratio=0.01, run_time=3),
        )
        textured_earth.add(textured_earth.mesh)
        textured_earth.save_state()
        self.play(Rotate(textured_earth, PI / 2), run_time=2)

        # self.play(Transform(surface, surfaces[1]), run_time=3)

        # self.play(
        #     Transform(surface, surfaces[2]),
        #     # Move camera frame during the transition
        #     frame.animate.increment_phi(-10 * DEGREES),
        #     frame.animate.increment_theta(-20 * DEGREES),
        #     run_time=3,
        # )
        # Add ambient rotation
        frame.add_updater(lambda m, dt: m.increment_theta(-0.1 * dt))

        # Play around with where the light is
        # light_text = Text("You can move around the light source")
        # light_text.move_to(surface_text)
        # light_text.fix_in_frame()

        # self.play(FadeTransform(surface_text, light_text))
        light = self.camera.light_source
        self.add(light)
        light.save_state()
        self.play(light.animate.move_to(3 * IN), run_time=5)
        self.play(light.animate.shift(10 * OUT), run_time=5)

from manim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.