Animation ¶
Animation(compute=None, reset=None, view=None)
Minimal base class for time-stepped animations.
Animation
defines the three lifecycle hooks that the [Engine
][npblender.engine.Engine]
calls on every frame/subframe: reset()
, compute()
, and view()
. You can either
subclass and override these methods, or pass callables to the constructor to set
_reset
, _compute
, and _view
dynamically. It also exposes lightweight accessors
to the global engine (engine
, time
, delta_time
) and optional baking hooks.
Notes
reset()
is called once on the first frame of a run.compute()
is called at each substep; the engine enumerates subframes as1, 2, …, n-1, 0
, where0
is the main frame after substeps.view()
is called after compute/load to push results into Blender.
Optionally provide function-based hooks instead of subclassing.
If a callable is provided, it is bound to the corresponding private
attribute (_compute
, _reset
, _view
) that compute()
, reset()
,
and view()
will delegate to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compute
|
callable or None
|
Step function called at each subframe. |
None
|
reset
|
callable or None
|
Initialization function called at the first frame. |
None
|
view
|
callable or None
|
Function that writes results back to Blender. |
None
|
delta_time
property
¶
delta_time
Time step between substeps (proxy to engine.delta_time
).
Returns:
Type | Description |
---|---|
float
|
|
engine
property
¶
engine
Global engine singleton.
Returns:
Type | Description |
---|---|
Engine
|
The module-level engine instance that drives the animation. |
time
property
¶
time
Current time in seconds (proxy to engine.time
).
Returns:
Type | Description |
---|---|
float
|
The timeline time including subframes, offset, and scale. |
compute ¶
compute()
Per-substep compute hook.
To be overridden
Delegates to _compute()
if defined. Called by the engine for each
subframe and the main frame (… , n-1, 0
).
get_frame_data ¶
get_frame_data()
Return animation data to be baked for the current frame.
Returns:
Type | Description |
---|---|
Any or None
|
Per-animation payload to store in the bake file, or |
get_frame_state ¶
get_frame_state()
Return state to be saved to resume simulation from the current frame..
Returns:
Type | Description |
---|---|
Any or None
|
Optional state payload |
go ¶
go(subframes=0)
Run this animation once through the engine.
Convenience wrapper for engine.animation(self, subframes=subframes)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subframes
|
int
|
Number of subframes per frame. |
0
|
Examples:
anim = Animation(compute=lambda: ..., reset=lambda: ..., view=lambda: ...)
anim.go(subframes=4)
reset ¶
reset()
First-frame initialization hook.
To be overridden
Delegates to _reset()
if defined. Called once by the engine at the
first frame of the run.
set_frame_data ¶
set_frame_data(data)
Load animation data from the bake file for the current frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
Payload previously produced by |
required |
Returns:
Type | Description |
---|---|
bool
|
|
set_frame_state ¶
set_frame_state(data)
Restore persistent state saved with the current frame.
The simulation can be resume for next frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
State payload previously produced by |
required |
view ¶
view()
Push results into Blender.
To be overridden
Delegates to _view()
if defined. Called by the engine after compute or
after loading a baked frame, to update Blender data/objects.