Class: Scene
Defined in: core/Scene.ts:68
Scene orchestrator for manimweb. Manages the renderer, camera, mobjects, and animation playback. Works like Manim's Scene class - add mobjects, play animations.
Extended by
Constructors
Constructor
new Scene(
container,options):Scene
Defined in: core/Scene.ts:112
Create a new Scene.
Parameters
container
HTMLElement
DOM element to render into
options
SceneOptions = {}
Scene configuration options
Returns
Scene
Properties
_autoRender
protected_autoRender:boolean=true
Defined in: core/Scene.ts:96
_disposed
protected_disposed:boolean=false
Defined in: core/Scene.ts:80
_waitCleanups
protected_waitCleanups: () =>void[] =[]
Defined in: core/Scene.ts:81
Returns
void
Accessors
_hasActiveLoop
Get Signature
get
protected_hasActiveLoop():boolean
Defined in: core/Scene.ts:219
Whether a render loop is active (play() or wait()). Used by ThreeDScene to avoid duplicate orbit rAF loops.
Returns
boolean
audioManager
Get Signature
get audioManager():
AudioManager
Defined in: core/Scene.ts:245
Get the audio manager (lazily created on first access). Use this to access lower-level audio controls.
Returns
backgroundOpacity
Get Signature
get backgroundOpacity():
number
Defined in: core/Scene.ts:1040
Get the background opacity (0 = fully transparent, 1 = fully opaque).
Returns
number
Set Signature
set backgroundOpacity(
value):void
Defined in: core/Scene.ts:1048
Set the background opacity (0 = fully transparent, 1 = fully opaque). Only effective if the scene was created with backgroundOpacity < 1.
Parameters
value
number
Returns
void
camera
Get Signature
get camera():
Camera2D
Defined in: core/Scene.ts:181
Get the camera.
Returns
currentTime
Get Signature
get currentTime():
number
Defined in: core/Scene.ts:226
Get the current playback time.
Returns
number
isPlaying
Get Signature
get isPlaying():
boolean
Defined in: core/Scene.ts:211
Get whether animations are currently playing.
Returns
boolean
mobjects
Get Signature
get mobjects():
ReadonlySet<Mobject>
Defined in: core/Scene.ts:233
Get all mobjects in the scene.
Returns
ReadonlySet<Mobject>
renderer
Get Signature
get renderer():
Renderer
Defined in: core/Scene.ts:188
Get the renderer.
Returns
stateManager
Get Signature
get stateManager():
SceneStateManager
Defined in: core/Scene.ts:1067
Get the scene's state manager for advanced undo/redo control.
Returns
threeScene
Get Signature
get threeScene():
Scene
Defined in: core/Scene.ts:174
Get the Three.js scene.
Returns
Scene
timeline
Get Signature
get timeline():
Timeline
Defined in: core/Scene.ts:195
Get the current timeline.
Returns
Methods
_needsPerFrameRendering()
protected_needsPerFrameRendering():boolean
Defined in: core/Scene.ts:738
Whether the scene needs per-frame rendering during wait(). Returns true if any mobject has updaters. Subclasses (e.g. ThreeDScene) can override to also check for ambient camera rotation, etc.
Returns
boolean
_render()
protected_render():void
Defined in: core/Scene.ts:750
Render a single frame. Syncs only dirty mobjects before rendering for performance. Protected so subclasses (e.g. ZoomedScene) can override for multi-pass rendering.
Returns
void
add()
add(...
mobjects):this
Defined in: core/Scene.ts:321
Add mobjects to the scene.
Parameters
mobjects
...Mobject[]
Mobjects to add
Returns
this
addForegroundMobject()
addForegroundMobject(...
mobjects):this
Defined in: core/Scene.ts:298
Add mobjects as foreground objects that render on top of everything. Matches Manim Python's add_foreground_mobject().
Parameters
mobjects
...Mobject[]
Mobjects to add in the foreground
Returns
this
addSound()
addSound(
url,options?):Promise<AudioTrack>
Defined in: core/Scene.ts:266
Add a sound to play at a specific time on the timeline.
Mirrors Python manim's self.add_sound("file.wav", time_offset=0.5).
Parameters
url
string
URL of the audio file
options?
Scheduling and playback options
Returns
Promise<AudioTrack>
Promise resolving to the created AudioTrack
Example
await scene.addSound('/sounds/click.wav', { time: 0.5 });
await scene.addSound('/sounds/whoosh.wav'); // plays at time 0
addSoundAtAnimation()
addSoundAtAnimation(
animation,url,options?):Promise<AudioTrack>
Defined in: core/Scene.ts:285
Add a sound that starts when a given animation begins.
Parameters
animation
The animation to sync with
url
string
URL of the audio file
options?
Omit<AddSoundOptions, "time"> & object
Additional options (timeOffset shifts relative to animation start)
Returns
Promise<AudioTrack>
Promise resolving to the created AudioTrack
Example
const fadeIn = new FadeIn(circle);
await scene.addSoundAtAnimation(fadeIn, '/sounds/appear.wav');
await scene.play(fadeIn);
batch()
batch(
callback):void
Defined in: core/Scene.ts:942
Batch multiple mobject updates without re-rendering between each. Useful for performance when making many changes at once.
Parameters
callback
() => void
Function containing multiple mobject operations
Returns
void
Example
scene.batch(() => {
circle.setColor('red');
circle.shift([1, 0, 0]);
square.setOpacity(0.5);
});
clear()
clear(
__namedParameters):this
Defined in: core/Scene.ts:420
Clear all mobjects from the scene.
Parameters
__namedParameters
render?
boolean = true
Returns
this
dispose()
dispose():
void
Defined in: core/Scene.ts:1220
Clean up all resources (renderer, mobjects, audio).
Returns
void
export()
export(
filename,options?):Promise<Blob>
Defined in: core/Scene.ts:1176
Export the scene animation as a file (GIF or video). Format is inferred from the filename extension.
Supported extensions:
.gif- Animated GIF.webm- WebM video (VP9).mp4- MP4 video (browser codec support varies).mov- QuickTime video (browser codec support varies)
Parameters
filename
string
Output filename (e.g. 'animation.gif', 'scene.webm')
options?
Export options (fps, quality, dimensions, etc.)
Returns
Promise<Blob>
The exported Blob
Example
// Export as GIF
const blob = await scene.export('animation.gif');
// Export as WebM with custom options
const blob = await scene.export('scene.webm', {
fps: 30,
quality: 0.8,
onProgress: (p) => console.log(`${Math.round(p * 100)}%`),
});
getCanvas()
getCanvas():
HTMLCanvasElement
Defined in: core/Scene.ts:1004
Get the canvas element.
Returns
HTMLCanvasElement
The HTMLCanvasElement used for rendering
getContainer()
getContainer():
HTMLElement
Defined in: core/Scene.ts:1013
Get the container element the scene is rendered into. Returns the parent element of the canvas.
Returns
HTMLElement
The container HTMLElement
getHeight()
getHeight():
number
Defined in: core/Scene.ts:1033
Get the height of the canvas in pixels.
Returns
number
Canvas height in pixels
getState()
getState(
label?):SceneSnapshot
Defined in: core/Scene.ts:1121
Get a snapshot of the current scene state without modifying stacks.
Parameters
label?
string
Returns
getTargetFps()
getTargetFps():
number
Defined in: core/Scene.ts:968
Get the current target frame rate.
Returns
number
Target fps
getTimelineDuration()
getTimelineDuration():
number
Defined in: core/Scene.ts:1056
Get the total duration of the current timeline.
Returns
number
Duration in seconds, or 0 if no timeline
getWidth()
getWidth():
number
Defined in: core/Scene.ts:1025
Get the width of the canvas in pixels.
Returns
number
Canvas width in pixels
isInView()
isInView(
object):boolean
Defined in: core/Scene.ts:791
Check if an object is within the camera's view frustum. Useful for manual culling checks or debugging.
Parameters
object
Object3D
Three.js object to check
Returns
boolean
true if object is in view or if culling is disabled
pause()
pause():
this
Defined in: core/Scene.ts:653
Pause playback (video and audio).
Returns
this
play()
play(...
animations):Promise<void>
Defined in: core/Scene.ts:462
Play animations in parallel (all at once). Matches Manim's scene.play() behavior where multiple animations run simultaneously. Automatically adds mobjects to the scene if not already present.
Parameters
animations
...Animation[]
Animations to play
Returns
Promise<void>
Promise that resolves when all animations complete
playAll()
playAll(...
animations):Promise<void>
Defined in: core/Scene.ts:531
Play multiple animations in parallel (all at once). Alias for play() - delegates to play() to avoid duplicated logic.
Parameters
animations
...Animation[]
Animations to play simultaneously
Returns
Promise<void>
Promise that resolves when all animations complete
redo()
redo():
boolean
Defined in: core/Scene.ts:1110
Redo the last undone change. The current state is pushed to the undo stack.
Returns
boolean
true if redo was applied, false if nothing to redo
remove()
remove(...
mobjects):this
Defined in: core/Scene.ts:366
Remove mobjects from the scene.
Parameters
mobjects
...Mobject[]
Mobjects to remove
Returns
this
render()
render():
void
Defined in: core/Scene.ts:1140
Force render a single frame. Useful for video export where frames need to be captured at specific times.
Returns
void
resize()
resize(
width,height):this
Defined in: core/Scene.ts:986
Handle window resize.
Parameters
width
number
New width in pixels
height
number
New height in pixels
Returns
this
resume()
resume():
this
Defined in: core/Scene.ts:667
Resume playback (video and audio).
Returns
this
saveState()
saveState(
label?):SceneSnapshot
Defined in: core/Scene.ts:1086
Save the current state of all scene mobjects. Pushes onto the undo stack and clears the redo stack.
Parameters
label?
string
Optional human-readable label
Returns
The captured SceneSnapshot
Example
scene.add(circle, square);
scene.saveState();
circle.shift([2, 0, 0]);
scene.undo(); // circle returns to original position
seek()
seek(
time):this
Defined in: core/Scene.ts:638
Seek to a specific time in the timeline. Also seeks the audio manager if audio has been used.
Parameters
time
number
Time in seconds
Returns
this
setFrustumCulling()
setFrustumCulling(
enabled):this
Defined in: core/Scene.ts:976
Enable or disable frustum culling.
Parameters
enabled
boolean
Whether frustum culling should be enabled
Returns
this
setState()
setState(
snapshot):void
Defined in: core/Scene.ts:1129
Apply a previously captured snapshot, overwriting all mobject states. Does NOT modify undo/redo stacks. Call saveState() first to preserve.
Parameters
snapshot
Returns
void
setTargetFps()
setTargetFps(
fps):this
Defined in: core/Scene.ts:958
Set the target frame rate.
Parameters
fps
number
Target frames per second (1-120)
Returns
this
stop()
stop():
this
Defined in: core/Scene.ts:682
Stop playback and reset timeline (video and audio).
Returns
this
undo()
undo():
boolean
Defined in: core/Scene.ts:1096
Undo the last change (restore the most recently saved state). The current state is pushed to the redo stack.
Returns
boolean
true if undo was applied, false if nothing to undo
wait()
wait(
duration):Promise<void>
Defined in: core/Scene.ts:541
Wait for a duration (pause between animations). Runs a render loop during the wait so that updaters keep ticking.
Parameters
duration
number = 1
Duration in seconds
Returns
Promise<void>
Promise that resolves after the duration