Skip to main content

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:
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:
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

Time Series Guide

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:
<VTKFile type="PolyData" version="1.0">
  <PolyData>
    <Piece NumberOfPoints="N" NumberOfPolys="M">
      <Points>...</Points>
      <Polys>...</Polys>
      <PointData>
        <DataArray Name="Colors" .../>
      </PointData>
    </Piece>
  </PolyData>
</VTKFile>
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:
<VTKFile type="vtkMultiBlockDataSet">
  <vtkMultiBlockDataSet>
    <DataSet index="0" file="Circle_0.vtp"/>
    <DataSet index="1" file="Square_1.vtp"/>
  </vtkMultiBlockDataSet>
</VTKFile>
Example output:
media/vtk/MyScene/
├── MyScene_final.vtm
├── Circle_0.vtp
└── Square_1.vtp

Basic Examples

Export a Simple Shape

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()
manimvtk -pql scene.py CircleExport --vtk-export
Output: media/vtk/CircleExport/CircleExport_final.vtp

Export Multiple Objects

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()
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

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()
manimvtk -pqh scene.py SurfaceExport --renderer vtk --vtk-export

Export Location

By default, VTK files are saved to:
media/vtk/<SceneName>/
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:
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:
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:
MobjectVTK Representation
Filled shapesPolygons (triangulated)
Stroked shapesPolyLines
SurfacesPolygonal mesh
Text/TexFilled paths (polygons)

Transformations

All transformations (position, rotation, scale) are applied before export:
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:
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 for details.

Vector Fields

Attach vector data for flow visualization:
from manimvtk.vtk import add_vector_field

# Add velocity vectors to exported polydata
add_vector_field(polydata, "velocity", velocity_array)
See 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

ParaView Guide

Detailed ParaView visualization guide

PyVista (Python)

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)

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:
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 correctlyCheck:
  • Are colors set before rendering?
  • Does the mobject have a stroke or fill?
# Ensure colors are set
circle.set_color(BLUE)
circle.set_fill(BLUE, opacity=0.5)

Next Steps