pythreejs

2.4.2 · active · verified Fri Apr 17

pythreejs provides interactive 3D graphics for the Jupyter Notebook and JupyterLab environments, leveraging the popular Three.js JavaScript library and Jupyter Widgets. It allows Python users to create and manipulate 3D scenes directly within their notebooks. The current version is 2.4.2, and it typically sees a few releases per year, often tracking updates in Three.js or Jupyter widgets.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple 3D scene with a red cube, set up a camera, and render it using `pythreejs` within a Jupyter Notebook or JupyterLab environment. It also includes `OrbitControls` for interactive camera navigation.

from pythreejs import Scene, PerspectiveCamera, WebGLRenderer, Mesh, BoxGeometry, MeshStandardMaterial, OrbitControls
from IPython.display import display

# Create a basic scene with a red cube
scene = Scene(children=[
    Mesh(
        geometry=BoxGeometry(1, 1, 1),
        material=MeshStandardMaterial(color='red')
    )
])

# Set up a camera
camera = PerspectiveCamera(position=[3, 3, 3], fov=60, aspect=1.5)

# Create a WebGL renderer and attach the scene and camera
# Add OrbitControls for interactive camera movement
renderer = WebGLRenderer(
    scene=scene,
    camera=camera,
    controls=[OrbitControls(controlling=camera)]
)
renderer.width = 600
renderer.height = 400

# Display the interactive 3D renderer in a Jupyter environment
display(renderer)

view raw JSON →