Getting Started - 62firelight/manimRT-490 GitHub Wiki

Requirements

Installation

This guide assumes that you are not familiar with Manim, so some parts can be skipped if you are already experienced with Manim.

ManimRT can be installed with the following pip command:

pip install -i https://test.pypi.org/simple/ manim-rt

Other methods of installation are currently not supported.

Example Scene

An example scene can be used to test if ManimRT was installed correctly.

Animating a ray

  1. Open a text editor (such as Notepad) and paste in the following code:
from manim import *
from manim_rt import *


class ManimRTExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=65*DEGREES, theta=-135*DEGREES, zoom=1.5)
        sphere = RTSphere(color=BLUE)
        ray = Ray3D([-5, 0, 0], length=10, color=RED)
        self.begin_ambient_camera_rotation(0)
        self.add(sphere)
        self.play(Create(ray, run_time=2))
        self.wait(2)
  1. Save this file as ManimRTExample.py in a folder that is easily accessible (e.g. the desktop).

  2. Using a command line interface (e.g. Command Prompt on Windows or the terminal on Linux), navigate to the folder where you created ManimRTExample.py and type in the following command to render the example scene:

manim -pql ManimRTExample.py

Manim will display some information as it renders the example scene and creates an MP4 file. Once finished, your default movie player will play the newly created MP4 file, which should appear the same as in the video below:

https://github.com/user-attachments/assets/76830c66-4a86-45c3-9a1b-3af2519661fc

If you see this video, then congratulations! You've just rendered your first ManimRT scene.

If you get an error message, don't see the video, or if the video output appears differently to the video above, then something has gone wrong. Try double-checking that you've performed the above steps in the right order. The Manim FAQ may be useful for troubleshooting in this case.

Explanation

Below is a brief explanation of the above code.

The first two lines import the contents of both Manim and ManimRT. Note that ManimRT is reliant on the existing Manim library.

from manim import *

from manim_rt import *

According to Manim's own Quickstart section, this is the recommended method of using Manim, as it is very likely that you will end up using multiple names from the Manim and ManimRT namespace. The code uses ThreeDScene, DEGREES, RED, BLUE, and Create from Manim. RTSphere and Ray3D are both imported from ManimRT.

Let's consider the next two lines of code:

class ManimRTExample(ThreeDScene):
    def construct(self):
        [...]

Generally, any code that is used for scripting an animation in Manim is contained within the construct() method of a Scene class. In this case, we are creating a ManimRTExample class which inherits from the existing ThreeDScene class (which in turn inherits from the existing Scene class). The ThreeDScene class provides additional methods for 3D scenes.

Because the name of the class that inherits from a Scene class is called ManimRTExample, the corresponding video file that gets rendered will be named ManimRTExample.mp4.

The next line sets the camera to a specific orientation using Euler angles. It is also zoomed in slightly.

self.set_camera_orientation(phi=65*DEGREES, theta=-135*DEGREES, zoom=1.5)

The next two lines create a sphere (colored blue) and a ray (colored red). The ray is essentially a 3D arrow that starts at [-5, 0, 0], has a default direction of [1, 0, 0], and a length of 10 units.

sphere = RTSphere(color=BLUE)
ray = Ray3D([-5, 0, 0], length=10, color=RED)

The next line of code sets the camera to constantly rotate at a rate of 0 units. This may seem unnecessary, but it is crucial to include this line for any animations that depict an intersection between 3D objects (such as this example scene). Without this line, intersections will not display correctly. The source for this fix comes from this Reddit post.

self.begin_ambient_camera_rotation(0)

The next three lines add the sphere to the scene (with no animation), use the Create animation to display the ray, and uses the wait() method to play a "no operation" animation (i.e. idling) for 2 seconds. The run_time parameter is used to ensure that the Create animation lasts exactly 2 seconds, as the default duration (1 second) can seem a bit fast.

self.add(sphere)
self.play(Create(ray, run_time=2))
self.wait(2)

Example Gallery

For more examples of scenes that can be rendered with ManimRT, see the Example Gallery.

Reference Manual

To see more detailed documentation for each class and function in ManimRT, see the Reference Manual.

Uninstallation

Assuming that ManimRT was initially installed with pip, ManimRT can be uninstalled with the following pip command:

pip uninstall manim-rt