Pyrender

0.1.45 · active · verified Wed Apr 15

Pyrender is a pure Python library (compatible with Python 2.7, 3.4, 3.5, 3.6, though recent Python versions have known issues) for physically-based rendering and visualization. It adheres to the glTF 2.0 specification and provides both an interactive scene viewer and an offscreen renderer capable of GPU-accelerated rendering on headless servers, making it well-suited for machine learning applications. It is lightweight, easy to install, and designed for simplicity of use. The current version is 0.1.45, with development continuing on GitHub.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a basic mesh using `trimesh`, add it to a Pyrender scene, set up a camera and lighting, and then display the scene in an interactive viewer. For offscreen rendering, a `pyrender.OffscreenRenderer` would be used instead of `pyrender.Viewer`.

import trimesh
import pyrender

# Load a mesh (e.g., a simple box)
fuze_trimesh = trimesh.creation.icosphere()
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)

# Create a scene
scene = pyrender.Scene()
scene.add(mesh)

# Add a camera
camera = pyrender.PerspectiveCamera(yfov=0.8, aspectRatio=1.0)
camera_pose = [1.0, 0.0, 0.0, 0.0,
               0.0, 1.0, 0.0, 0.0,
               0.0, 0.0, 1.0, 3.0,
               0.0, 0.0, 0.0, 1.0]
scene.add(camera, pose=camera_pose)

# Add some lighting
light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=3.0)
light_pose = [0.0, 0.0, 0.0, 0.0,
              -0.5, 0.8, 0.0, 0.0,
               0.0, 0.0, 1.0, 0.0,
               0.0, 0.0, 0.0, 1.0]
scene.add(light, pose=light_pose)

# View the scene
pyrender.Viewer(scene, use_raymond_lighting=True)

view raw JSON →