# CLI Options
Source: https://manimvtk.mathify.dev/advanced/cli-options
Complete command-line interface reference
## Basic Usage
```bash theme={null}
manimvtk [OPTIONS] FILE [SCENES]
```
## Quality Options
| Option | Description |
| ------ | ---------------------------- |
| `-ql` | Low quality (480p, 15fps) |
| `-qm` | Medium quality (720p, 30fps) |
| `-qh` | High quality (1080p, 60fps) |
| `-qk` | 4K quality (2160p, 60fps) |
## Output Options
| Option | Description |
| ------------- | ------------------------- |
| `-p` | Preview after rendering |
| `-s` | Save last frame as image |
| `-a` | Render all scenes in file |
| `-o FILENAME` | Output filename |
## Renderer Options
| Option | Description |
| ------------------------------- | --------------- |
| `--renderer {cairo,opengl,vtk}` | Select renderer |
## VTK Export Options
| Option | Description |
| ------------------- | ------------------------- |
| `--vtk-export` | Export final scene to VTK |
| `--vtk-time-series` | Export frame-by-frame VTK |
## Examples
```bash theme={null}
# High quality with preview
manimvtk -pqh scene.py MyScene
# VTK export
manimvtk -pqh scene.py MyScene --renderer vtk --vtk-export
# Time series for ParaView
manimvtk -pqm scene.py MyScene --vtk-time-series
# All scenes, low quality
manimvtk -aql scene.py
```
## See Also
Config file settings
Getting started guide
# Configuration
Source: https://manimvtk.mathify.dev/advanced/configuration
Configuring ManimVTK settings
## Configuration File
Create `manim.cfg` in your project directory:
```ini theme={null}
[CLI]
renderer = vtk
quality = high
frame_rate = 60
background_color = BLACK
[output]
video_dir = {media_dir}/videos/{module_name}/{quality}
vtk_dir = {media_dir}/vtk
```
## Configuration Options
### CLI Options
* `renderer`: cairo, opengl, or vtk
* `quality`: low, medium, high, fourk
* `frame_rate`: Frames per second
* `background_color`: Scene background
### Output Paths
* `video_dir`: Where videos are saved
* `images_dir`: Where images are saved
* `vtk_dir`: Where VTK exports are saved
## Per-Scene Configuration
```python theme={null}
class MyScene(Scene):
def construct(self):
# Access config
config.frame_rate = 30
config.background_color = WHITE
# Your scene code
pass
```
## See Also
Command-line reference
Getting started
# Custom Animations
Source: https://manimvtk.mathify.dev/advanced/custom-animations
Creating custom animation classes
## Creating Custom Animations
Extend Animation class:
```python theme={null}
from manimvtk import *
class CustomAnimation(Animation):
def interpolate_mobject(self, alpha):
# alpha goes from 0 to 1
# Modify self.mobject based on alpha
self.mobject.scale(1 + alpha)
```
## See Also
Animation concepts
# Custom Mobjects
Source: https://manimvtk.mathify.dev/advanced/custom-mobjects
Creating custom mobject classes
## Creating Custom Mobjects
Extend VMobject or Mobject to create custom shapes:
```python theme={null}
from manimvtk import *
class CustomStar(VMobject):
def __init__(self, points=5, **kwargs):
super().__init__(**kwargs)
# Define your shape logic
angles = np.linspace(0, TAU, points * 2 + 1)
vertices = [
[np.cos(a), np.sin(a), 0] * (2 if i % 2 else 1)
for i, a in enumerate(angles[:-1])
]
self.set_points_as_corners(vertices)
self.close_path()
```
## See Also
Mobjects concepts
# Creation Animations
Source: https://manimvtk.mathify.dev/api-reference/animations/creation
Creation animation reference
## Creation Animations
See [Animations Overview](/api-reference/animations/overview) for complete documentation.
Complete animations guide
# Indication Animations
Source: https://manimvtk.mathify.dev/api-reference/animations/indication
Indication animation reference
## Indication Animations
See [Animations Overview](/api-reference/animations/overview) for complete documentation.
Complete animations guide
# Movement Animations
Source: https://manimvtk.mathify.dev/api-reference/animations/movement
Movement animation reference
## Movement Animations
See [Animations Overview](/api-reference/animations/overview) for complete documentation.
Complete animations guide
# Animations Overview
Source: https://manimvtk.mathify.dev/api-reference/animations/overview
Complete reference for ManimVTK animations
## Animation Categories
Create, Write, FadeIn, GrowFromCenter
Transform, ReplacementTransform, MoveToTarget
Shift, Rotate, Scale
Indicate, Flash, Wiggle, Circumscribe
## Playing Animations
```python theme={null}
self.play(AnimationClass(mobject, **kwargs))
```
**Common parameters:**
* `run_time` (float): Duration in seconds
* `rate_func` (function): Timing function
* `lag_ratio` (float): For grouped animations
## The .animate Syntax
```python theme={null}
self.play(mobject.animate.method())
```
**Example:**
```python theme={null}
self.play(circle.animate.shift(RIGHT).scale(2).set_color(RED))
```
## See Also
Conceptual guide
Animation examples
# Transform Animations
Source: https://manimvtk.mathify.dev/api-reference/animations/transform
Transform animation reference
## Transform Animations
See [Animations Overview](/api-reference/animations/overview) for complete documentation.
Complete animations guide
# 3D Objects
Source: https://manimvtk.mathify.dev/api-reference/mobjects/3d-objects
3D primitives and surfaces reference
## 3D Primitives
### Sphere
```python theme={null}
Sphere(radius=1, resolution=(20, 20), **kwargs)
```
Creates a 3D sphere.
**Parameters:**
* `radius` (float): Sphere radius
* `resolution` (tuple): (u\_res, v\_res) mesh resolution
**Example:**
```python theme={null}
sphere = Sphere(radius=1.5, resolution=(40, 40), color=BLUE)
```
### Cube
```python theme={null}
Cube(side_length=2, **kwargs)
```
### Cone
```python theme={null}
Cone(base_radius=1, height=2, **kwargs)
```
### Cylinder
```python theme={null}
Cylinder(radius=1, height=2, **kwargs)
```
## Surfaces
### Surface
```python theme={null}
Surface(
func,
u_range=[-1, 1],
v_range=[-1, 1],
resolution=(10, 10),
**kwargs
)
```
Creates a parametric surface.
**Parameters:**
* `func`: Function (u, v) → \[x, y, z]
* `u_range`: Range for parameter u
* `v_range`: Range for parameter v
* `resolution`: Mesh resolution
**Example:**
```python theme={null}
import numpy as np
surface = Surface(
lambda u, v: np.array([u, v, u**2 - v**2]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(30, 30)
)
```
### ParametricSurface
```python theme={null}
ParametricSurface(func, **kwargs)
```
## 3D Axes
### ThreeDAxes
```python theme={null}
ThreeDAxes(
x_range=[-6, 6, 1],
y_range=[-5, 5, 1],
z_range=[-4, 4, 1],
**kwargs
)
```
## See Also
3D visualization examples
Export 3D objects to VTK
# Geometry
Source: https://manimvtk.mathify.dev/api-reference/mobjects/geometry
2D geometric shapes reference
## Circles and Ellipses
### Circle
```python theme={null}
Circle(radius=1.0, color=WHITE, **kwargs)
```
Creates a circle.
**Parameters:**
* `radius` (float): Circle radius
* `color` (Color): Circle color
* `stroke_width` (float): Width of outline
* `fill_opacity` (float): Fill transparency (0-1)
**Example:**
```python theme={null}
circle = Circle(radius=2, color=BLUE, fill_opacity=0.5)
```
### Ellipse
```python theme={null}
Ellipse(width=2, height=1, **kwargs)
```
**Example:**
```python theme={null}
ellipse = Ellipse(width=3, height=1.5, color=RED)
```
## Polygons
### Square
```python theme={null}
Square(side_length=2.0, **kwargs)
```
### Rectangle
```python theme={null}
Rectangle(width=4.0, height=2.0, **kwargs)
```
### Triangle
```python theme={null}
Triangle(**kwargs)
```
### Polygon
```python theme={null}
Polygon(*vertices, **kwargs)
```
**Example:**
```python theme={null}
pentagon = Polygon(
[0, 0, 0],
[1, 0, 0],
[1.5, 1, 0],
[0.5, 1.5, 0],
[-0.5, 1, 0],
color=GREEN
)
```
## Lines and Arrows
### Line
```python theme={null}
Line(start=LEFT, end=RIGHT, **kwargs)
```
### Arrow
```python theme={null}
Arrow(start=ORIGIN, end=RIGHT, **kwargs)
```
### Vector
```python theme={null}
Vector(direction=RIGHT, **kwargs)
```
**Example:**
```python theme={null}
arrow = Arrow(start=LEFT*2, end=RIGHT*2, color=RED)
```
## Arcs
### Arc
```python theme={null}
Arc(radius=1.0, start_angle=0, angle=TAU/4, **kwargs)
```
### ArcBetweenPoints
```python theme={null}
ArcBetweenPoints(start, end, angle=TAU/4, **kwargs)
```
## Curves
### CubicBezier
```python theme={null}
CubicBezier(start, control1, control2, end, **kwargs)
```
### ParametricCurve
```python theme={null}
ParametricCurve(function, t_range=[0, 1], **kwargs)
```
## See Also
All mobject types
Geometry examples
# Graphs and Coordinates
Source: https://manimvtk.mathify.dev/api-reference/mobjects/graphs
Coordinate systems, axes, and graphing reference
## Coordinate Systems
### Axes
```python theme={null}
Axes(
x_range=[-7, 7, 1],
y_range=[-5, 5, 1],
**kwargs
)
```
2D coordinate axes.
### NumberPlane
```python theme={null}
NumberPlane(
x_range=[-10, 10, 1],
y_range=[-10, 10, 1],
**kwargs
)
```
Grid plane with axes.
### ThreeDAxes
```python theme={null}
ThreeDAxes(
x_range=[-6, 6, 1],
y_range=[-5, 5, 1],
z_range=[-4, 4, 1]
)
```
3D coordinate system.
## Graphing
### Plotting Functions
```python theme={null}
axes = Axes(x_range=[-3, 3], y_range=[-2, 2])
graph = axes.plot(lambda x: x**2, color=BLUE)
```
### Labels
```python theme={null}
axes = Axes()
labels = axes.get_axis_labels(x_label="x", y_label="f(x)")
```
## See Also
Graphing examples
All mobjects
# Mobjects Overview
Source: https://manimvtk.mathify.dev/api-reference/mobjects/overview
Complete reference for Manim Objects (Mobjects)
## Mobject Types
ManimVTK provides a rich set of mobject classes for creating visual elements.
2D geometric shapes: Circle, Square, Line, Arc, Polygon, etc.
3D primitives and surfaces: Sphere, Cube, Surface, etc.
Text and mathematical equations: Text, Tex, MathTex
Coordinate systems, axes, and graphs
## Base Classes
### Mobject
The base class for all Manim objects.
**Common methods:**
* `shift(vector)` - Move relative to current position
* `move_to(point)` - Move to absolute position
* `scale(factor)` - Scale by factor
* `rotate(angle)` - Rotate by angle
* `set_color(color)` - Set color
* `copy()` - Create a copy
### VMobject
Vectorized mobject for 2D shapes.
**Additional methods:**
* `set_stroke(color, width, opacity)` - Set stroke properties
* `set_fill(color, opacity)` - Set fill properties
* `get_points()` - Get bezier curve points
### VGroup
Container for grouping multiple mobjects.
**Methods:**
* `add(*mobjects)` - Add mobjects to group
* `remove(*mobjects)` - Remove mobjects
* `arrange(direction, buff)` - Arrange in a line
* `arrange_in_grid(rows, cols, buff)` - Arrange in grid
## Common Patterns
```python theme={null}
# Create and style
circle = Circle(radius=1, color=BLUE, fill_opacity=0.5)
# Transform
circle.shift(RIGHT * 2).scale(1.5).rotate(PI/4)
# Group
shapes = VGroup(circle, Square(), Triangle())
shapes.arrange(RIGHT, buff=1)
```
## See Also
Conceptual guide
See examples
Animate mobjects
# Text and LaTeX
Source: https://manimvtk.mathify.dev/api-reference/mobjects/text
Text rendering reference
## Text Objects
### Text
```python theme={null}
Text(text, font="", font_size=48, **kwargs)
```
Regular text rendering.
**Example:**
```python theme={null}
text = Text("Hello, World!", font_size=60, color=BLUE)
```
### MarkupText
```python theme={null}
MarkupText(text, **kwargs)
```
Text with markup support (bold, italic, colors).
### Tex
```python theme={null}
Tex(*tex_strings, **kwargs)
```
LaTeX text rendering.
**Example:**
```python theme={null}
formula = Tex(r"E = mc^2")
```
### MathTex
```python theme={null}
MathTex(*tex_strings, **kwargs)
```
Mathematical equations.
**Example:**
```python theme={null}
equation = MathTex(
r"\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}"
)
```
## See Also
Text examples
Mobject concepts
# Camera
Source: https://manimvtk.mathify.dev/api-reference/scene/camera
camera API reference
## API Reference
See conceptual guides for detailed documentation.
Scene concepts
Camera control
# Moving camera
Source: https://manimvtk.mathify.dev/api-reference/scene/moving-camera
moving camera API reference
## API Reference
See conceptual guides for detailed documentation.
Scene concepts
Camera control
# Scene
Source: https://manimvtk.mathify.dev/api-reference/scene/scene
scene API reference
## API Reference
See conceptual guides for detailed documentation.
Scene concepts
Camera control
# Three d scene
Source: https://manimvtk.mathify.dev/api-reference/scene/three-d-scene
three d scene API reference
## API Reference
See conceptual guides for detailed documentation.
Scene concepts
Camera control
# Scalar fields
Source: https://manimvtk.mathify.dev/api-reference/vtk/scalar-fields
scalar fields API reference
## API Reference
See the VTK documentation for implementation details.
VTK features overview
VTK export guide
# Vector fields
Source: https://manimvtk.mathify.dev/api-reference/vtk/vector-fields
vector fields API reference
## API Reference
See the VTK documentation for implementation details.
VTK features overview
VTK export guide
# Vtk adapter
Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-adapter
vtk adapter API reference
## API Reference
See the VTK documentation for implementation details.
VTK features overview
VTK export guide
# Vtk exporter
Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-exporter
vtk exporter API reference
## API Reference
See the VTK documentation for implementation details.
VTK features overview
VTK export guide
# Vtk renderer
Source: https://manimvtk.mathify.dev/api-reference/vtk/vtk-renderer
vtk renderer API reference
## API Reference
See the VTK documentation for implementation details.
VTK features overview
VTK export guide
# Animations
Source: https://manimvtk.mathify.dev/concepts/animations
Master animation techniques in ManimVTK
## Animation Basics
Animations are transformations applied to mobjects over time. ManimVTK provides a rich set of animation classes for creating smooth, beautiful movements and effects.
All animations are played using `self.play()` in your scene's `construct()` method
## Playing Animations
### Basic Syntax
```python theme={null}
from manimvtk import *
class BasicAnimation(Scene):
def construct(self):
circle = Circle()
# Play a single animation
self.play(Create(circle))
# Wait (pause animation)
self.wait()
```
### Multiple Animations
```python theme={null}
class MultipleAnimations(Scene):
def construct(self):
c1 = Circle().shift(LEFT)
c2 = Square().shift(RIGHT)
# Play animations simultaneously
self.play(
Create(c1),
Create(c2)
)
# Play sequentially
self.play(FadeOut(c1))
self.play(FadeOut(c2))
```
### Animation Parameters
```python theme={null}
self.play(
Create(circle),
run_time=2, # Duration in seconds
rate_func=smooth # Timing function
)
```
## Animation Types
### Creation Animations
Animations that introduce objects to the scene:
Draw the object from start to finish:
```python theme={null}
circle = Circle()
self.play(Create(circle))
```
Write text or equations:
```python theme={null}
text = Text("Hello, World!")
self.play(Write(text))
```
Fade object into view:
```python theme={null}
square = Square()
self.play(FadeIn(square))
```
Grow object from its center:
```python theme={null}
circle = Circle()
self.play(GrowFromCenter(circle))
```
### Removal Animations
Animations that remove objects from the scene:
Reverse of Create:
```python theme={null}
self.play(Uncreate(circle))
```
Fade object out of view:
```python theme={null}
self.play(FadeOut(square))
```
Shrink to center point:
```python theme={null}
self.play(ShrinkToCenter(circle))
```
### Transform Animations
Transform one object into another:
```python theme={null}
class TransformExample(Scene):
def construct(self):
circle = Circle()
square = Square()
self.play(Create(circle))
self.wait()
# Transform circle into square
self.play(Transform(circle, square))
self.wait()
```
**Types of transforms:**
* `Transform` - Morph one object into another
* `ReplacementTransform` - Replace and morph
* `TransformFromCopy` - Create copy that transforms
* `ClockwiseTransform` - Transform with rotation
### Movement Animations
Move objects around the scene:
```python theme={null}
class MovementExample(Scene):
def construct(self):
circle = Circle()
self.add(circle)
# Using .animate syntax (recommended)
self.play(circle.animate.shift(RIGHT * 3))
self.play(circle.animate.move_to(UP * 2))
# Using explicit animations
self.play(circle.animate.to_edge(LEFT))
```
### Rotation Animations
Rotate objects:
```python theme={null}
class RotationExample(Scene):
def construct(self):
square = Square()
self.add(square)
# Rotate 90 degrees
self.play(Rotate(square, PI / 2))
# Or using .animate
self.play(square.animate.rotate(PI / 2))
```
### Indication Animations
Draw attention to objects:
Briefly highlight:
```python theme={null}
self.play(Indicate(circle))
```
Flash effect:
```python theme={null}
self.play(Flash(point))
```
Wiggle animation:
```python theme={null}
self.play(Wiggle(text))
```
Draw attention with shape around object:
```python theme={null}
self.play(Circumscribe(equation))
```
## The .animate Syntax
The most intuitive way to animate transformations:
```python theme={null}
class AnimateSyntax(Scene):
def construct(self):
circle = Circle()
self.add(circle)
# Chain multiple transformations
self.play(
circle.animate
.shift(RIGHT * 2)
.scale(1.5)
.set_color(RED)
)
```
**Benefits:**
* Readable and intuitive
* Supports method chaining
* Works with most mobject methods
**Examples:**
```python theme={null}
# Movement
self.play(mob.animate.shift(UP))
self.play(mob.animate.move_to([1, 2, 0]))
self.play(mob.animate.to_edge(RIGHT))
# Scaling
self.play(mob.animate.scale(2))
self.play(mob.animate.stretch(2, 0))
# Rotation
self.play(mob.animate.rotate(PI / 4))
# Color
self.play(mob.animate.set_color(BLUE))
self.play(mob.animate.set_opacity(0.5))
# Combination
self.play(
mob.animate
.shift(RIGHT)
.rotate(PI / 2)
.set_color(RED)
)
```
## Rate Functions
Control the timing and pacing of animations:
```python theme={null}
from manimvtk import *
class RateFunctions(Scene):
def construct(self):
circle = Circle()
self.add(circle)
# Linear (constant speed)
self.play(circle.animate.shift(RIGHT), rate_func=linear)
# Smooth (ease in and out)
self.play(circle.animate.shift(LEFT), rate_func=smooth)
# Rush into (accelerate)
self.play(circle.animate.shift(UP), rate_func=rush_into)
# Rush from (decelerate)
self.play(circle.animate.shift(DOWN), rate_func=rush_from)
```
**Common rate functions:**
* `linear` - Constant speed
* `smooth` - Ease in and out
* `rush_into` - Start slow, end fast
* `rush_from` - Start fast, end slow
* `there_and_back` - Go and return
* `running_start` - Build momentum
## Animation Composition
### Succession
Animate one after another:
```python theme={null}
from manimvtk import Succession
self.play(
Succession(
Create(circle),
FadeIn(square),
Write(text)
)
)
```
### AnimationGroup
Group animations to play together:
```python theme={null}
from manimvtk import AnimationGroup
self.play(
AnimationGroup(
Create(circle),
FadeIn(square),
lag_ratio=0.5 # Stagger the animations
)
)
```
### LaggedStart
Start animations with a delay:
```python theme={null}
from manimvtk import LaggedStart
shapes = VGroup(*[Circle() for _ in range(5)])
shapes.arrange(RIGHT)
self.play(
LaggedStart(*[Create(s) for s in shapes], lag_ratio=0.2)
)
```
## Advanced Techniques
### Custom Run Time
```python theme={null}
# Slow animation
self.play(Create(circle), run_time=3)
# Fast animation
self.play(FadeOut(square), run_time=0.5)
```
### UpdateFromFunc
Animate based on custom function:
```python theme={null}
def update_func(mob, alpha):
# alpha goes from 0 to 1
mob.move_to(alpha * RIGHT * 3)
circle = Circle()
self.add(circle)
self.play(UpdateFromFunc(circle, update_func))
```
### ValueTracker
Animate a value over time:
```python theme={null}
tracker = ValueTracker(0)
def update_circle(circle):
circle.move_to(RIGHT * tracker.get_value())
circle = Circle()
circle.add_updater(update_circle)
self.add(circle)
self.play(tracker.animate.set_value(3), run_time=2)
```
### Updaters
Continuous updates during animation:
```python theme={null}
def update_text(text):
text.next_to(circle.get_center(), UP)
circle = Circle()
text = Text("Follow me")
text.add_updater(update_text)
self.add(circle, text)
self.play(circle.animate.shift(RIGHT * 3))
```
## Animation Timing
### Wait Duration
```python theme={null}
# Wait 1 second
self.wait()
# Wait 2 seconds
self.wait(2)
# Wait 0.5 seconds
self.wait(0.5)
```
### Controlling Speed
```python theme={null}
# Default speed
self.play(Create(circle))
# Slow motion (2x slower)
self.play(Create(circle), run_time=2)
# Fast forward (2x faster)
self.play(Create(circle), run_time=0.5)
```
## Best Practices
Choose run times that feel natural:
```python theme={null}
# Good - gives viewers time to process
self.play(Write(important_equation), run_time=2)
self.wait(1)
# Too fast - hard to follow
self.play(Write(important_equation), run_time=0.2)
```
```python theme={null}
# Good - simultaneous related actions
self.play(
circle.animate.shift(RIGHT),
square.animate.shift(LEFT)
)
# Less effective - sequential when simultaneous makes sense
self.play(circle.animate.shift(RIGHT))
self.play(square.animate.shift(LEFT))
```
```python theme={null}
# Smooth for most animations
self.play(mob.animate.shift(UP), rate_func=smooth)
# Linear for constant motion
self.play(mob.animate.shift(RIGHT), rate_func=linear)
# Rush for dramatic effect
self.play(mob.animate.scale(2), rate_func=rush_into)
```
```python theme={null}
# Preferred - clear and concise
self.play(circle.animate.shift(RIGHT).scale(2))
# Avoid - more verbose
self.play(
ApplyMethod(circle.shift, RIGHT),
ApplyMethod(circle.scale, 2)
)
```
## Common Patterns
### Intro → Content → Outro
```python theme={null}
class StandardPattern(Scene):
def construct(self):
# Intro
title = Text("My Topic")
self.play(Write(title))
self.wait()
self.play(FadeOut(title))
# Content
circle = Circle()
self.play(Create(circle))
self.play(circle.animate.scale(2))
self.wait()
# Outro
self.play(FadeOut(circle))
```
### Build Up Gradually
```python theme={null}
class BuildUp(Scene):
def construct(self):
elements = VGroup(*[Square() for _ in range(4)])
elements.arrange(RIGHT, buff=0.5)
# Add one at a time
for elem in elements:
self.play(FadeIn(elem))
self.wait(0.3)
```
### Transform Chain
```python theme={null}
class TransformChain(Scene):
def construct(self):
shapes = [Circle(), Square(), Triangle(), Star()]
current = shapes[0]
self.play(Create(current))
for next_shape in shapes[1:]:
self.wait(0.5)
self.play(Transform(current, next_shape))
```
## Next Steps
Complete animations API
Learn about animatable objects
Browse animation examples
Explore timing functions
# Cameras
Source: https://manimvtk.mathify.dev/concepts/cameras
Understanding and controlling cameras in ManimVTK
## Camera Basics
The camera determines what is visible in your scene and from what perspective. ManimVTK provides different camera types for different needs.
For 2D scenes, the camera is mostly invisible. For 3D scenes, camera control is essential.
## Camera Types
### 2D Camera (Scene)
The default camera for 2D scenes:
```python theme={null}
class Basic2D(Scene):
def construct(self):
circle = Circle()
self.play(Create(circle))
# Camera is fixed, looking straight at the XY plane
```
**Characteristics:**
* Fixed perspective
* Orthographic projection
* Default view: looking down Z-axis
### 3D Camera (ThreeDScene)
Camera with full 3D control:
```python theme={null}
class Basic3D(ThreeDScene):
def construct(self):
# Set camera angle
self.set_camera_orientation(
phi=60 * DEGREES,
theta=30 * DEGREES
)
sphere = Sphere()
self.play(Create(sphere))
```
**Characteristics:**
* Adjustable viewing angle
* Can rotate around objects
* Perspective projection
### Moving Camera (MovingCameraScene)
Camera that can zoom and pan in 2D:
```python theme={null}
class MovingCamera(MovingCameraScene):
def construct(self):
square = Square()
self.add(square)
# Zoom in
self.play(self.camera.frame.animate.scale(0.5))
# Pan to the right
self.play(self.camera.frame.animate.shift(RIGHT * 2))
```
## 3D Camera Control
### Setting Initial Orientation
```python theme={null}
class CameraOrientation(ThreeDScene):
def construct(self):
# Set at the beginning
self.set_camera_orientation(
phi=75 * DEGREES, # Vertical angle (0 = top view, 90 = side view)
theta=-30 * DEGREES, # Horizontal rotation
distance=8, # Distance from origin
gamma=0 * DEGREES # Camera roll (usually 0)
)
# Add objects
axes = ThreeDAxes()
self.add(axes)
```
**Understanding angles:**
* **phi**: Vertical angle from Z-axis (0° = top, 90° = side)
* **theta**: Horizontal rotation around Z-axis
* **distance**: How far the camera is from the origin
* **gamma**: Camera rotation (tilt)
### Animating Camera Movement
```python theme={null}
class CameraMovement(ThreeDScene):
def construct(self):
sphere = Sphere()
self.add(sphere)
# Initial position
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
self.wait()
# Move camera
self.move_camera(
phi=90 * DEGREES,
theta=45 * DEGREES,
run_time=3
)
self.wait()
```
### Ambient Camera Rotation
Continuous rotation for showcasing 3D objects:
```python theme={null}
class AmbientRotation(ThreeDScene):
def construct(self):
torus = Torus()
self.add(torus)
# Start rotation
self.begin_ambient_camera_rotation(rate=0.2)
# Let it rotate for 5 seconds
self.wait(5)
# Stop rotation
self.stop_ambient_camera_rotation()
```
**Rate parameter:**
* Positive: Counter-clockwise rotation
* Negative: Clockwise rotation
* Typical values: 0.1 to 0.3
### Camera at a Specific Point
Point camera at an object:
```python theme={null}
class LookAtPoint(ThreeDScene):
def construct(self):
# Create objects at different locations
sphere1 = Sphere().shift(LEFT * 2)
sphere2 = Sphere().shift(RIGHT * 2)
self.add(sphere1, sphere2)
# Look at first sphere
self.set_camera_orientation(phi=60 * DEGREES, theta=0)
self.wait()
# Adjust to look at second sphere
self.move_camera(theta=30 * DEGREES, run_time=2)
self.wait()
```
## Moving Camera (2D)
### Frame Control
```python theme={null}
class FrameControl(MovingCameraScene):
def construct(self):
# Get the camera frame
frame = self.camera.frame
# Create content larger than the frame
grid = NumberPlane(x_range=[-10, 10], y_range=[-10, 10])
self.add(grid)
# Pan around
self.play(frame.animate.shift(RIGHT * 3))
self.play(frame.animate.shift(UP * 2))
# Return to origin
self.play(frame.animate.move_to(ORIGIN))
```
### Zooming
```python theme={null}
class ZoomExample(MovingCameraScene):
def construct(self):
circle = Circle(radius=0.1)
text = Text("Tiny text", font_size=12).next_to(circle, UP, buff=0.1)
self.add(circle, text)
# Zoom in to see details
self.play(self.camera.frame.animate.scale(0.2))
self.wait()
# Zoom out
self.play(self.camera.frame.animate.scale(5))
self.wait()
```
### Following Objects
```python theme={null}
class FollowObject(MovingCameraScene):
def construct(self):
dot = Dot()
self.add(dot)
# Camera follows the dot
self.camera.frame.add_updater(
lambda m: m.move_to(dot.get_center())
)
# Move the dot around
self.play(dot.animate.shift(RIGHT * 5), run_time=3)
self.play(dot.animate.shift(UP * 3), run_time=2)
# Stop following
self.camera.frame.clear_updaters()
```
## Camera Presets
### Common 3D Views
```python theme={null}
class CommonViews(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
self.add(axes)
# Top view
self.set_camera_orientation(phi=0, theta=0)
self.wait()
# Front view
self.move_camera(phi=90 * DEGREES, theta=0)
self.wait()
# Side view
self.move_camera(phi=90 * DEGREES, theta=90 * DEGREES)
self.wait()
# Isometric view
self.move_camera(phi=60 * DEGREES, theta=45 * DEGREES)
self.wait()
```
### Reset Camera
```python theme={null}
# Reset to default position
self.set_camera_orientation(phi=0, theta=0, distance=8)
# Or in MovingCameraScene
self.play(self.camera.frame.animate.move_to(ORIGIN).scale(1))
```
## Advanced Techniques
### Camera Along Path
```python theme={null}
class CameraPath(ThreeDScene):
def construct(self):
surface = Sphere()
self.add(surface)
# Define camera positions
positions = [
(60 * DEGREES, 0 * DEGREES),
(60 * DEGREES, 90 * DEGREES),
(60 * DEGREES, 180 * DEGREES),
(60 * DEGREES, 270 * DEGREES),
(60 * DEGREES, 360 * DEGREES),
]
# Move through positions
for phi, theta in positions:
self.move_camera(phi=phi, theta=theta, run_time=1.5)
```
### Combine Zoom and Pan
```python theme={null}
class ZoomAndPan(MovingCameraScene):
def construct(self):
shapes = VGroup(*[Square() for _ in range(9)])
shapes.arrange_in_grid(3, 3, buff=1)
self.add(shapes)
# Zoom and pan to top-left square
self.play(
self.camera.frame.animate
.scale(0.3)
.move_to(shapes[0])
)
self.wait()
```
### Smooth Camera Transitions
```python theme={null}
class SmoothTransition(ThreeDScene):
def construct(self):
cube = Cube()
self.add(cube)
# Smooth camera movement with rate function
self.set_camera_orientation(phi=60 * DEGREES, theta=0)
self.move_camera(
phi=90 * DEGREES,
theta=180 * DEGREES,
run_time=4,
rate_func=smooth # Smooth ease in/out
)
```
## Best Practices
* **2D content**: Use standard `Scene`
* **3D objects**: Use `ThreeDScene` with good phi/theta
* **Detail work**: Use `MovingCameraScene` to zoom
```python theme={null}
# Good - slow enough to follow
self.move_camera(phi=90 * DEGREES, run_time=3)
# Too fast - disorienting
self.move_camera(phi=90 * DEGREES, run_time=0.2)
```
Set initial camera position that shows your object well:
```python theme={null}
# Good starting point for most 3D objects
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
```
```python theme={null}
# Good - slow rotation for showcase
self.begin_ambient_camera_rotation(rate=0.1)
# Too fast - nauseating
self.begin_ambient_camera_rotation(rate=1.0)
```
## Camera Configuration
### Via Code
```python theme={null}
# In your scene
class ConfiguredCamera(ThreeDScene):
def construct(self):
# Camera settings
self.camera.frame_width = 15
self.camera.frame_height = 15
# Your content
sphere = Sphere()
self.add(sphere)
```
### Via Config File
```ini theme={null}
[camera]
frame_width = 15
frame_height = 15
```
## Common Patterns
### Orbit Around Object
```python theme={null}
class OrbitPattern(ThreeDScene):
def construct(self):
obj = Torus()
self.add(obj)
# Set initial position
self.set_camera_orientation(phi=60 * DEGREES, theta=0)
# Orbit 360 degrees
self.move_camera(theta=360 * DEGREES, run_time=8)
```
### Zoom to Detail
```python theme={null}
class ZoomToDetail(MovingCameraScene):
def construct(self):
# Large scene
full_scene = VGroup(*[Circle() for _ in range(20)])
full_scene.arrange_in_grid(4, 5)
self.add(full_scene)
self.wait()
# Zoom to one element
target = full_scene[5]
self.play(
self.camera.frame.animate
.scale(0.2)
.move_to(target)
)
self.wait()
```
### Pan Across Scene
```python theme={null}
class PanAcross(MovingCameraScene):
def construct(self):
# Create wide content
content = VGroup(
Text("Part 1").shift(LEFT * 6),
Text("Part 2"),
Text("Part 3").shift(RIGHT * 6)
)
self.add(content)
# Pan from left to right
self.camera.frame.move_to(LEFT * 6)
self.play(
self.camera.frame.animate.move_to(ORIGIN),
run_time=3
)
self.play(
self.camera.frame.animate.move_to(RIGHT * 6),
run_time=3
)
```
## Next Steps
Learn about different rendering backends
ThreeDScene API reference
See camera control examples
VTK rendering for 3D
# Mobjects
Source: https://manimvtk.mathify.dev/concepts/mobjects
Understanding and working with Manim objects (Mobjects)
## What are Mobjects?
**Mobjects** (Manim Objects) are the visual elements in your scenes - everything you see in a ManimVTK animation is a mobject:
* Geometric shapes (circles, squares, polygons)
* 3D objects (spheres, cubes, surfaces)
* Text and mathematical equations
* Graphs, plots, and coordinate systems
* Custom drawn paths
Mobjects are the building blocks of ManimVTK - understanding them is key to creating great animations
## Mobject Hierarchy
```
Mobject (base class)
├── VMobject (vectorized 2D shapes)
│ ├── Circle, Square, Triangle
│ ├── Line, Arrow, Vector
│ ├── Text, Tex, MathTex
│ └── Polygon, Rectangle
├── ThreeDMobject (3D objects)
│ ├── Sphere, Cube, Cone
│ ├── Surface, ParametricSurface
│ └── Prism, Cylinder, Torus
└── VGroup (container for grouping)
```
## Creating Mobjects
### Basic 2D Shapes
```python theme={null}
from manimvtk import *
class BasicShapes(Scene):
def construct(self):
# Circle
circle = Circle(radius=1, color=BLUE)
# Square
square = Square(side_length=2, color=RED)
# Triangle
triangle = Triangle(color=GREEN)
# Rectangle
rectangle = Rectangle(width=3, height=1.5, color=YELLOW)
# Arrange and display
shapes = VGroup(circle, square, triangle, rectangle)
shapes.arrange(RIGHT, buff=0.5)
self.play(Create(shapes))
self.wait()
```
### Basic 3D Objects
```python theme={null}
from manimvtk import *
class Basic3DObjects(ThreeDScene):
def construct(self):
# Sphere
sphere = Sphere(radius=1, color=BLUE)
# Cube
cube = Cube(side_length=1.5, color=RED)
# Cone
cone = Cone(base_radius=0.5, height=1, color=GREEN)
# Arrange
objects = VGroup(sphere, cube, cone)
objects.arrange(RIGHT, buff=1.5)
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
self.play(Create(objects))
self.wait()
```
### Text and Math
```python theme={null}
from manimvtk import *
class TextAndMath(Scene):
def construct(self):
# Regular text
text = Text("Hello, ManimVTK!", font_size=48)
# Mathematical equation
equation = MathTex(r"E = mc^2")
# Arrange vertically
VGroup(text, equation).arrange(DOWN, buff=1)
self.play(Write(text))
self.play(Write(equation))
self.wait()
```
## Mobject Properties
### Color
```python theme={null}
# Set color at creation
circle = Circle(color=BLUE)
# Set color after creation
circle.set_color(RED)
# Gradient color
square = Square()
square.set_color_by_gradient(BLUE, RED)
# RGB values
circle.set_color(rgb_to_color([0.5, 0.7, 0.9]))
```
### Opacity
```python theme={null}
# Stroke opacity (outline)
circle.set_stroke(opacity=0.8)
# Fill opacity (interior)
circle.set_fill(opacity=0.5)
# Overall opacity
circle.set_opacity(0.7)
```
### Size
```python theme={null}
# Scale
circle.scale(2) # 2x larger
circle.scale(0.5) # Half size
# Set specific dimensions
rectangle.width = 3
rectangle.height = 2
# Stretch in one direction
square.stretch(2, 0) # Stretch horizontally
```
### Position
```python theme={null}
# Shift (relative movement)
circle.shift(RIGHT * 2)
circle.shift(UP + LEFT)
# Move to absolute position
circle.move_to(ORIGIN)
circle.move_to([1, 2, 0])
# Align
circle.to_edge(LEFT)
circle.to_corner(UR) # Upper right
```
### Rotation
```python theme={null}
# Rotate around center
square.rotate(PI / 4) # 45 degrees
# Rotate around a point
square.rotate(PI / 4, about_point=ORIGIN)
# Rotate around axis (3D)
cube.rotate(PI / 2, axis=UP)
```
## Styling Mobjects
### Stroke (Outline)
```python theme={null}
circle = Circle()
# Stroke color
circle.set_stroke(color=BLUE)
# Stroke width
circle.set_stroke(width=5)
# Combine
circle.set_stroke(color=BLUE, width=3, opacity=0.8)
```
### Fill (Interior)
```python theme={null}
square = Square()
# Fill color
square.set_fill(color=RED)
# Fill opacity
square.set_fill(opacity=0.5)
# Combine
square.set_fill(color=RED, opacity=0.7)
```
### Combining Stroke and Fill
```python theme={null}
# Circle with blue fill and red outline
circle = Circle()
circle.set_fill(BLUE, opacity=0.5)
circle.set_stroke(RED, width=3)
```
## Grouping Mobjects
### VGroup
Group multiple mobjects together:
```python theme={null}
# Create individual shapes
c1 = Circle()
c2 = Square()
c3 = Triangle()
# Group them
group = VGroup(c1, c2, c3)
# Operations on group affect all members
group.arrange(RIGHT, buff=1)
group.set_color(BLUE)
group.scale(0.5)
```
### Arrangement
```python theme={null}
shapes = VGroup(*[Circle() for _ in range(6)])
# Arrange in a row
shapes.arrange(RIGHT, buff=0.5)
# Arrange in a column
shapes.arrange(DOWN, buff=0.5)
# Arrange in a grid
shapes.arrange_in_grid(rows=2, cols=3, buff=0.5)
# Arrange in a circle
shapes.arrange_in_circle()
```
## Copying Mobjects
```python theme={null}
# Simple copy
circle1 = Circle()
circle2 = circle1.copy()
# Copy and modify
circle2.shift(RIGHT * 2)
circle2.set_color(RED)
# Deep copy (for complex objects)
import copy
complex_group = VGroup(...)
copy_of_group = copy.deepcopy(complex_group)
```
## Mobject Methods
### Common Methods
Get the center point:
```python theme={null}
center = circle.get_center()
print(center) # [x, y, z]
```
Get dimensions:
```python theme={null}
width = rectangle.get_width()
height = rectangle.get_height()
```
Get current color:
```python theme={null}
color = circle.get_color()
```
Rotate the mobject:
```python theme={null}
square.rotate(PI / 4)
```
Scale the mobject:
```python theme={null}
circle.scale(2) # Double size
```
Move relative to current position:
```python theme={null}
circle.shift(RIGHT * 2 + UP)
```
### Alignment Methods
```python theme={null}
# Align to edges
mobject.to_edge(UP)
mobject.to_edge(LEFT)
# Align to corners
mobject.to_corner(UL) # Upper left
mobject.to_corner(DR) # Down right
# Align relative to other mobject
circle.next_to(square, RIGHT)
circle.next_to(square, DOWN, buff=0.5)
# Move to specific position
mobject.move_to(ORIGIN)
mobject.move_to([1, 2, 0])
```
## Custom Mobjects
### Creating Custom Shapes
```python theme={null}
from manimvtk import *
class CustomStar(VMobject):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Define your custom shape
points = [...] # Define points
self.set_points_as_corners(points)
```
### Using Paths
```python theme={null}
# Custom path
path = VMobject()
path.set_points_as_corners([
ORIGIN,
UP,
UP + RIGHT,
RIGHT
])
path.set_stroke(BLUE, width=3)
```
## Surfaces and Parametric Objects
### Parametric Surface
```python theme={null}
from manimvtk import *
import numpy as np
class ParametricSurfaceExample(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([
u,
v,
np.sin(u) * np.cos(v)
]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(30, 30)
)
surface.set_color_by_gradient(BLUE, GREEN, RED)
self.set_camera_orientation(phi=60 * DEGREES)
self.play(Create(surface))
self.wait()
```
### Common Parametric Surfaces
```python theme={null}
# Torus
torus = Surface(
lambda u, v: np.array([
(2 + np.cos(v)) * np.cos(u),
(2 + np.cos(v)) * np.sin(u),
np.sin(v)
]),
u_range=[0, TAU],
v_range=[0, TAU]
)
# Sphere (parametric)
sphere = Surface(
lambda u, v: np.array([
np.cos(u) * np.cos(v),
np.sin(u) * np.cos(v),
np.sin(v)
]),
u_range=[0, TAU],
v_range=[-PI/2, PI/2]
)
```
## Best Practices
Set properties when creating:
```python theme={null}
# Good
circle = Circle(radius=2, color=BLUE, fill_opacity=0.5)
# Less efficient
circle = Circle()
circle.scale(2)
circle.set_color(BLUE)
circle.set_fill(opacity=0.5)
```
```python theme={null}
# Good - reuse and transform
circle = Circle()
self.play(Create(circle))
self.play(circle.animate.shift(RIGHT))
# Avoid - creating new objects
circle1 = Circle()
self.play(Create(circle1))
circle2 = Circle().shift(RIGHT)
self.play(Transform(circle1, circle2))
```
```python theme={null}
# Organize related objects
axes_group = VGroup(x_axis, y_axis, labels)
data_group = VGroup(points, lines, curves)
# Easy to manipulate together
axes_group.shift(LEFT * 3)
data_group.set_color(BLUE)
```
Define color schemes:
```python theme={null}
PRIMARY = BLUE
SECONDARY = RED
ACCENT = YELLOW
title = Text("Title", color=PRIMARY)
shape = Circle(color=SECONDARY)
highlight = Square(color=ACCENT)
```
## Next Steps
Learn how to animate mobjects
Complete geometry API reference
Complete 3D objects API
See mobject examples
# Renderers
Source: https://manimvtk.mathify.dev/concepts/renderers
Understanding ManimVTK's rendering backends
## Renderer Overview
ManimVTK supports three rendering backends, each optimized for different use cases:
**2D Vector Graphics**
Best for 2D animations and diagrams
**3D Hardware Acceleration**
Fast real-time 3D rendering
**Scientific Visualization**
High-quality 3D with VTK export
## Selecting a Renderer
### Via Command Line
```bash theme={null}
# Cairo (default)
manimvtk -pqh scene.py MyScene
# OpenGL
manimvtk -pqh scene.py MyScene --renderer opengl
# VTK
manimvtk -pqh scene.py MyScene --renderer vtk
```
### Via Configuration
In `manim.cfg`:
```ini theme={null}
[CLI]
renderer = vtk
```
## Cairo Renderer
The default renderer, based on the Cairo graphics library.
### Characteristics
* ✅ **Excellent 2D quality**: Sharp vector graphics
* ✅ **Text rendering**: High-quality text and LaTeX
* ✅ **Mature and stable**: Well-tested, minimal bugs
* ⚠️ **2D focused**: Basic 3D support only
* ⚠️ **CPU-based**: No GPU acceleration
### Best For
* 2D mathematical animations
* Educational diagrams
* Text-heavy content
* Precise vector graphics
### Example
```python theme={null}
from manimvtk import *
class CairoExample(Scene):
def construct(self):
# Perfect for 2D
equation = MathTex(r"e^{i\pi} + 1 = 0")
self.play(Write(equation))
self.wait()
```
```bash theme={null}
# Render with Cairo (default)
manimvtk -pqh scene.py CairoExample
```
## OpenGL Renderer
Hardware-accelerated rendering using OpenGL.
### Characteristics
* ✅ **Fast**: GPU-accelerated
* ✅ **Real-time preview**: Interactive viewing
* ✅ **3D support**: Good 3D capabilities
* ⚠️ **Less mature**: May have edge cases
* ⚠️ **Platform-dependent**: Requires OpenGL drivers
### Best For
* Interactive development
* Real-time previews
* 3D animations (lighter-weight than VTK)
* Fast iteration
### Example
```python theme={null}
from manimvtk import *
class OpenGLExample(ThreeDScene):
def construct(self):
sphere = Sphere()
self.set_camera_orientation(phi=60 * DEGREES)
self.play(Create(sphere))
self.wait()
```
```bash theme={null}
# Render with OpenGL
manimvtk -pqh scene.py OpenGLExample --renderer opengl
```
## VTK Renderer
Scientific visualization renderer with VTK export capabilities.
### Characteristics
* ✅ **Scientific quality**: Publication-grade 3D
* ✅ **VTK export**: Export to .vtp, .vtm, .pvd formats
* ✅ **Advanced lighting**: Realistic shading
* ✅ **ParaView integration**: Direct export to ParaView
* ⚠️ **Slower startup**: VTK initialization overhead
* ⚠️ **3D focused**: Best for 3D content
### Best For
* Scientific visualization
* 3D surfaces and meshes
* CFD/FEA visualization
* ParaView workflows
* High-quality 3D renders
### Example
```python theme={null}
from manimvtk import *
import numpy as np
class VTKExample(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([u, v, np.sin(u) * np.cos(v)]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50)
)
surface.set_color_by_gradient(BLUE, RED)
self.set_camera_orientation(phi=60 * DEGREES)
self.play(Create(surface))
self.wait()
```
```bash theme={null}
# Render with VTK and export
manimvtk -pqh scene.py VTKExample --renderer vtk --vtk-export
```
Detailed guide on VTK renderer features
## Renderer Comparison
| Feature | Cairo | OpenGL | VTK |
| -------------------- | ----------- | ----------- | --------- |
| **2D Quality** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ |
| **3D Quality** | ⭐ | ⭐⭐ | ⭐⭐⭐ |
| **Performance** | ⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
| **Text/LaTeX** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ |
| **Stability** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ |
| **Export Formats** | Image/Video | Image/Video | VTK Files |
| **GPU Acceleration** | ❌ | ✅ | ✅ |
| **Scientific Use** | ⭐ | ⭐⭐ | ⭐⭐⭐ |
## Choosing the Right Renderer
### Decision Tree
```
Are you creating 2D content?
├─ Yes → Use Cairo
└─ No (3D content)
├─ Need VTK export?
│ └─ Yes → Use VTK
└─ Need fast preview?
├─ Yes → Use OpenGL
└─ Need highest quality → Use VTK
```
### Use Cases
**Recommendation: Cairo**
Most educational content is 2D:
* Equations and text
* 2D graphs
* Geometric diagrams
```bash theme={null}
manimvtk -pqh lesson.py Lecture
```
**Recommendation: VTK**
Scientific work needs VTK export:
* Surface meshes
* CFD data
* ParaView integration
```bash theme={null}
manimvtk -pqh simulation.py CFDViz --renderer vtk --vtk-export
```
**Recommendation: OpenGL or VTK**
3D demonstrations:
* Product visualizations
* Architecture
* Mathematical surfaces
```bash theme={null}
# Fast preview
manimvtk -pql demo.py Product --renderer opengl
# Final quality
manimvtk -pqh demo.py Product --renderer vtk
```
**Recommendation: OpenGL (low quality)**
Fast iteration:
* Testing animations
* Debugging layouts
* Quick previews
```bash theme={null}
manimvtk -ql test.py TestScene --renderer opengl
```
## Renderer-Specific Features
### Cairo Only
* **Precise 2D rendering**: Perfect for diagrams
* **Text shaping**: Advanced typography
* **SVG-like quality**: Clean vector output
### OpenGL Only
* **Interactive preview**: Real-time interaction
* **Fast rendering**: GPU acceleration
* **Window mode**: Live preview window
### VTK Only
* **VTK file export**: .vtp, .vtm, .pvd formats
* **Scientific data**: Scalar/vector fields
* **Advanced shading**: Physically-based rendering
* **ParaView compatibility**: Direct export
## Switching Renderers
You can use different renderers for the same scene:
```python theme={null}
class UniversalScene(ThreeDScene):
def construct(self):
sphere = Sphere()
self.set_camera_orientation(phi=60 * DEGREES)
self.play(Create(sphere))
self.wait()
```
```bash theme={null}
# Test with OpenGL (fast)
manimvtk -ql scene.py UniversalScene --renderer opengl
# Final render with VTK (quality)
manimvtk -qh scene.py UniversalScene --renderer vtk --vtk-export
# Alternative with Cairo (if 2D is enough)
manimvtk -qh scene.py UniversalScene
```
## Performance Considerations
### Cairo
* **Startup**: Fast
* **Rendering**: Moderate (CPU-bound)
* **Memory**: Low to moderate
* **Best for**: Small to medium 2D scenes
### OpenGL
* **Startup**: Moderate
* **Rendering**: Fast (GPU-accelerated)
* **Memory**: Moderate
* **Best for**: Large 3D scenes, development
### VTK
* **Startup**: Slow (VTK initialization)
* **Rendering**: Moderate to slow
* **Memory**: Higher (complex meshes)
* **Best for**: Final quality renders, export
## Troubleshooting
**Cause:** OpenGL drivers not available
**Solution:**
```bash theme={null}
# On headless servers
xvfb-run -a manimvtk -pqh scene.py MyScene --renderer opengl
# Or use Cairo/VTK instead
manimvtk -pqh scene.py MyScene --renderer cairo
```
**Cause:** VTK not installed
**Solution:**
```bash theme={null}
pip install vtk
# Or reinstall with VTK extras
pip install manimvtk[vtk]
```
**Cause:** Cairo is optimized for 2D
**Solution:**
Switch to VTK or OpenGL for 3D:
```bash theme={null}
manimvtk -pqh scene.py MyScene --renderer vtk
```
**Cause:** Complex geometry or wrong renderer
**Solution:**
* Use lower quality for testing: `-ql`
* Use OpenGL for faster preview
* Reduce geometry resolution
## Best Practices
```bash theme={null}
# Testing - fast
manimvtk -ql scene.py Test --renderer opengl
# Final 2D - quality
manimvtk -qh scene.py Final
# Final 3D with export - quality + export
manimvtk -qh scene.py Final --renderer vtk --vtk-export
```
Most code works across all renderers:
```python theme={null}
# This works with any renderer
class AgnosticScene(Scene):
def construct(self):
circle = Circle()
self.play(Create(circle))
```
Verify your scene works across renderers:
```bash theme={null}
manimvtk -ql scene.py Test --renderer cairo
manimvtk -ql scene.py Test --renderer opengl
manimvtk -ql scene.py Test --renderer vtk
```
## Next Steps
Detailed VTK renderer guide
Learn about VTK file export
Configure renderer settings
All command-line options
# Scenes
Source: https://manimvtk.mathify.dev/concepts/scenes
Understanding scenes and the construct method in ManimVTK
## What is a Scene?
A **Scene** is the fundamental building block of ManimVTK. It's a container for your animation that manages:
* **Mobjects** (visual objects)
* **Animations** (movements and transformations)
* **Camera** (viewpoint and perspective)
* **Rendering** (video output and VTK export)
Every ManimVTK animation starts with a scene class.
## Basic Scene Structure
```python theme={null}
from manimvtk import *
class MyScene(Scene):
def construct(self):
# Your animation code goes here
pass
```
**Key components:**
1. **Import**: `from manimvtk import *`
2. **Class definition**: Inherit from `Scene`
3. **construct() method**: Where you build your animation
## The construct() Method
The `construct()` method is where all your animation logic lives:
```python theme={null}
class SimpleAnimation(Scene):
def construct(self):
# Create objects
circle = Circle(radius=1, color=BLUE)
# Add to scene
self.add(circle)
# Animate
self.play(circle.animate.scale(2))
# Wait
self.wait()
```
The `construct()` method is called automatically when you render the scene
## Scene Types
ManimVTK provides several scene types for different use cases:
**Basic 2D scene** - Default scene type
```python theme={null}
class Basic2D(Scene):
def construct(self):
square = Square()
self.play(Create(square))
```
**Use for:**
* 2D animations
* Graphs and plots
* Educational diagrams
**3D scene with camera controls**
```python theme={null}
class Basic3D(ThreeDScene):
def construct(self):
# Set camera angle
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
# Add 3D object
sphere = Sphere()
self.play(Create(sphere))
```
**Use for:**
* 3D visualizations
* Surfaces and parametric objects
* Scientific simulations
**Scene with movable camera**
```python theme={null}
class CameraMove(MovingCameraScene):
def construct(self):
square = Square()
self.add(square)
# Zoom in
self.play(self.camera.frame.animate.scale(0.5))
```
**Use for:**
* Zooming animations
* Pan and scan effects
* Focus on details
**Scene with picture-in-picture zoom**
```python theme={null}
class ZoomExample(ZoomedScene):
def construct(self):
# Main content
dots = VGroup(*[Dot() for _ in range(10)]).arrange_in_grid()
self.add(dots)
# Create zoomed camera
zoomed_camera = self.zoomed_camera
# Activate zoom
self.activate_zooming()
```
**Use for:**
* Detail views
* Magnification effects
* Complex diagrams
## Adding Objects to a Scene
### Using add()
Instantly add objects without animation:
```python theme={null}
class AddExample(Scene):
def construct(self):
circle = Circle()
square = Square()
# Add instantly (no animation)
self.add(circle, square)
self.wait()
```
### Using play()
Add objects with animation:
```python theme={null}
class PlayExample(Scene):
def construct(self):
circle = Circle()
# Add with creation animation
self.play(Create(circle))
self.wait()
```
### Adding Multiple Objects
```python theme={null}
class MultipleObjects(Scene):
def construct(self):
# Create a group
shapes = VGroup(
Circle(),
Square(),
Triangle()
).arrange(RIGHT, buff=1)
# Add all at once
self.play(Create(shapes))
self.wait()
```
## Scene Methods
### Animation Control
Play one or more animations:
```python theme={null}
self.play(Create(circle))
self.play(Transform(square, circle))
# Multiple animations simultaneously
self.play(
Create(circle),
FadeIn(text)
)
```
Pause the animation:
```python theme={null}
self.wait() # Wait 1 second (default)
self.wait(2) # Wait 2 seconds
self.wait(0.5) # Wait 0.5 seconds
```
Add objects without animation:
```python theme={null}
self.add(circle)
self.add(square, triangle) # Multiple objects
```
Remove objects from scene:
```python theme={null}
self.remove(circle)
self.remove(square, triangle)
```
### Camera Control (ThreeDScene)
Set the initial camera position:
```python theme={null}
self.set_camera_orientation(
phi=60 * DEGREES, # Vertical angle
theta=30 * DEGREES, # Horizontal angle
distance=8 # Distance from origin
)
```
Start continuous camera rotation:
```python theme={null}
self.begin_ambient_camera_rotation(rate=0.1)
self.wait(5) # Rotate for 5 seconds
self.stop_ambient_camera_rotation()
```
Animate camera movement:
```python theme={null}
self.move_camera(
phi=75 * DEGREES,
theta=45 * DEGREES,
run_time=2
)
```
## Scene Lifecycle
Understanding the order of operations:
```python theme={null}
class LifecycleExample(Scene):
def construct(self):
# 1. Object creation
circle = Circle()
# 2. Add to scene (instant)
self.add(circle)
# 3. Animations
self.play(circle.animate.scale(2))
# 4. Wait/pause
self.wait()
# 5. More animations
self.play(FadeOut(circle))
# 6. Scene ends (automatic rendering)
```
**Rendering process:**
1. `construct()` method executes
2. Animations are recorded
3. Frames are generated
4. Video is encoded
5. VTK export (if requested)
## Configuration
### In Scene Class
```python theme={null}
class ConfiguredScene(Scene):
def construct(self):
# Access config
print(f"Frame rate: {config.frame_rate}")
print(f"Resolution: {config.pixel_width}x{config.pixel_height}")
# Your animation
circle = Circle()
self.play(Create(circle))
```
### Via Command Line
```bash theme={null}
# Set quality
manimvtk -qh scene.py MyScene # High quality
# Set frame rate
manimvtk -r 60 scene.py MyScene # 60 fps
# Set resolution
manimvtk --resolution 1920,1080 scene.py MyScene
```
### Via Config File
Create `manim.cfg`:
```ini theme={null}
[CLI]
quality = high
frame_rate = 60
background_color = BLACK
```
## Common Patterns
### Simple Animation
```python theme={null}
class SimplePattern(Scene):
def construct(self):
# Create → Animate → Remove
obj = Circle()
self.play(Create(obj))
self.play(obj.animate.shift(RIGHT))
self.play(FadeOut(obj))
```
### Sequential Animations
```python theme={null}
class Sequential(Scene):
def construct(self):
objs = VGroup(*[Circle() for _ in range(3)])
objs.arrange(RIGHT, buff=1)
# Animate one by one
for obj in objs:
self.play(Create(obj))
self.wait()
```
### Simultaneous Animations
```python theme={null}
class Simultaneous(Scene):
def construct(self):
c1 = Circle().shift(LEFT)
c2 = Circle().shift(RIGHT)
# Both at the same time
self.play(
Create(c1),
Create(c2)
)
```
### Build Up and Transform
```python theme={null}
class BuildAndTransform(Scene):
def construct(self):
# Build up
circle = Circle()
self.play(Create(circle))
# Transform
square = Square()
self.play(Transform(circle, square))
# Continue with transformed object
self.play(circle.animate.rotate(PI/4))
```
## Best Practices
Break complex scenes into helper methods:
```python theme={null}
class OrganizedScene(Scene):
def construct(self):
self.intro()
self.main_content()
self.outro()
def intro(self):
title = Text("Introduction")
self.play(Write(title))
self.wait()
self.play(FadeOut(title))
def main_content(self):
# Main animation logic
pass
def outro(self):
# Closing
pass
```
```python theme={null}
# Good
class QuadraticFunction(Scene):
pass
# Avoid
class Test1(Scene):
pass
```
Give viewers time to process:
```python theme={null}
self.play(Create(important_diagram))
self.wait(2) # Let viewers see it
self.play(FadeOut(important_diagram))
```
```python theme={null}
# Efficient
circle = Circle()
self.play(Create(circle))
self.play(circle.animate.shift(RIGHT))
# Less efficient
circle1 = Circle()
self.play(Create(circle1))
circle2 = circle1.copy().shift(RIGHT)
self.play(Transform(circle1, circle2))
```
## Debugging Scenes
### Print Debug Info
```python theme={null}
class DebugScene(Scene):
def construct(self):
circle = Circle()
# Debug output
print(f"Circle center: {circle.get_center()}")
print(f"Circle color: {circle.get_color()}")
self.add(circle)
```
### Preview Frames
```bash theme={null}
# Save last frame only (fast)
manimvtk -s scene.py MyScene
# Save all frames
manimvtk --save_sections scene.py MyScene
```
### Use Lower Quality for Testing
```bash theme={null}
# Fast preview
manimvtk -ql scene.py MyScene
# Final render
manimvtk -qh scene.py MyScene
```
## Next Steps
Learn about creating and manipulating objects
Master animation techniques
Control camera movement and perspective
Browse example scenes
# Animation Examples
Source: https://manimvtk.mathify.dev/examples/animations
Advanced animation techniques and patterns
## Animation Patterns
Master common animation patterns used in ManimVTK projects.
## Transformation Chains
```python theme={null}
from manimvtk import *
class TransformChain(Scene):
def construct(self):
# Start with a circle
shapes = [
Circle(color=BLUE),
Square(color=GREEN),
Triangle(color=RED),
Star(color=YELLOW)
]
current = shapes[0]
self.play(Create(current))
# Transform through each shape
for next_shape in shapes[1:]:
self.wait(0.5)
self.play(Transform(current, next_shape))
self.wait()
```
## Lagged Animations
```python theme={null}
from manimvtk import *
class LaggedExample(Scene):
def construct(self):
squares = VGroup(*[
Square(side_length=0.5).shift(RIGHT * i)
for i in range(-3, 4)
])
# Staggered creation
self.play(
LaggedStart(*[Create(s) for s in squares], lag_ratio=0.15)
)
self.wait()
# Staggered color change
self.play(
LaggedStart(*[s.animate.set_color(RED) for s in squares], lag_ratio=0.1)
)
self.wait()
```
## Value Tracking
```python theme={null}
from manimvtk import *
class ValueTrackingExample(Scene):
def construct(self):
# Create a tracker
tracker = ValueTracker(0)
# Create object that follows tracker
dot = Dot()
dot.add_updater(lambda m: m.move_to([tracker.get_value(), 0, 0]))
self.add(dot)
# Animate tracker value
self.play(tracker.animate.set_value(3), run_time=2)
self.play(tracker.animate.set_value(-3), run_time=2)
self.play(tracker.animate.set_value(0), run_time=1)
```
## Next Steps
Complete animations guide
Animations API reference
# Basic 2D Examples
Source: https://manimvtk.mathify.dev/examples/basic-2d
Simple 2D shape and animation examples
## Introduction
Start with these basic 2D examples to learn ManimVTK fundamentals. These examples use the default Cairo renderer and are perfect for beginners.
## Simple Shapes
### Circle Example
```python theme={null}
from manimvtk import *
class CircleExample(Scene):
def construct(self):
circle = Circle(radius=2, color=BLUE, fill_opacity=0.5)
self.play(Create(circle))
self.wait()
```
**Render:**
```bash theme={null}
manimvtk -pql examples.py CircleExample
```
### Multiple Shapes
```python theme={null}
from manimvtk import *
class MultipleShapes(Scene):
def construct(self):
# Create shapes
circle = Circle(radius=1, color=BLUE)
square = Square(side_length=1.5, color=RED)
triangle = Triangle(color=GREEN)
# Arrange horizontally
shapes = VGroup(circle, square, triangle)
shapes.arrange(RIGHT, buff=1)
# Animate
self.play(Create(shapes))
self.wait()
```
### Colored Shapes
```python theme={null}
from manimvtk import *
class ColoredShapes(Scene):
def construct(self):
# Create a grid of colored circles
colors = [RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE]
circles = VGroup(*[
Circle(radius=0.5, color=color, fill_opacity=0.7)
for color in colors
])
circles.arrange_in_grid(rows=2, cols=3, buff=0.5)
# Animate creation with lag
self.play(LaggedStart(*[Create(c) for c in circles], lag_ratio=0.2))
self.wait()
```
## Transformations
### Square to Circle
```python theme={null}
from manimvtk import *
class SquareToCircle(Scene):
def construct(self):
square = Square(color=BLUE, fill_opacity=0.5)
circle = Circle(color=RED, fill_opacity=0.5)
self.play(Create(square))
self.wait()
self.play(Transform(square, circle))
self.wait()
```
### Movement and Rotation
```python theme={null}
from manimvtk import *
class MovementExample(Scene):
def construct(self):
square = Square(color=BLUE)
# Create
self.play(Create(square))
# Move right
self.play(square.animate.shift(RIGHT * 3))
# Rotate
self.play(square.animate.rotate(PI / 4))
# Scale
self.play(square.animate.scale(1.5))
self.wait()
```
## Text and Labels
### Simple Text
```python theme={null}
from manimvtk import *
class TextExample(Scene):
def construct(self):
text = Text("Hello, ManimVTK!", font_size=48, color=BLUE)
self.play(Write(text))
self.wait()
```
### Mathematical Equations
```python theme={null}
from manimvtk import *
class EquationExample(Scene):
def construct(self):
# Pythagorean theorem
equation = MathTex(r"a^2 + b^2 = c^2")
# Write equation
self.play(Write(equation))
self.wait()
# Transform to specific example
example = MathTex(r"3^2 + 4^2 = 5^2")
self.play(Transform(equation, example))
self.wait()
```
### Labeled Shapes
```python theme={null}
from manimvtk import *
class LabeledShapes(Scene):
def construct(self):
circle = Circle(radius=1.5, color=BLUE)
label = Text("Circle", font_size=36).next_to(circle, UP)
group = VGroup(circle, label)
self.play(Create(circle))
self.play(Write(label))
self.wait()
```
## Animation Techniques
### Fade In and Out
```python theme={null}
from manimvtk import *
class FadeExample(Scene):
def construct(self):
shapes = VGroup(*[
Square(side_length=1).shift(direction * 2)
for direction in [LEFT, ORIGIN, RIGHT]
])
# Fade in
self.play(FadeIn(shapes))
self.wait()
# Fade out one by one
for shape in shapes:
self.play(FadeOut(shape))
self.wait()
```
### Indicate and Flash
```python theme={null}
from manimvtk import *
class IndicateExample(Scene):
def construct(self):
squares = VGroup(*[Square() for _ in range(3)])
squares.arrange(RIGHT, buff=1)
self.add(squares)
self.wait()
# Indicate middle square
self.play(Indicate(squares[1]))
self.wait()
# Flash effect
self.play(Flash(squares[0].get_center()))
self.wait()
```
### Growing Animations
```python theme={null}
from manimvtk import *
class GrowExample(Scene):
def construct(self):
shapes = VGroup(
Circle(color=BLUE),
Square(color=RED).shift(RIGHT * 2.5),
Triangle(color=GREEN).shift(LEFT * 2.5)
)
# Grow from center
self.play(*[GrowFromCenter(shape) for shape in shapes])
self.wait()
# Shrink to center
self.play(*[ShrinkToCenter(shape) for shape in shapes])
```
## Groups and Arrangements
### Arranging in Grid
```python theme={null}
from manimvtk import *
class GridArrangement(Scene):
def construct(self):
# Create 12 squares
squares = VGroup(*[Square(side_length=0.5) for _ in range(12)])
# Arrange in 3x4 grid
squares.arrange_in_grid(rows=3, cols=4, buff=0.3)
# Color by row
for i, row in enumerate([squares[0:4], squares[4:8], squares[8:12]]):
row.set_color([RED, GREEN, BLUE][i])
self.play(Create(squares))
self.wait()
```
### Circular Arrangement
```python theme={null}
from manimvtk import *
class CircularArrangement(Scene):
def construct(self):
dots = VGroup(*[Dot() for _ in range(8)])
dots.arrange_in_circle(radius=2)
self.play(LaggedStart(*[GrowFromCenter(dot) for dot in dots], lag_ratio=0.1))
self.wait()
```
## VTK Export Examples
### Export 2D Shapes
```python theme={null}
from manimvtk import *
class Export2DShapes(Scene):
def construct(self):
shapes = VGroup(
Circle(radius=1, color=BLUE, fill_opacity=0.5),
Square(side_length=1.5, color=RED, fill_opacity=0.5),
Triangle(color=GREEN, fill_opacity=0.5)
).arrange(RIGHT, buff=1)
self.play(Create(shapes))
self.wait()
```
**Render with VTK export:**
```bash theme={null}
manimvtk -pql examples.py Export2DShapes --vtk-export
```
This creates both a video and VTK files for further visualization.
## Next Steps
Explore 3D visualization examples
Advanced animation techniques
Learn more about mobjects
Master animation techniques
# Basic 3D Examples
Source: https://manimvtk.mathify.dev/examples/basic-3d
3D objects and visualization examples
## Introduction
3D examples in ManimVTK leverage ThreeDScene for camera control and work best with the VTK or OpenGL renderer.
## Basic 3D Objects
### Sphere Example
```python theme={null}
from manimvtk import *
class SphereExample(ThreeDScene):
def construct(self):
# Set camera angle
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
# Create sphere
sphere = Sphere(radius=1.5, resolution=(20, 20))
sphere.set_color(BLUE)
self.play(Create(sphere))
self.wait()
```
**Render:**
```bash theme={null}
manimvtk -pql examples.py SphereExample --renderer vtk
```
### Multiple 3D Objects
```python theme={null}
from manimvtk import *
class Multiple3DObjects(ThreeDScene):
def construct(self):
self.set_camera_orientation(phi=70 * DEGREES, theta=30 * DEGREES)
# Create objects
sphere = Sphere(radius=0.5, color=BLUE).shift(LEFT * 2)
cube = Cube(side_length=1, color=RED)
cone = Cone(base_radius=0.5, height=1, color=GREEN).shift(RIGHT * 2)
objects = VGroup(sphere, cube, cone)
self.play(Create(objects))
self.begin_ambient_camera_rotation(rate=0.1)
self.wait(5)
self.stop_ambient_camera_rotation()
```
## Parametric Surfaces
### Wave Surface
```python theme={null}
from manimvtk import *
import numpy as np
class WaveSurface(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([
u,
v,
np.sin(u) * np.cos(v)
]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(40, 40)
)
surface.set_color_by_gradient(BLUE, GREEN, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=-45 * DEGREES)
self.play(Create(surface), run_time=2)
self.wait()
```
### Torus
```python theme={null}
from manimvtk import *
import numpy as np
class TorusExample(ThreeDScene):
def construct(self):
torus = Surface(
lambda u, v: np.array([
(2 + np.cos(v)) * np.cos(u),
(2 + np.cos(v)) * np.sin(u),
np.sin(v)
]),
u_range=[0, TAU],
v_range=[0, TAU],
resolution=(40, 40)
)
torus.set_color_by_gradient(BLUE, PURPLE, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
self.play(Create(torus))
self.begin_ambient_camera_rotation(rate=0.15)
self.wait(6)
```
## 3D Animations
### Rotating Cube
```python theme={null}
from manimvtk import *
class RotatingCube(ThreeDScene):
def construct(self):
cube = Cube(side_length=2, fill_opacity=0.7)
cube.set_color_by_gradient(BLUE, GREEN, YELLOW)
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
self.play(Create(cube))
self.play(Rotate(cube, angle=TAU, axis=UP, run_time=4))
self.wait()
```
### Growing Sphere
```python theme={null}
from manimvtk import *
class GrowingSphere(ThreeDScene):
def construct(self):
sphere = Sphere(radius=0.5, color=BLUE)
self.set_camera_orientation(phi=60 * DEGREES)
self.play(GrowFromCenter(sphere))
self.play(sphere.animate.scale(3), run_time=2)
self.wait()
```
## Camera Movement
### Orbiting Camera
```python theme={null}
from manimvtk import *
class OrbitingCamera(ThreeDScene):
def construct(self):
axes = ThreeDAxes()
sphere = Sphere(radius=1, color=BLUE)
self.add(axes, sphere)
# Start from front
self.set_camera_orientation(phi=60 * DEGREES, theta=0)
self.wait()
# Orbit 360 degrees
self.move_camera(theta=360 * DEGREES, run_time=8)
self.wait()
```
### Camera Zoom
```python theme={null}
from manimvtk import *
class CameraZoom(ThreeDScene):
def construct(self):
cube = Cube()
self.add(cube)
# Start far away
self.set_camera_orientation(phi=60 * DEGREES, distance=10)
self.wait()
# Zoom in
self.move_camera(distance=4, run_time=3)
self.wait()
```
## VTK Export for ParaView
### Export 3D Surface
```python theme={null}
from manimvtk import *
import numpy as np
class ExportSurface(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([u, v, u**2 - v**2]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(30, 30)
)
surface.set_color_by_gradient(BLUE, RED)
self.set_camera_orientation(phi=60 * DEGREES)
self.play(Create(surface))
self.wait()
```
**Render with VTK export:**
```bash theme={null}
manimvtk -pqh examples.py ExportSurface --renderer vtk --vtk-export
```
Open the resulting `.vtp` file in ParaView for further analysis.
## Next Steps
Scientific visualization examples
Complete 3D objects reference
VTK renderer features
Master camera control
# Scientific Visualization Examples
Source: https://manimvtk.mathify.dev/examples/scientific
Examples for CFD, FEA, and scientific data visualization
## Scientific Visualization with ManimVTK
ManimVTK's VTK integration makes it ideal for scientific visualization workflows. Export your animations to ParaView for further analysis.
## CFD-Style Surface
### Pressure Field Visualization
```python theme={null}
from manimvtk import *
import numpy as np
class PressureField(ThreeDScene):
def construct(self):
# Create surface representing a pressure field
surface = Surface(
lambda u, v: np.array([
u,
v,
np.exp(-(u**2 + v**2)) # Gaussian pressure distribution
]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50)
)
# Color by height (simulating pressure)
surface.set_color_by_gradient(BLUE, GREEN, YELLOW, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=-45 * DEGREES)
self.play(Create(surface), run_time=2)
self.wait()
```
**Render and export:**
```bash theme={null}
manimvtk -pqh example.py PressureField --renderer vtk --vtk-export
```
### Velocity Field Arrows
```python theme={null}
from manimvtk import *
import numpy as np
class VelocityField(Scene):
def construct(self):
# Create a grid of velocity vectors
vectors = VGroup()
for x in np.linspace(-3, 3, 7):
for y in np.linspace(-3, 3, 7):
# Compute velocity (circular flow)
velocity = np.array([-y, x, 0]) / 5
magnitude = np.linalg.norm(velocity)
if magnitude > 0:
arrow = Arrow(
start=np.array([x, y, 0]),
end=np.array([x, y, 0]) + velocity,
buff=0,
color=interpolate_color(BLUE, RED, magnitude / 1.5)
)
vectors.add(arrow)
self.play(Create(vectors))
self.wait()
```
## Time-Varying Simulations
### Wave Propagation
```python theme={null}
from manimvtk import *
import numpy as np
class WavePropagation(ThreeDScene):
def construct(self):
def wave_surface(t):
return Surface(
lambda u, v: np.array([
u,
v,
0.5 * np.sin(np.sqrt(u**2 + v**2) - t)
]),
u_range=[-3, 3],
v_range=[-3, 3],
resolution=(40, 40)
)
self.set_camera_orientation(phi=60 * DEGREES)
# Initial surface
surface = wave_surface(0)
surface.set_color_by_gradient(BLUE, GREEN, RED)
self.play(Create(surface))
# Animate wave propagation
for t in np.linspace(0, 2*PI, 60):
new_surface = wave_surface(t)
new_surface.set_color_by_gradient(BLUE, GREEN, RED)
surface.become(new_surface)
self.wait(1/30)
```
**Export as time series:**
```bash theme={null}
manimvtk -pqm example.py WavePropagation --renderer vtk --vtk-time-series
```
## Mesh Visualization
### Surface Mesh Example
```python theme={null}
from manimvtk import *
import numpy as np
class SurfaceMesh(ThreeDScene):
def construct(self):
# Create a mathematical surface
surface = Surface(
lambda u, v: np.array([
u,
v,
np.sin(u) * np.cos(v)
]),
u_range=[-PI, PI],
v_range=[-PI, PI],
resolution=(25, 25)
)
surface.set_color(BLUE_E)
surface.set_opacity(0.8)
self.set_camera_orientation(phi=70 * DEGREES, theta=45 * DEGREES)
self.play(Create(surface))
self.begin_ambient_camera_rotation(rate=0.1)
self.wait(6)
```
## Multi-Field Visualization
### Combined Scalar and Vector Fields
```python theme={null}
from manimvtk import *
import numpy as np
class MultiFieldViz(ThreeDScene):
def construct(self):
# Base surface (scalar field)
surface = Surface(
lambda u, v: np.array([u, v, 0]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(20, 20)
)
surface.set_color(BLUE_E)
# Overlay vector field
arrows = VGroup()
for x in np.linspace(-2, 2, 5):
for y in np.linspace(-2, 2, 5):
arrow = Arrow(
start=[x, y, 0],
end=[x + 0.3, y + 0.2, 0.5],
buff=0,
color=RED
)
arrows.add(arrow)
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
self.play(Create(surface))
self.play(Create(arrows))
self.wait()
```
## ParaView Workflow
After exporting to VTK, open in ParaView:
1. **Load data**: File → Open → Select `.pvd` or `.vtm` file
2. **Apply filters**: Contour, Slice, Clip, etc.
3. **Add color maps**: Color by scalar fields
4. **Add glyphs**: Visualize vector fields
5. **Export animation**: Save as video or image sequence
## Next Steps
Master ParaView visualization
Learn VTK export options
Create temporal animations
VTK API reference
# Welcome to ManimVTK
Source: https://manimvtk.mathify.dev/index
Scientific Visualization meets Mathematical Animation
## What is ManimVTK?
**ManimVTK** is a powerful fork of [Manim Community](https://www.manim.community/) that combines the elegant animation syntax of Manim with VTK (Visualization Toolkit) for scientific visualization and export capabilities.
Create stunning mathematical animations and export them as interactive 3D datasets for use in ParaView, PyVista, and vtk.js.
Get started with ManimVTK in minutes
Explore VTK export and rendering capabilities
Browse examples from 2D to scientific visualization
Comprehensive API documentation
## Key Features
Create elegant animations using Manim's intuitive syntax. Animate geometric shapes, mathematical functions, graphs, and complex transformations with ease.
Export your scenes to VTK formats (.vtp, .vtm, .pvd) for visualization in
ParaView and other scientific tools. Perfect for CFD, FEA, and research
presentations.
Attach scalar fields (pressure, temperature) and vector fields (velocity,
forces) to your exported VTK data for advanced scientific visualization.
Export frame-by-frame VTK files with ParaView Data (.pvd) collection files.
Scrub through animations using ParaView's native time slider.
Generate vtk.js compatible datasets for embedding interactive 3D visualizations in web applications and documentation.
## Quick Example
Here's a simple example that creates an animated surface and exports it to VTK format:
```python theme={null}
from manimvtk import *
class WaveSurface(Scene):
def construct(self):
# Create a parametric surface
surface = Surface(
lambda u, v: np.array([
u,
v,
np.sin(u) * np.cos(v)
]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50),
)
surface.set_color(BLUE)
# Animate the surface
self.play(Create(surface))
self.wait()
```
**Render with VTK export:**
```bash theme={null}
manimvtk -pqh example.py WaveSurface --renderer vtk --vtk-export
```
**Output:**
* `media/videos/example/1080p60/WaveSurface.mp4` - Video animation
* `media/vtk/WaveSurface/WaveSurface_final.vtm` - VTK MultiBlock file
## Use Cases
Create engaging math and physics explanations with beautiful animations
Visualize computational fluid dynamics simulations with scalar and vector
fields
Generate publication-quality animations and interactive 3D datasets
Embed interactive 3D visualizations using vtk.js exports
## Architecture
ManimVTK extends Manim's renderer architecture with VTK support:
```
┌─────────────────────────────────────────────────────────┐
│ Manim Core │
│ (Scene, Mobject, Animation, play, etc.) │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ Renderer Abstraction │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │CairoRenderer│ │OpenGLRenderer│ │ VTKRenderer ✨ │ │
│ └─────────────┘ └─────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ VTK Export / Viewer Layer │
│ • File export (.vtp, .vtm, .pvd) │
│ • Manim → VTK conversion │
│ • Scalar/Vector field support │
└─────────────────────────────────────────────────────────┘
```
## Getting Started
Ready to create your first animation? Follow our quick start guide:
Install ManimVTK and create your first scene
## Community & Support
View source code, report issues, and contribute
Join the broader Manim community
# Installation Guide
Source: https://manimvtk.mathify.dev/installation
Detailed installation instructions for all platforms
## System Requirements
Python 3.9 or higher required
Windows, macOS, Linux (all supported)
\~500MB for basic installation
4GB minimum, 8GB recommended
## Prerequisites by Platform
### Linux
ManimVTK requires system-level dependencies on Linux for text rendering (ManimPango).
```bash theme={null}
!sudo apt update
!sudo apt install libcairo2-dev \
# optional dependencies for full LaTeX support
# texlive texlive-latex-extra texlive-fonts-extra \
# texlive-latex-recommended texlive-science \
tipa libpango1.0-dev
!pip install IPython==8.21.0
```
```bash theme={null}
sudo apt update
sudo apt install libpango1.0-dev pkg-config python3-dev
```
**Tested on:**
* Ubuntu 20.04, 22.04, 24.04
* Debian 11, 12
* Google Colab
`bash sudo dnf install pango-devel pkg-config python3-devel ` **Tested
on:** - Fedora 38, 39, 40
`bash sudo pacman -S pango pkgconf ` **Tested on:** - Arch Linux (rolling
release) - Manjaro
Install the following packages using your distribution's package manager:
* Pango development files (`libpango1.0-dev` or `pango-devel`)
* pkg-config
* Python development headers
**Linux headless environments:** For rendering on servers without a display,
you'll need `xvfb`: `bash sudo apt install xvfb # Debian/Ubuntu sudo dnf
install xorg-x11-server-Xvfb # Fedora `
### macOS
No additional system dependencies required! Python 3.9+ is sufficient.
```bash theme={null}
# Verify Python version
python3 --version
```
### Windows
No additional system dependencies required! Python 3.9+ is sufficient.
**Windows users:** We recommend using Windows Terminal for the best CLI
experience
## Installation Methods
### Method 1: From PyPI (Recommended)
Install the latest stable release from the Python Package Index:
```bash theme={null}
pip install manimvtk[vtk]
```
This includes:
* Core ManimVTK functionality
* VTK rendering and export
* All standard dependencies
`bash pip install manimvtk[scientific] ` Includes everything from basic
installation plus: - PyVista (advanced VTK visualization) - Additional
scientific computing tools
```bash theme={null}
pip install manimvtk[dev]
```
Includes all dependencies plus:
* Testing frameworks (pytest)
* Linting tools (flake8, black)
* Documentation tools
### Method 2: From Source
For development or the latest unreleased features:
```bash theme={null}
# Clone the repository
git clone https://github.com/mathifylabs/manimVTK.git
cd manimVTK
# Install in editable mode with VTK support
pip install -e ".[vtk]"
# Or with all extras for development
pip install -e ".[vtk,dev]"
```
**Editable mode** (`-e`) allows you to modify the source code and see changes
immediately without reinstalling
## Verify Installation
After installation, verify that ManimVTK is working correctly:
```bash theme={null}
# Check version
manimvtk --version
# Should output something like: ManimVTK 0.19.0
```
### Test Rendering
Create a test file `test.py`:
```python theme={null}
from manimvtk import *
class Test(Scene):
def construct(self):
circle = Circle()
self.play(Create(circle))
```
Render it:
```bash theme={null}
manimvtk -pql test.py Test
```
If a video file opens, your installation is working correctly!
### Test VTK Export
Test VTK functionality:
```bash theme={null}
manimvtk -ql test.py Test --vtk-export
```
Check for VTK output:
```bash theme={null}
ls media/vtk/Test/
# Should show: Test_final.vtp
```
## Troubleshooting
This means ManimPango failed to install, usually due to missing system dependencies.
**Solution:**
1. Install system dependencies (see Prerequisites section above)
2. Reinstall: `pip install --force-reinstall manimpango`
VTK was not installed or the installation failed. **Solution:** `bash pip
install vtk # Or reinstall with VTK extras pip install --force-reinstall
manimvtk[vtk] `
This occurs in headless environments (servers without display). **Solution:**
````bash # Install xvfb sudo apt install xvfb # Run with xvfb wrapper xvfb-run theme={null}
-a manimvtk -pql example.py Scene ```
{" "}
You may need to use `--user` flag or a virtual environment. **Solution:**
```bash # Option 1: Install for current user only pip install --user
manimvtk[vtk] # Option 2: Use a virtual environment (recommended) python -m
venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip
install manimvtk[vtk] ```
ManimVTK uses FFmpeg for video encoding.
**Solution:**
```bash
# Ubuntu/Debian
sudo apt install ffmpeg
# macOS
brew install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.html
# Add to PATH
````
## Virtual Environments (Recommended)
Using virtual environments helps avoid dependency conflicts:
```bash theme={null}
# Create virtual environment
python -m venv manimvtk-env
# Activate (Linux/macOS)
source manimvtk-env/bin/activate
# Activate (Windows)
manimvtk-env\Scripts\activate
# Install ManimVTK
pip install manimvtk[vtk]
```
````bash # Create conda environment conda create -n manimvtk python=3.11 conda theme={null}
activate manimvtk # Install ManimVTK pip install manimvtk[vtk] ```
```bash
# Install uv (if not already installed)
pip install uv
# Create environment and install
uv venv
source .venv/bin/activate # or .venv\Scripts\activate on Windows
uv pip install manimvtk[vtk]
````
## Updating ManimVTK
Keep your installation up to date:
```bash theme={null}
# Update to latest version
pip install --upgrade manimvtk[vtk]
# Update from source
cd manimVTK
git pull
pip install -e ".[vtk]"
```
## Optional Dependencies
Additional packages you might want to install:
```bash theme={null}
# For advanced VTK visualization
pip install pyvista
# For Jupyter notebook support
pip install jupyter ipywidgets
# For 3D file export
pip install trimesh
# For advanced plotting
pip install matplotlib
```
## Next Steps
Create your first animation
Learn about VTK capabilities
Browse example scenes
Customize ManimVTK settings
# Quick Start
Source: https://manimvtk.mathify.dev/quickstart
Get started with ManimVTK in minutes
## Installation
### Prerequisites
**Linux Users:** ManimVTK depends on ManimPango, which requires system
dependencies on Linux. Install them first before proceeding.
```bash theme={null}
!sudo apt update
!sudo apt install libcairo2-dev \
# optional dependencies for full LaTeX support
# texlive texlive-latex-extra texlive-fonts-extra \
# texlive-latex-recommended texlive-science \
tipa libpango1.0-dev
!pip install IPython==8.21.0
```
```bash theme={null}
sudo apt install libpango1.0-dev pkg-config python3-dev
```
`bash sudo dnf install pango-devel pkg-config python3-devel `
```bash theme={null}
sudo pacman -S pango pkgconf
```
### Install ManimVTK
Install the latest stable version from PyPI:
```bash theme={null}
# Basic installation with VTK support
pip install manimvtk[vtk]
# Full scientific stack (includes PyVista)
pip install manimvtk[scientific]
```
Clone the repository and install in development mode:
```bash theme={null}
# Clone the repository
git clone https://github.com/mathifylabs/manimVTK.git
cd manimVTK
# Install with VTK support
pip install -e ".[vtk]"
# Or install with full scientific stack
pip install -e ".[scientific]"
```
**Verify Installation:** Run `manimvtk --version` to confirm installation
## Your First Animation
Let's create a simple animation to verify everything is working.
### Step 1: Create a Scene File
Create a new file called `example.py`:
```python theme={null}
from manimvtk import *
class CircleExample(Scene):
def construct(self):
# Create a circle
circle = Circle(radius=1, color=BLUE)
# Add it to the scene
self.play(Create(circle))
self.wait()
```
### Step 2: Render the Animation
Render your scene with the default Cairo renderer:
```bash theme={null}
manimvtk -pql example.py CircleExample
```
**Command breakdown:**
* `-p`: Preview the video after rendering
* `-q`: Quality (l=low, m=medium, h=high)
* `-l`: Low quality for faster rendering
The rendered video will be saved in
`media/videos/example/480p15/CircleExample.mp4`
### Step 3: Add VTK Export
Now let's export the scene to VTK format:
```bash theme={null}
manimvtk -pql example.py CircleExample --vtk-export
```
This creates:
* `media/videos/example/480p15/CircleExample.mp4` - Video file
* `media/vtk/CircleExample/CircleExample_final.vtp` - VTK file
**Success!** You've created your first ManimVTK animation with VTK export
## Using the VTK Renderer
Switch to the VTK renderer for high-quality 3D rendering:
```python theme={null}
from manimvtk import *
class SphereExample(ThreeDScene):
def construct(self):
# Create a 3D sphere
sphere = Sphere(radius=1.5, resolution=(20, 20))
sphere.set_color(BLUE)
# Rotate the camera
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
# Animate
self.play(Create(sphere))
self.play(Rotate(sphere, angle=PI, axis=UP))
self.wait()
```
Render with the VTK renderer:
```bash theme={null}
manimvtk -pql example.py SphereExample --renderer vtk --vtk-export
```
## Time Series Export for ParaView
Export frame-by-frame VTK files for animation scrubbing in ParaView:
```python theme={null}
from manimvtk import *
class AnimatedCircle(Scene):
def construct(self):
circle = Circle(radius=1, color=BLUE)
self.add(circle)
# Animate the circle growing
self.play(circle.animate.scale(2))
self.wait()
```
Render with time series export:
```bash theme={null}
manimvtk -pql example.py AnimatedCircle --vtk-time-series
```
**Output structure:**
```
media/vtk/AnimatedCircle/
├── AnimatedCircle.pvd # ParaView collection file
├── AnimatedCircle_00000.vtp # Frame 0
├── AnimatedCircle_00001.vtp # Frame 1
├── ...
└── AnimatedCircle_viewer.html # HTML viewer template
```
Open the `.pvd` file in ParaView to scrub through the animation using the time
slider
## Common CLI Options
| Option | Description |
| ------------------------------- | ------------------------------------ |
| `-p` | Preview video after rendering |
| `-q{l,m,h}` | Quality: low, medium, or high |
| `-s` | Save last frame as PNG |
| `-a` | Render all scenes in file |
| `--renderer {cairo,opengl,vtk}` | Choose renderer |
| `--vtk-export` | Export final scene to VTK |
| `--vtk-time-series` | Export all frames as VTK time series |
Complete reference of command-line options
## Next Steps
Learn about VTK rendering and export
Understand scenes, mobjects, and animations
Explore example animations
Browse the complete API
## Getting Help
Report issues on our [GitHub repository](https://github.com/mathifylabs/manimVTK/issues)
Check the [Manim Community](https://www.manim.community/) resources and
Discord
See our [Contributing Guide](https://github.com/mathifylabs/manimVTK/blob/main/CONTRIBUTING.md)
# VTK Export
Source: https://manimvtk.mathify.dev/vtk/export
Export Manim scenes to VTK file formats
## Introduction
ManimVTK allows you to export your animations to VTK (Visualization Toolkit) file formats, enabling visualization in ParaView, PyVista, and other scientific tools.
**VTK export works with any renderer** - you can use Cairo, OpenGL, or VTK renderer and still export to VTK formats.
## Export Methods
### Static Export (Final Frame)
Export the final state of your scene:
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-export
```
**Output formats:**
* Single mobject → `.vtp` (VTK PolyData)
* Multiple mobjects → `.vtm` (VTK MultiBlock Dataset)
### Time Series Export (All Frames)
Export every frame as a VTK file:
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-time-series
```
**Output:**
* `.pvd` - ParaView Data collection file
* `.vtp` files - One per frame
* `viewer.html` - Basic HTML viewer template
Detailed guide on time series export
## File Formats
### VTK PolyData (.vtp)
Used for single objects with points, lines, and polygons.
**When created:**
* Scene contains a single mobject
* Explicitly exporting one mobject
**Structure:**
```xml theme={null}
...
...
```
**Example output:**
```
media/vtk/MyScene/
└── MyScene_final.vtp
```
### VTK MultiBlock (.vtm)
Used for scenes with multiple objects.
**When created:**
* Scene contains multiple mobjects
* Complex hierarchical structures
**Structure:**
```xml theme={null}
```
**Example output:**
```
media/vtk/MyScene/
├── MyScene_final.vtm
├── Circle_0.vtp
└── Square_1.vtp
```
## Basic Examples
### Export a Simple Shape
```python theme={null}
from manimvtk import *
class CircleExport(Scene):
def construct(self):
circle = Circle(radius=2, color=BLUE, fill_opacity=0.5)
self.play(Create(circle))
self.wait()
```
```bash theme={null}
manimvtk -pql scene.py CircleExport --vtk-export
```
**Output:** `media/vtk/CircleExport/CircleExport_final.vtp`
### Export Multiple Objects
```python theme={null}
from manimvtk import *
class MultipleShapes(Scene):
def construct(self):
circle = Circle(radius=1, color=BLUE).shift(LEFT * 2)
square = Square(side_length=1.5, color=RED)
triangle = Triangle(color=GREEN).shift(RIGHT * 2)
self.play(
Create(circle),
Create(square),
Create(triangle)
)
self.wait()
```
```bash theme={null}
manimvtk -pql scene.py MultipleShapes --vtk-export
```
**Output:**
```
media/vtk/MultipleShapes/
├── MultipleShapes_final.vtm
├── Circle_0.vtp
├── Square_1.vtp
└── Triangle_2.vtp
```
### Export 3D Surfaces
```python theme={null}
from manimvtk import *
import numpy as np
class SurfaceExport(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([u, v, np.sin(u) * np.cos(v)]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50),
)
surface.set_color_by_gradient(BLUE, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
self.play(Create(surface))
self.wait()
```
```bash theme={null}
manimvtk -pqh scene.py SurfaceExport --renderer vtk --vtk-export
```
## Export Location
By default, VTK files are saved to:
```
media/vtk//
```
The location follows ManimVTK's standard media directory structure:
```
media/
├── videos/
│ └── scene.py/
│ └── 1080p60/
│ └── MyScene.mp4
└── vtk/
└── MyScene/
├── MyScene_final.vtp
└── MyScene_final.vtm
```
## Programmatic Export
You can also export VTK files programmatically:
```python theme={null}
from manimvtk import *
from manimvtk.vtk import VTKExporter
class ProgrammaticExport(Scene):
def construct(self):
circle = Circle(radius=2, color=BLUE)
self.add(circle)
# Create exporter
exporter = VTKExporter(
output_dir="custom_output",
scene_name="MyCircle"
)
# Export single mobject
exporter.export_mobject(circle, filename="circle.vtp")
# Export scene (all mobjects)
exporter.export_scene_static(self.mobjects)
```
## Data Preservation
### Colors
Mobject colors are preserved in VTK export:
```python theme={null}
circle = Circle(radius=1)
circle.set_color(BLUE) # Exported as RGB values
circle.set_opacity(0.5) # Exported as opacity
```
In VTK, colors are stored as `PointData` arrays named "Colors" with RGBA values.
### Geometry
Different mobject types are converted appropriately:
| Mobject | VTK Representation |
| -------------- | ----------------------- |
| Filled shapes | Polygons (triangulated) |
| Stroked shapes | PolyLines |
| Surfaces | Polygonal mesh |
| Text/Tex | Filled paths (polygons) |
### Transformations
All transformations (position, rotation, scale) are applied before export:
```python theme={null}
circle = Circle()
circle.shift(RIGHT * 2) # Position
circle.rotate(45 * DEGREES) # Rotation
circle.scale(1.5) # Scale
# All transformations are baked into exported geometry
```
## Advanced Features
### Scalar Fields
Attach scalar data to exported geometry:
```python theme={null}
from manimvtk import *
from manimvtk.vtk import add_scalar_field
import numpy as np
class ScalarFieldExport(Scene):
def construct(self):
# Create surface
surface = Surface(
lambda u, v: np.array([u, v, u**2 - v**2]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(30, 30)
)
self.add(surface)
# Export and add scalar field in post-processing
```
See [Scalar Fields](/api-reference/vtk/scalar-fields) for details.
### Vector Fields
Attach vector data for flow visualization:
```python theme={null}
from manimvtk.vtk import add_vector_field
# Add velocity vectors to exported polydata
add_vector_field(polydata, "velocity", velocity_array)
```
See [Vector Fields](/api-reference/vtk/vector-fields) for details.
## Viewing Exported Files
### ParaView
1. Open ParaView
2. File → Open
3. Select `.vtp`, `.vtm`, or `.pvd` file
4. Click "Apply" in the Properties panel
Detailed ParaView visualization guide
### PyVista (Python)
```python theme={null}
import pyvista as pv
# Load exported file
mesh = pv.read('media/vtk/MyScene/MyScene_final.vtp')
# Visualize
mesh.plot(
color='lightblue',
show_edges=True,
window_size=[800, 600]
)
# Or interactive
mesh.plot(jupyter_backend='trame')
```
### vtk.js (Web)
```javascript theme={null}
import vtkXMLPolyDataReader from '@kitware/vtk.js/IO/XML/XMLPolyDataReader';
const reader = vtkXMLPolyDataReader.newInstance();
reader.setUrl('MyScene_final.vtp');
reader.loadData().then(() => {
const polydata = reader.getOutputData();
// Render with vtk.js
});
```
## Best Practices
VTK XML formats are human-readable but can be large. Considerations:
* Use compression in ParaView: File → Save Data → check "Compressed"
* Lower resolution for testing: `resolution=(20, 20)` instead of `(50, 50)`
* Use binary format for production (requires VTK binary writer)
Keep exports organized:
```
project/
├── scenes/
│ ├── scene1.py
│ └── scene2.py
└── media/
└── vtk/
├── Scene1/
└── Scene2/
```
**Use static export when:**
* You only need the final result
* Creating static visualizations
* File size is a concern
**Use time series when:**
* Analyzing animation in ParaView
* Need frame-by-frame data
* Creating interactive temporal visualizations
Export adds minimal overhead:
* Cairo/OpenGL rendering time: \~90%
* VTK export time: \~10%
Time series export is slower due to per-frame I/O.
## Troubleshooting
**Possible causes:**
* Forgot `--vtk-export` flag
* Scene has no mobjects
* Permission issues in output directory
**Check:**
```bash theme={null}
ls -la media/vtk/
```
**Possible causes:**
* VTK file corrupted
* ParaView version too old
**Solution:**
* Re-export the file
* Update ParaView to 5.9+
* Check file with text editor (XML should be valid)
**Cause:** Color data not exported correctly
**Check:**
* Are colors set before rendering?
* Does the mobject have a stroke or fill?
```python theme={null}
# Ensure colors are set
circle.set_color(BLUE)
circle.set_fill(BLUE, opacity=0.5)
```
## Next Steps
Learn about frame-by-frame export
Visualize exports in ParaView
Add scientific data fields
See scientific visualization examples
# VTK Features Overview
Source: https://manimvtk.mathify.dev/vtk/overview
Understanding ManimVTK's VTK integration and capabilities
## What is VTK Integration?
ManimVTK extends the original Manim animation engine with **VTK (Visualization Toolkit)** integration, enabling you to:
1. **Render with VTK**: Use VTK's rendering engine for high-quality 3D visualization
2. **Export to VTK formats**: Save scenes as `.vtp`, `.vtm`, and `.pvd` files
3. **Create time series**: Export frame-by-frame animations for ParaView
4. **Add scientific data**: Attach scalar and vector fields to exported geometry
High-quality 3D rendering using VTK
Export scenes to VTK file formats
Frame-by-frame export for ParaView
Visualize exports in ParaView
## Key Capabilities
### 1. VTK Rendering
Render scenes using VTK's powerful rendering engine instead of Cairo or OpenGL:
```bash theme={null}
manimvtk -pqh scene.py MyScene --renderer vtk
```
**Benefits:**
* High-quality 3D rendering with proper lighting and shading
* Better performance for complex 3D geometry
* Native support for scientific visualization
### 2. VTK File Export
Export your scenes to industry-standard VTK formats:
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-export
```
**Output:**
* Single mobject → `.vtp` (VTK PolyData)
* Multiple mobjects → `.vtm` (VTK MultiBlock)
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-time-series
```
**Output:**
* `.pvd` collection file
* Frame-by-frame `.vtp` files
* HTML viewer template
### 3. Scientific Data Fields
Attach scalar and vector fields to VTK exports for scientific visualization:
```python theme={null}
from manimvtk.vtk import add_scalar_field, add_vector_field
# After creating VTK polydata
add_scalar_field(polydata, "pressure", pressure_values)
add_vector_field(polydata, "velocity", velocity_vectors)
```
**Use cases:**
* CFD (Computational Fluid Dynamics) visualization
* FEA (Finite Element Analysis) results
* Temperature distributions
* Velocity fields and streamlines
## Supported Mobject Types
| Mobject Type | VTK Export | Notes |
| ---------------------- | ---------- | --------------------------------- |
| **2D Shapes** | ✅ | Circle, Square, Polygon, etc. |
| `VMobject` | ✅ | Converted to PolyData with colors |
| `Surface` | ✅ | Full mesh with UV coordinates |
| `ParametricSurface` | ✅ | Parametric surfaces |
| **3D Primitives** | ✅ | Sphere, Cube, Cone, etc. |
| `VGroup` | ✅ | Exported as VTK MultiBlock |
| `Text` / `Tex` | ✅ | Exported as filled paths |
| `Arrow` / `Vector` | ✅ | Stroke-based or filled |
| `NumberPlane` / `Axes` | ✅ | Exported as line geometry |
**Nearly all Manim mobjects** are supported for VTK export!
## File Format Reference
### VTK PolyData (.vtp)
Single object with points, lines, and polygons.
**Best for:**
* Single surfaces or meshes
* Simple geometry
* Quick visualization
**Structure:**
```xml theme={null}
...
...
...
```
### VTK MultiBlock (.vtm)
Collection of multiple datasets.
**Best for:**
* Scenes with multiple objects
* Hierarchical data
* Complex assemblies
**Structure:**
```xml theme={null}
```
### ParaView Data (.pvd)
Time series collection file.
**Best for:**
* Animations
* Temporal data
* Time-varying simulations
**Structure:**
```xml theme={null}
...
```
## Workflow Examples
### Basic Workflow
```python theme={null}
from manimvtk import *
class MyScene(Scene):
def construct(self):
circle = Circle(radius=2, color=BLUE)
self.play(Create(circle))
self.wait()
```
```bash theme={null}
# Render and export
manimvtk -pqh scene.py MyScene --renderer vtk --vtk-export
```
**Output:**
1. `MyScene.mp4` - Video animation
2. `MyScene_final.vtp` - VTK export of final frame
### Scientific Visualization Workflow
```python theme={null}
from manimvtk import *
import numpy as np
class CFDSurface(Scene):
def construct(self):
# Create surface mesh
surface = Surface(
lambda u, v: np.array([u, v, np.sin(u) * np.cos(v)]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50),
)
# Color gradient for visualization
surface.set_color_by_gradient(BLUE, RED)
self.play(Create(surface))
self.wait()
```
```bash theme={null}
# Export with time series
manimvtk -pqh scene.py CFDSurface --vtk-time-series
```
**Workflow:**
1. Create animation in ManimVTK
2. Export time series
3. Open `.pvd` in ParaView
4. Apply filters (contours, glyphs, etc.)
5. Add scalar/vector field visualization
### Interactive Web Workflow
```bash theme={null}
# Export for web viewing
manimvtk -pqh scene.py MyScene --vtk-export
# The .vtp file can be loaded with vtk.js
```
Embed in web applications using vtk.js for interactive 3D visualization.
## Performance Considerations
* **Faster** for complex 3D scenes with many polygons
* **Slower** initial startup (VTK initialization)
* Best for: High-quality final renders
* **Text format (.vtp)**: Human-readable but larger
* **Binary format**: Smaller but not human-readable
* **Compression**: Use ParaView to compress exported files
* High-resolution surfaces consume more memory
* Time series exports can be large (one file per frame)
* Recommended: Export at lower quality, then upscale if needed
## Compatibility
### ParaView Versions
* ✅ ParaView 5.9+
* ✅ ParaView 5.10+
* ✅ ParaView 5.11+
### VTK Versions
* ✅ VTK 9.0+
* ✅ VTK 9.1+
* ✅ VTK 9.2+
### PyVista Integration
```python theme={null}
import pyvista as pv
# Load exported VTK file
mesh = pv.read('media/vtk/MyScene/MyScene_final.vtp')
# Visualize in PyVista
mesh.plot()
```
## Next Steps
Learn about VTK rendering options
Master VTK file export
Create animations for ParaView
Visualize in ParaView
# ParaView Integration
Source: https://manimvtk.mathify.dev/vtk/paraview
Visualize ManimVTK exports in ParaView
## Introduction
[ParaView](https://www.paraview.org/) is a powerful open-source scientific visualization application. ManimVTK's VTK export is specifically designed to integrate seamlessly with ParaView.
Get the latest ParaView version (5.9+ recommended)
## Quick Start
### 1. Export from ManimVTK
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-export
```
### 2. Open in ParaView
1. Launch ParaView
2. **File → Open**
3. Navigate to `media/vtk/MyScene/`
4. Select `MyScene_final.vtp` or `MyScene_final.vtm`
5. Click **"Open"**
6. Click **"Apply"** in Properties panel
Your ManimVTK scene is now loaded!
## Basic Visualization
### Surface Representation
Change how your objects appear:
**In Properties panel:**
* **Representation**: Surface, Wireframe, Points, Surface With Edges
* **Coloring**: Solid Color, by array data
* **Opacity**: 0.0 (transparent) to 1.0 (opaque)
**Surface With Edges** is great for seeing the mesh structure
### Color by Data
If your export includes color data:
1. In Properties panel, find **"Coloring"**
2. Select **"Colors"** from dropdown
3. Choose color map (Cool to Warm, Viridis, etc.)
4. Adjust range in **Color Map Editor**
### Camera Controls
* **Left Click + Drag**: Rotate
* **Middle Click + Drag**: Pan
* **Scroll Wheel**: Zoom
* **Right Click + Drag**: Zoom
**Reset camera:**
* Click camera icon in toolbar
* Or **View → Camera → Reset**
## Time Series Animation
For exports with `--vtk-time-series`:
### Loading Time Series
1. File → Open
2. Select the **`.pvd` file** (not individual frames)
3. Click "Apply"
### Playback Controls
**Time toolbar** appears at top:
* ⏮️ First frame
* ⏪ Previous frame
* ▶️ Play
* ⏸️ Pause
* ⏩ Next frame
* ⏭️ Last frame
**Time slider:**
* Drag to scrub through frames
* Shows current time value
### Animation View
For advanced timeline control:
1. **View → Animation View**
2. Set duration and frame rate
3. Add keyframes for camera movement
4. Export animation as video
## Filters and Analysis
### Common Filters
Cut through your geometry to see inside:
1. Select your object
2. **Filters → Common → Clip**
3. Adjust plane position and normal
4. Click "Apply"
Create a 2D slice through 3D data:
1. **Filters → Common → Slice**
2. Choose slice orientation
3. Position the slice
4. Apply
Create isosurfaces from scalar data:
1. **Filters → Common → Contour**
2. Select scalar array
3. Set isovalues
4. Apply
Compute new fields from existing data:
1. **Filters → Common → Calculator**
2. Enter formula (e.g., `sqrt(X^2 + Y^2 + Z^2)`)
3. Name result array
4. Apply
### Measuring
**Distance Tool:**
1. **View → Find Data → Select Points On**
2. Click two points
3. View distance in Information panel
**Volume/Area:**
1. Select object
2. **Filters → Alphabetical → Integrate Variables**
3. View in Spreadsheet View
## Scientific Visualization
### Scalar Field Visualization
If you've attached scalar data (temperature, pressure):
```python theme={null}
# In ManimVTK (requires post-processing)
from manimvtk.vtk import add_scalar_field
# add_scalar_field(polydata, "temperature", temp_array)
```
**In ParaView:**
1. Color by scalar field
2. Add color bar: **View → Color Map Editor → Show Color Legend**
3. Apply **Contour** filter for isosurfaces
4. Use **Threshold** to filter by value range
### Vector Field Visualization
For velocity or force fields:
```python theme={null}
# In ManimVTK (post-processing)
from manimvtk.vtk import add_vector_field
# add_vector_field(polydata, "velocity", velocity_array)
```
**In ParaView:**
**Glyphs (arrows):**
1. **Filters → Common → Glyph**
2. Set Glyph Type: Arrow
3. Orient by vector field
4. Scale by magnitude
5. Apply
**Streamlines:**
1. **Filters → Common → Stream Tracer**
2. Set Vectors: your velocity field
3. Choose seed type (Line, Point, etc.)
4. Apply
### CFD Workflow Example
1. **Load data**: Open your `.pvd` time series
2. **Slice**: Create cross-section
3. **Contour**: Show pressure isosurfaces
4. **Glyph**: Display velocity vectors
5. **Color**: By temperature or pressure
6. **Animate**: Play through time steps
## Rendering and Export
### Screenshots
**High-quality screenshots:**
1. Adjust view and size window
2. **File → Save Screenshot**
3. Set resolution (e.g., 4096x2160)
4. Choose format (PNG recommended)
5. Save
Use **transparent background** for compositing: Check "Transparent Background" in save dialog
### Exporting Animation
**Save as video:**
1. Set up time series and view
2. **File → Save Animation**
3. Choose format:
* **AVI**: Uncompressed, large
* **MP4**: Compressed, smaller (requires ffmpeg)
* **Image sequence**: PNG frames
4. Set frame rate and resolution
5. Save
**Quality settings:**
* **Stereo**: For 3D viewing
* **Frame Rate**: Match source or higher
* **Compression**: Balance quality/size
### Python Export
Export current view to Python script:
1. **Tools → Start Trace**
2. Perform visualization steps
3. **Tools → Stop Trace**
4. Save Python script
5. Run with `pvpython script.py`
## Advanced Features
### Python Scripting
Automate ParaView with Python:
```python theme={null}
# Load in pvpython or Programmable Filter
from paraview.simple import *
# Load VTK file
reader = XMLPolyDataReader(FileName='MyScene_final.vtp')
Show(reader)
# Apply filter
clip = Clip(Input=reader)
clip.ClipType = 'Plane'
Show(clip)
# Render
Render()
```
### Batch Processing
Process multiple files:
```python theme={null}
import glob
from paraview.simple import *
for file in glob.glob('media/vtk/*/*.vtp'):
reader = XMLPolyDataReader(FileName=file)
# Process...
SaveData(f'output/{file}.png')
```
### Custom Filters
Create reusable visualization pipelines:
1. Set up filter pipeline
2. **Tools → Create Custom Filter**
3. Name and save
4. Access from **Filters → Custom**
## Tips and Tricks
* `R`: Reset camera
* `Space`: Play/pause animation
* `Ctrl + O`: Open file
* `Ctrl + S`: Save screenshot
* `Ctrl + E`: Save animation
* `3`: Toggle surface with edges
* Click eye icon to toggle object visibility
* Use Pipeline Browser to manage multiple objects
* Group objects: Select multiple → Right click → Group
Best color maps for different data:
* **Sequential**: Viridis, Plasma, Inferno
* **Diverging**: Cool to Warm, Blue to Red
* **Rainbow**: Use sparingly (can be misleading)
For large datasets:
* Use **LOD (Level of Detail)**: Edit → Settings → Render View
* Reduce geometry: **Filters → Decimate**
* Hide objects not in view
* Use client-server mode for very large data
## Example Workflows
### Basic Shape Inspection
```python theme={null}
# ManimVTK scene
from manimvtk import *
class ShapeInspection(Scene):
def construct(self):
shapes = VGroup(
Circle(radius=1, color=BLUE),
Square(side_length=1.5, color=RED),
Triangle(color=GREEN)
).arrange(RIGHT, buff=1)
self.play(Create(shapes))
self.wait()
```
```bash theme={null}
manimvtk -pql scene.py ShapeInspection --vtk-export
```
**In ParaView:**
1. Open `ShapeInspection_final.vtm`
2. Apply
3. In Pipeline Browser, expand to see each shape
4. Toggle visibility to examine individually
5. Use "Surface With Edges" to see mesh
### 3D Surface Analysis
```python theme={null}
# ManimVTK scene
from manimvtk import *
import numpy as np
class SurfaceAnalysis(ThreeDScene):
def construct(self):
surface = Surface(
lambda u, v: np.array([u, v, np.sin(u) * np.cos(v)]),
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(50, 50)
)
surface.set_color_by_gradient(BLUE, RED)
self.set_camera_orientation(phi=60 * DEGREES)
self.add(surface)
```
```bash theme={null}
manimvtk -pqh scene.py SurfaceAnalysis --vtk-export
```
**In ParaView:**
1. Open surface
2. Apply **Calculator** filter: `coordsZ` to create height field
3. Color by height
4. Apply **Contour** to show level curves
5. Adjust camera for best view
## Troubleshooting
**Cause:** No lighting or normals
**Solution:**
* Apply **Generate Surface Normals** filter
* Or adjust lighting in Properties
**Cause:** Wrong file opened
**Solution:**
* Must open `.pvd` file, not individual `.vtp`
* Close all and reopen `.pvd`
**Cause:** Color data not in export
**Solution:**
* Check if colors set in ManimVTK
* Look for "Colors" array in Information panel
* If missing, set in Coloring dropdown to "Solid Color"
**Cause:** Complex geometry or large data
**Solution:**
* Use lower quality setting in ParaView
* Apply Decimate filter
* Enable LOD threshold
* Close unused pipeline objects
## Resources
Official ParaView documentation
Step-by-step tutorials
Community forum for help
VTK format specification
## Next Steps
Master VTK file export from ManimVTK
Create animated time series
See scientific visualization examples
Add scientific data to exports
# VTK Renderer
Source: https://manimvtk.mathify.dev/vtk/renderer
Using the VTK renderer for high-quality 3D visualization
## Overview
The VTK renderer is one of three rendering backends available in ManimVTK (alongside Cairo and OpenGL). It leverages the VTK (Visualization Toolkit) library for high-quality 3D rendering with advanced shading and lighting.
The VTK renderer is particularly powerful for **3D scenes** and **scientific visualization**, providing superior quality compared to the standard Cairo renderer.
## Basic Usage
### Selecting the VTK Renderer
Use the `--renderer vtk` flag when rendering:
```bash theme={null}
manimvtk -pqh scene.py MyScene --renderer vtk
```
### In Code
You can also specify the renderer in your scene configuration:
```python theme={null}
from manimvtk import *
class MyScene(ThreeDScene):
def construct(self):
# Your 3D content here
sphere = Sphere()
self.add(sphere)
```
`ThreeDScene` works with all renderers, but VTK provides the best quality for 3D content
## Renderer Comparison
| Feature | Cairo | OpenGL | VTK |
| ------------------ | ----------- | ----------- | --------- |
| **2D Quality** | ⭐⭐⭐ | ⭐⭐ | ⭐⭐ |
| **3D Quality** | ⭐ | ⭐⭐ | ⭐⭐⭐ |
| **Performance** | ⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
| **Export Support** | Images only | Images only | VTK files |
| **Lighting** | Basic | Good | Excellent |
| **Shading** | None | Basic | Advanced |
| **Anti-aliasing** | Good | Good | Excellent |
## VTK Renderer Features
### Advanced Lighting
VTK supports sophisticated lighting models:
```python theme={null}
from manimvtk import *
class LightingExample(ThreeDScene):
def construct(self):
# Create a sphere
sphere = Sphere(radius=1.5, resolution=(40, 40))
sphere.set_color(BLUE)
# Adjust camera and lighting
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
self.add(sphere)
self.wait()
```
When rendered with VTK (`--renderer vtk`), you'll see realistic shading and highlights.
### Surface Shading
VTK provides multiple shading options:
* **Flat shading**: Each polygon rendered with uniform color
* **Gouraud shading**: Smooth interpolation across polygons
* **Phong shading**: High-quality specular highlights
VTK automatically selects the appropriate shading based on your geometry and lighting
### Transparency and Opacity
VTK handles transparency correctly with depth sorting:
```python theme={null}
from manimvtk import *
class TransparencyExample(ThreeDScene):
def construct(self):
# Create overlapping transparent spheres
sphere1 = Sphere(radius=1).shift(LEFT)
sphere1.set_color(BLUE)
sphere1.set_opacity(0.5)
sphere2 = Sphere(radius=1).shift(RIGHT)
sphere2.set_color(RED)
sphere2.set_opacity(0.5)
self.set_camera_orientation(phi=60 * DEGREES)
self.add(sphere1, sphere2)
self.wait()
```
## Configuration
### Camera Settings
Configure the camera for optimal VTK rendering:
```python theme={null}
from manimvtk import *
class CameraExample(ThreeDScene):
def construct(self):
# Set camera position
self.set_camera_orientation(
phi=75 * DEGREES, # Vertical rotation
theta=30 * DEGREES, # Horizontal rotation
distance=8 # Distance from origin
)
# Add your objects
axes = ThreeDAxes()
surface = Surface(
lambda u, v: np.array([u, v, u**2 - v**2]),
u_range=[-2, 2],
v_range=[-2, 2]
)
self.add(axes, surface)
self.wait()
```
### Resolution Settings
Control render quality in config:
```python theme={null}
# In your scene file
config.pixel_height = 1080
config.pixel_width = 1920
config.frame_rate = 60
```
Or via CLI:
```bash theme={null}
# High quality 1080p @ 60fps
manimvtk -qh scene.py MyScene --renderer vtk
# 4K quality
manimvtk --resolution 3840,2160 scene.py MyScene --renderer vtk
```
## Best Practices
The VTK renderer excels at 3D visualization. For pure 2D animations, Cairo may be faster and sufficient.
**VTK recommended for:**
* Surfaces and parametric surfaces
* 3D primitives (spheres, cubes, etc.)
* Scientific 3D data
* Complex lighting scenarios
Start with lower resolution for testing, then render at full quality:
```bash theme={null}
# Test render (fast)
manimvtk -ql scene.py MyScene --renderer vtk
# Final render (slow but high quality)
manimvtk -qh scene.py MyScene --renderer vtk
```
VTK rendering may display colors differently than Cairo due to lighting. Test your colors with VTK early in development.
```python theme={null}
# Set colors that work well with lighting
surface.set_color(BLUE)
surface.set_opacity(0.8) # Slight transparency often looks better
```
Smooth camera movements work beautifully with VTK:
```python theme={null}
self.begin_ambient_camera_rotation(rate=0.2)
self.wait(5)
self.stop_ambient_camera_rotation()
```
## Combining with Export
The VTK renderer works seamlessly with VTK export:
```bash theme={null}
# Render with VTK and export
manimvtk -pqh scene.py MyScene --renderer vtk --vtk-export
```
This produces:
1. High-quality video rendered with VTK
2. VTK files (.vtp or .vtm) for further analysis
## Troubleshooting
**Cause:** VTK initialization failed or display not available
**Solution:**
```bash theme={null}
# On headless servers, use xvfb
xvfb-run -a manimvtk -pqh scene.py MyScene --renderer vtk
```
**Cause:** High polygon count or complex geometry
**Solution:**
* Reduce surface resolution
* Lower video quality for testing
* Use simpler geometry during development
```python theme={null}
# Lower resolution surface
surface = Surface(
func,
resolution=(20, 20) # Instead of (50, 50)
)
```
**Cause:** VTK applies lighting and shading
**Solution:**
* Adjust colors to account for lighting
* Increase ambient light if colors are too dark
* Test with different camera angles
**Cause:** VTK not installed
**Solution:**
```bash theme={null}
pip install vtk
# Or reinstall with VTK extras
pip install manimvtk[vtk]
```
## Advanced Examples
### Parametric Surface with Lighting
```python theme={null}
from manimvtk import *
import numpy as np
class ParametricSurfaceVTK(ThreeDScene):
def construct(self):
# Create a complex parametric surface
surface = Surface(
lambda u, v: np.array([
np.cos(u) * (2 + np.cos(v)),
np.sin(u) * (2 + np.cos(v)),
np.sin(v)
]),
u_range=[0, TAU],
v_range=[0, TAU],
resolution=(50, 50),
)
# Gradient coloring
surface.set_color_by_gradient(BLUE, GREEN, YELLOW, RED)
# Camera setup
self.set_camera_orientation(phi=60 * DEGREES, theta=-45 * DEGREES)
# Animation
self.play(Create(surface), run_time=2)
self.begin_ambient_camera_rotation(rate=0.1)
self.wait(5)
self.stop_ambient_camera_rotation()
```
Render:
```bash theme={null}
manimvtk -pqh scene.py ParametricSurfaceVTK --renderer vtk --vtk-export
```
### Multiple 3D Objects
```python theme={null}
from manimvtk import *
class Multiple3DObjects(ThreeDScene):
def construct(self):
# Create axes
axes = ThreeDAxes()
# Create objects
sphere = Sphere(radius=0.5).shift(UP + LEFT)
sphere.set_color(BLUE)
cube = Cube(side_length=1).shift(UP + RIGHT)
cube.set_color(RED)
cone = Cone(base_radius=0.5, height=1).shift(DOWN)
cone.set_color(GREEN)
# Camera
self.set_camera_orientation(phi=70 * DEGREES, theta=30 * DEGREES)
# Animate
self.play(Create(axes))
self.play(
FadeIn(sphere),
FadeIn(cube),
FadeIn(cone)
)
# Rotate all objects
self.play(
Rotate(sphere, angle=PI, axis=UP),
Rotate(cube, angle=PI, axis=UP),
Rotate(cone, angle=PI, axis=UP),
run_time=3
)
self.wait()
```
## Next Steps
Learn how to export VTK files
Master 3D scene creation
Explore 3D surface objects
View 3D rendering examples
# Time Series Export
Source: https://manimvtk.mathify.dev/vtk/time-series
Export frame-by-frame VTK files for animation in ParaView
## Overview
Time series export creates a VTK file for **every frame** of your animation, allowing you to scrub through the animation in ParaView using its time slider.
**Perfect for:** Analyzing animations frame-by-frame, creating temporal visualizations, and debugging complex motion
## Basic Usage
Use the `--vtk-time-series` flag:
```bash theme={null}
manimvtk -pqh scene.py MyScene --vtk-time-series
```
**Output structure:**
```
media/vtk/MyScene/
├── MyScene.pvd # ParaView Data collection file
├── MyScene_00000.vtp # Frame 0
├── MyScene_00001.vtp # Frame 1
├── MyScene_00002.vtp # Frame 2
├── ...
└── MyScene_viewer.html # HTML viewer template (optional)
```
## Example Scene
```python theme={null}
from manimvtk import *
class AnimatedCircle(Scene):
def construct(self):
circle = Circle(radius=1, color=BLUE)
self.add(circle)
# Animate the circle
self.play(circle.animate.scale(2))
self.play(circle.animate.shift(RIGHT * 3))
self.play(circle.animate.set_color(RED))
self.wait()
```
Render with time series:
```bash theme={null}
manimvtk -pql scene.py AnimatedCircle --vtk-time-series
```
## ParaView Data (.pvd) File
The `.pvd` file is an XML collection file that references all frame files:
```xml theme={null}
...
```
**Time step calculation:**
* Based on your frame rate: `timestep = frame_number / frame_rate`
* Default frame rate: 30 fps (configurable via `-r` flag)
## Opening in ParaView
1. **Launch ParaView**
2. **File → Open**
3. **Select the `.pvd` file** (not individual `.vtp` files)
4. **Click "Apply"** in Properties panel
You'll now see:
* **Time toolbar** at the top
* **Time slider** to scrub through frames
* **Play button** to animate
Use the time slider or VCR controls to move through your animation frame by frame
## Advanced Examples
### Growing Surface
```python theme={null}
from manimvtk import *
import numpy as np
class GrowingSurface(ThreeDScene):
def construct(self):
# Create a surface that changes over time
def surface_func(u, v):
return np.array([u, v, np.sin(u) * np.cos(v)])
surface = Surface(
surface_func,
u_range=[-2, 2],
v_range=[-2, 2],
resolution=(30, 30)
)
surface.set_color_by_gradient(BLUE, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=30 * DEGREES)
# Animate
self.play(Create(surface), run_time=2)
self.play(surface.animate.scale(1.5), run_time=2)
self.wait()
```
```bash theme={null}
manimvtk -pqh scene.py GrowingSurface --vtk-time-series
```
### Multiple Objects with Motion
```python theme={null}
from manimvtk import *
class MultiObjectMotion(Scene):
def construct(self):
# Create objects
circle = Circle(radius=0.5, color=BLUE).shift(LEFT * 2)
square = Square(side_length=0.8, color=RED)
triangle = Triangle(color=GREEN).shift(RIGHT * 2)
self.add(circle, square, triangle)
# Synchronized motion
self.play(
circle.animate.shift(UP * 2),
square.animate.rotate(PI),
triangle.animate.scale(1.5),
run_time=2
)
# Sequential motion
self.play(circle.animate.shift(RIGHT * 4), run_time=1)
self.play(square.animate.shift(DOWN * 2), run_time=1)
self.play(triangle.animate.shift(LEFT * 4), run_time=1)
self.wait()
```
```bash theme={null}
manimvtk -pqm scene.py MultiObjectMotion --vtk-time-series
```
### Rotating 3D Object
```python theme={null}
from manimvtk import *
class Rotating3DObject(ThreeDScene):
def construct(self):
# Create a torus
torus = Surface(
lambda u, v: np.array([
(2 + np.cos(v)) * np.cos(u),
(2 + np.cos(v)) * np.sin(u),
np.sin(v)
]),
u_range=[0, TAU],
v_range=[0, TAU],
resolution=(40, 40)
)
torus.set_color_by_gradient(BLUE, PURPLE, RED)
self.set_camera_orientation(phi=60 * DEGREES, theta=45 * DEGREES)
# Create and rotate
self.play(Create(torus), run_time=2)
self.play(Rotate(torus, angle=TAU, axis=UP, run_time=4))
self.wait()
```
```bash theme={null}
manimvtk -pqh scene.py Rotating3DObject --renderer vtk --vtk-time-series
```
## Frame Rate Control
Control the frame rate to adjust time resolution:
```bash theme={null}
# 30 fps (default) - 30 frames per second
manimvtk -pqh scene.py MyScene --vtk-time-series
# 60 fps - smoother, more files
manimvtk -pqh -r 60 scene.py MyScene --vtk-time-series
# 15 fps - fewer files, less storage
manimvtk -pqh -r 15 scene.py MyScene --vtk-time-series
```
**Trade-offs:**
* **Higher fps**: Smoother animation, more files, more storage
* **Lower fps**: Less storage, choppier animation
## File Naming Convention
Files are named with zero-padded frame numbers:
```
MyScene_00000.vtp # Frame 0
MyScene_00001.vtp # Frame 1
...
MyScene_00099.vtp # Frame 99
MyScene_00100.vtp # Frame 100
```
Padding ensures correct alphabetical sorting.
## Storage Considerations
Time series export can create many files:
**Calculation:**
```
Number of files = total_frames = duration_seconds × frame_rate
File size total ≈ size_per_frame × total_frames
```
**Example:**
* 10 second animation at 30 fps = 300 files
* If each file is 500 KB = 150 MB total
Long animations at high frame rates can generate **hundreds of files** and require **gigabytes** of storage
### Optimization Tips
Lower frame rate for testing:
```bash theme={null}
# Test with low frame rate
manimvtk -pql -r 15 scene.py MyScene --vtk-time-series
# Final render at full rate
manimvtk -pqh -r 60 scene.py MyScene --vtk-time-series
```
Use shorter `run_time` during development:
```python theme={null}
# Development
self.play(Create(surface), run_time=0.5)
# Production
self.play(Create(surface), run_time=2)
```
Lower resolution for faster export:
```python theme={null}
# Development
surface = Surface(func, resolution=(15, 15))
# Production
surface = Surface(func, resolution=(50, 50))
```
After loading in ParaView:
1. File → Save Data
2. Choose output location
3. Check "Write all timesteps"
4. Check "Use compression"
## Viewing and Analysis in ParaView
### Timeline Controls
* **Play/Pause**: Animate through time steps
* **Step Forward/Back**: Move one frame at a time
* **Time Slider**: Scrub to any frame
* **First/Last Frame**: Jump to beginning/end
### Animation Settings
In ParaView:
1. **View → Animation View**
2. Set animation duration
3. Set frame rate
4. Export as video:
* File → Save Animation
* Choose format (AVI, MP4, etc.)
### Filters on Time Series
Apply filters that respect time:
```
Temporal:
- Temporal Interpolator
- Temporal Shifts Scale
- Temporal Statistics
Geometric:
- Clip (changes over time)
- Threshold (updates per frame)
- Glyph (follows motion)
```
### Extract Specific Frames
Save individual frames:
1. Use time slider to desired frame
2. File → Save Data
3. Uncheck "Write all timesteps"
4. Save single `.vtp` file
## Combining with Other Exports
You can use both export methods:
```bash theme={null}
# Export both final frame AND time series
manimvtk -pqh scene.py MyScene --vtk-export --vtk-time-series
```
**Output:**
```
media/vtk/MyScene/
├── MyScene_final.vtp # Static export (final frame)
├── MyScene.pvd # Time series collection
├── MyScene_00000.vtp # Time series frame 0
├── MyScene_00001.vtp # Time series frame 1
└── ...
```
## Troubleshooting
**Cause:** Long animation or high frame rate
**Solution:**
* Reduce frame rate: `-r 15` instead of `-r 60`
* Shorten animation duration
* Use `--vtk-export` for final frame only
**Cause:** Opened individual `.vtp` instead of `.pvd`
**Solution:**
* Close all files in ParaView
* File → Open → Select the `.pvd` file
* Click Apply
**Cause:** Frame files moved or renamed
**Solution:**
* Ensure all `.vtp` files are in same directory as `.pvd`
* Check `.pvd` file paths are relative
* Re-export if files were moved
**Cause:** High resolution geometry or many frames
**Solution:**
* Lower surface resolution during testing
* Use `-ql` quality for faster export
* Reduce frame rate
## Best Practices
1. **Test with low quality first**
```bash theme={null}
manimvtk -ql -r 15 scene.py MyScene --vtk-time-series
```
2. **Use descriptive scene names**
```python theme={null}
class FluidFlowSimulation(Scene): # Good
class Test123(Scene): # Avoid
```
3. **Monitor disk space**
```bash theme={null}
du -sh media/vtk/MyScene/
```
4. **Clean up old exports**
```bash theme={null}
rm -rf media/vtk/old_scene/
```
## Next Steps
Master ParaView visualization
Learn static export
View scientific visualization examples
Explore animation types