@redwilly/anima 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/SceneLoader.d.ts +22 -0
- package/dist/cli/SceneLoader.js +47 -0
- package/dist/cli/commands/export-frame.d.ts +13 -0
- package/dist/cli/commands/export-frame.js +60 -0
- package/dist/cli/commands/list-scenes.d.ts +5 -0
- package/dist/cli/commands/list-scenes.js +22 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.js +11 -0
- package/dist/cli/commands/render.d.ts +16 -0
- package/dist/cli/commands/render.js +76 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +63 -0
- package/dist/core/animations/Animation.d.ts +41 -0
- package/dist/core/animations/Animation.js +76 -0
- package/dist/core/animations/camera/Follow.d.ts +70 -0
- package/dist/core/animations/camera/Follow.js +69 -0
- package/dist/core/animations/camera/Shake.d.ts +90 -0
- package/dist/core/animations/camera/Shake.js +87 -0
- package/dist/core/animations/camera/index.d.ts +2 -0
- package/dist/core/animations/camera/index.js +2 -0
- package/dist/core/animations/categories/ExitAnimation.d.ts +17 -0
- package/dist/core/animations/categories/ExitAnimation.js +15 -0
- package/dist/core/animations/categories/IntroductoryAnimation.d.ts +16 -0
- package/dist/core/animations/categories/IntroductoryAnimation.js +14 -0
- package/dist/core/animations/categories/TransformativeAnimation.d.ts +25 -0
- package/dist/core/animations/categories/TransformativeAnimation.js +25 -0
- package/dist/core/animations/categories/index.d.ts +3 -0
- package/dist/core/animations/categories/index.js +3 -0
- package/dist/core/animations/composition/Parallel.d.ts +37 -0
- package/dist/core/animations/composition/Parallel.js +79 -0
- package/dist/core/animations/composition/Sequence.d.ts +41 -0
- package/dist/core/animations/composition/Sequence.js +95 -0
- package/dist/core/animations/composition/index.d.ts +2 -0
- package/dist/core/animations/composition/index.js +3 -0
- package/dist/core/animations/draw/Draw.d.ts +30 -0
- package/dist/core/animations/draw/Draw.js +122 -0
- package/dist/core/animations/draw/Unwrite.d.ts +30 -0
- package/dist/core/animations/draw/Unwrite.js +120 -0
- package/dist/core/animations/draw/Write.d.ts +35 -0
- package/dist/core/animations/draw/Write.js +119 -0
- package/dist/core/animations/draw/index.d.ts +3 -0
- package/dist/core/animations/draw/index.js +3 -0
- package/dist/core/animations/draw/partialPath.d.ts +6 -0
- package/dist/core/animations/draw/partialPath.js +138 -0
- package/dist/core/animations/easing/bounce.d.ts +13 -0
- package/dist/core/animations/easing/bounce.js +37 -0
- package/dist/core/animations/easing/index.d.ts +7 -0
- package/dist/core/animations/easing/index.js +11 -0
- package/dist/core/animations/easing/manim.d.ts +46 -0
- package/dist/core/animations/easing/manim.js +102 -0
- package/dist/core/animations/easing/registry.d.ts +8 -0
- package/dist/core/animations/easing/registry.js +25 -0
- package/dist/core/animations/easing/standard.d.ts +113 -0
- package/dist/core/animations/easing/standard.js +151 -0
- package/dist/core/animations/easing/types.d.ts +6 -0
- package/dist/core/animations/easing/types.js +0 -0
- package/dist/core/animations/fade/FadeIn.d.ts +17 -0
- package/dist/core/animations/fade/FadeIn.js +22 -0
- package/dist/core/animations/fade/FadeOut.d.ts +17 -0
- package/dist/core/animations/fade/FadeOut.js +23 -0
- package/dist/core/animations/fade/index.d.ts +2 -0
- package/dist/core/animations/fade/index.js +2 -0
- package/dist/core/animations/index.d.ts +11 -0
- package/dist/core/animations/index.js +17 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.d.ts +33 -0
- package/dist/core/animations/keyframes/KeyframeAnimation.js +40 -0
- package/dist/core/animations/keyframes/KeyframeTrack.d.ts +31 -0
- package/dist/core/animations/keyframes/KeyframeTrack.js +83 -0
- package/dist/core/animations/keyframes/index.d.ts +4 -0
- package/dist/core/animations/keyframes/index.js +5 -0
- package/dist/core/animations/keyframes/types.d.ts +25 -0
- package/dist/core/animations/keyframes/types.js +6 -0
- package/dist/core/animations/morph/MorphTo.d.ts +22 -0
- package/dist/core/animations/morph/MorphTo.js +42 -0
- package/dist/core/animations/morph/index.d.ts +1 -0
- package/dist/core/animations/morph/index.js +1 -0
- package/dist/core/animations/transform/MoveTo.d.ts +24 -0
- package/dist/core/animations/transform/MoveTo.js +38 -0
- package/dist/core/animations/transform/Rotate.d.ts +23 -0
- package/dist/core/animations/transform/Rotate.js +34 -0
- package/dist/core/animations/transform/Scale.d.ts +23 -0
- package/dist/core/animations/transform/Scale.js +35 -0
- package/dist/core/animations/transform/index.d.ts +3 -0
- package/dist/core/animations/transform/index.js +3 -0
- package/dist/core/animations/types.d.ts +52 -0
- package/dist/core/animations/types.js +6 -0
- package/dist/core/camera/Camera.d.ts +87 -0
- package/dist/core/camera/Camera.js +175 -0
- package/dist/core/camera/CameraFrame.d.ts +242 -0
- package/dist/core/camera/CameraFrame.js +322 -0
- package/dist/core/camera/index.d.ts +4 -0
- package/dist/core/camera/index.js +3 -0
- package/dist/core/camera/types.d.ts +17 -0
- package/dist/core/camera/types.js +1 -0
- package/dist/core/errors/AnimationErrors.d.ts +12 -0
- package/dist/core/errors/AnimationErrors.js +37 -0
- package/dist/core/errors/index.d.ts +1 -0
- package/dist/core/errors/index.js +1 -0
- package/dist/core/math/Vector2/Vector2.d.ts +23 -0
- package/dist/core/math/Vector2/Vector2.js +46 -0
- package/dist/core/math/Vector2/index.d.ts +1 -0
- package/dist/core/math/Vector2/index.js +1 -0
- package/dist/core/math/bezier/BezierPath.d.ts +38 -0
- package/dist/core/math/bezier/BezierPath.js +264 -0
- package/dist/core/math/bezier/evaluators.d.ts +9 -0
- package/dist/core/math/bezier/evaluators.js +36 -0
- package/dist/core/math/bezier/index.d.ts +8 -0
- package/dist/core/math/bezier/index.js +6 -0
- package/dist/core/math/bezier/length.d.ts +5 -0
- package/dist/core/math/bezier/length.js +27 -0
- package/dist/core/math/bezier/morphing.d.ts +16 -0
- package/dist/core/math/bezier/morphing.js +151 -0
- package/dist/core/math/bezier/sampling.d.ts +7 -0
- package/dist/core/math/bezier/sampling.js +153 -0
- package/dist/core/math/bezier/split.d.ts +19 -0
- package/dist/core/math/bezier/split.js +44 -0
- package/dist/core/math/bezier/types.d.ts +8 -0
- package/dist/core/math/bezier/types.js +0 -0
- package/dist/core/math/color/Color.d.ts +28 -0
- package/dist/core/math/color/Color.js +60 -0
- package/dist/core/math/color/conversions.d.ts +17 -0
- package/dist/core/math/color/conversions.js +100 -0
- package/dist/core/math/color/index.d.ts +2 -0
- package/dist/core/math/color/index.js +2 -0
- package/dist/core/math/index.d.ts +4 -0
- package/dist/core/math/index.js +5 -0
- package/dist/core/math/matrix/Matrix3x3.d.ts +23 -0
- package/dist/core/math/matrix/Matrix3x3.js +91 -0
- package/dist/core/math/matrix/factories.d.ts +12 -0
- package/dist/core/math/matrix/factories.js +44 -0
- package/dist/core/math/matrix/index.d.ts +2 -0
- package/dist/core/math/matrix/index.js +2 -0
- package/dist/core/renderer/FrameRenderer.d.ts +37 -0
- package/dist/core/renderer/FrameRenderer.js +75 -0
- package/dist/core/renderer/ProgressReporter.d.ts +19 -0
- package/dist/core/renderer/ProgressReporter.js +58 -0
- package/dist/core/renderer/Renderer.d.ts +36 -0
- package/dist/core/renderer/Renderer.js +102 -0
- package/dist/core/renderer/drawMobject.d.ts +8 -0
- package/dist/core/renderer/drawMobject.js +109 -0
- package/dist/core/renderer/formats/index.d.ts +3 -0
- package/dist/core/renderer/formats/index.js +3 -0
- package/dist/core/renderer/formats/png.d.ts +5 -0
- package/dist/core/renderer/formats/png.js +7 -0
- package/dist/core/renderer/formats/sprite.d.ts +6 -0
- package/dist/core/renderer/formats/sprite.js +24 -0
- package/dist/core/renderer/formats/video.d.ts +8 -0
- package/dist/core/renderer/formats/video.js +51 -0
- package/dist/core/renderer/index.d.ts +7 -0
- package/dist/core/renderer/index.js +9 -0
- package/dist/core/renderer/types.d.ts +87 -0
- package/dist/core/renderer/types.js +13 -0
- package/dist/core/scene/Scene.d.ts +104 -0
- package/dist/core/scene/Scene.js +225 -0
- package/dist/core/scene/index.d.ts +2 -0
- package/dist/core/scene/index.js +1 -0
- package/dist/core/scene/types.d.ts +23 -0
- package/dist/core/scene/types.js +0 -0
- package/dist/core/serialization/animation.d.ts +23 -0
- package/dist/core/serialization/animation.js +176 -0
- package/dist/core/serialization/easingLookup.d.ts +13 -0
- package/dist/core/serialization/easingLookup.js +65 -0
- package/dist/core/serialization/index.d.ts +23 -0
- package/dist/core/serialization/index.js +29 -0
- package/dist/core/serialization/mobject.d.ts +23 -0
- package/dist/core/serialization/mobject.js +248 -0
- package/dist/core/serialization/prettyPrint.d.ts +12 -0
- package/dist/core/serialization/prettyPrint.js +16 -0
- package/dist/core/serialization/primitives.d.ts +24 -0
- package/dist/core/serialization/primitives.js +98 -0
- package/dist/core/serialization/registry.d.ts +29 -0
- package/dist/core/serialization/registry.js +39 -0
- package/dist/core/serialization/scene.d.ts +28 -0
- package/dist/core/serialization/scene.js +114 -0
- package/dist/core/serialization/types.d.ts +152 -0
- package/dist/core/serialization/types.js +6 -0
- package/dist/core/timeline/Timeline.d.ts +70 -0
- package/dist/core/timeline/Timeline.js +144 -0
- package/dist/core/timeline/index.d.ts +5 -0
- package/dist/core/timeline/index.js +4 -0
- package/dist/core/timeline/types.d.ts +29 -0
- package/dist/core/timeline/types.js +0 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +22 -0
- package/dist/mobjects/Mobject.d.ts +98 -0
- package/dist/mobjects/Mobject.js +343 -0
- package/dist/mobjects/VGroup/VGroup.d.ts +51 -0
- package/dist/mobjects/VGroup/VGroup.js +142 -0
- package/dist/mobjects/VGroup/index.d.ts +3 -0
- package/dist/mobjects/VGroup/index.js +2 -0
- package/dist/mobjects/VGroup/layout.d.ts +20 -0
- package/dist/mobjects/VGroup/layout.js +139 -0
- package/dist/mobjects/VMobject.d.ts +106 -0
- package/dist/mobjects/VMobject.js +216 -0
- package/dist/mobjects/geometry/Arc.d.ts +8 -0
- package/dist/mobjects/geometry/Arc.js +46 -0
- package/dist/mobjects/geometry/Arrow.d.ts +7 -0
- package/dist/mobjects/geometry/Arrow.js +34 -0
- package/dist/mobjects/geometry/Circle.d.ts +4 -0
- package/dist/mobjects/geometry/Circle.js +10 -0
- package/dist/mobjects/geometry/Line.d.ts +8 -0
- package/dist/mobjects/geometry/Line.js +19 -0
- package/dist/mobjects/geometry/Point.d.ts +5 -0
- package/dist/mobjects/geometry/Point.js +11 -0
- package/dist/mobjects/geometry/Polygon.d.ts +7 -0
- package/dist/mobjects/geometry/Polygon.js +21 -0
- package/dist/mobjects/geometry/Rectangle.d.ts +6 -0
- package/dist/mobjects/geometry/Rectangle.js +18 -0
- package/dist/mobjects/geometry/index.d.ts +7 -0
- package/dist/mobjects/geometry/index.js +7 -0
- package/dist/mobjects/graph/Graph.d.ts +28 -0
- package/dist/mobjects/graph/Graph.js +119 -0
- package/dist/mobjects/graph/GraphEdge.d.ts +26 -0
- package/dist/mobjects/graph/GraphEdge.js +64 -0
- package/dist/mobjects/graph/GraphNode.d.ts +19 -0
- package/dist/mobjects/graph/GraphNode.js +63 -0
- package/dist/mobjects/graph/index.d.ts +5 -0
- package/dist/mobjects/graph/index.js +5 -0
- package/dist/mobjects/graph/layouts/circular.d.ts +8 -0
- package/dist/mobjects/graph/layouts/circular.js +23 -0
- package/dist/mobjects/graph/layouts/forceDirected.d.ts +9 -0
- package/dist/mobjects/graph/layouts/forceDirected.js +102 -0
- package/dist/mobjects/graph/layouts/index.d.ts +3 -0
- package/dist/mobjects/graph/layouts/index.js +3 -0
- package/dist/mobjects/graph/layouts/tree.d.ts +9 -0
- package/dist/mobjects/graph/layouts/tree.js +99 -0
- package/dist/mobjects/graph/types.d.ts +35 -0
- package/dist/mobjects/graph/types.js +0 -0
- package/dist/mobjects/index.d.ts +6 -0
- package/dist/mobjects/index.js +6 -0
- package/dist/mobjects/text/Glyph.d.ts +11 -0
- package/dist/mobjects/text/Glyph.js +72 -0
- package/dist/mobjects/text/Text.d.ts +19 -0
- package/dist/mobjects/text/Text.js +76 -0
- package/dist/mobjects/text/index.d.ts +4 -0
- package/dist/mobjects/text/index.js +3 -0
- package/dist/mobjects/text/types.d.ts +12 -0
- package/dist/mobjects/text/types.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Vector2 } from '../math/Vector2/Vector2';
|
|
2
|
+
import { Matrix3x3 } from '../math/matrix/Matrix3x3';
|
|
3
|
+
import { CameraFrame } from './CameraFrame';
|
|
4
|
+
import { MANIM_FRAME_HEIGHT } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Camera manages the view into the scene.
|
|
7
|
+
* Uses CameraFrame (a Mobject) to store transform state, enabling camera animations.
|
|
8
|
+
*
|
|
9
|
+
* The Camera provides both instant manipulation methods (panTo, zoomTo) and
|
|
10
|
+
* access to the CameraFrame for fluent animation APIs.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Instant camera manipulation
|
|
14
|
+
* camera.zoomTo(2);
|
|
15
|
+
* camera.panTo(new Vector2(5, 3));
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Animated camera movement via frame
|
|
19
|
+
* this.play(this.frame.zoomIn(2).duration(1));
|
|
20
|
+
* this.play(this.frame.centerOn(circle).duration(0.5));
|
|
21
|
+
*/
|
|
22
|
+
export class Camera {
|
|
23
|
+
config;
|
|
24
|
+
/** The CameraFrame that stores the camera's transform state. Use this for animations. */
|
|
25
|
+
frame;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new Camera with the specified viewport dimensions.
|
|
28
|
+
*
|
|
29
|
+
* @param config - Configuration options
|
|
30
|
+
* @param config.pixelWidth - Width of the viewport in pixels (default: 1920)
|
|
31
|
+
* @param config.pixelHeight - Height of the viewport in pixels (default: 1080)
|
|
32
|
+
*/
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
this.config = {
|
|
35
|
+
pixelWidth: config.pixelWidth ?? 1920,
|
|
36
|
+
pixelHeight: config.pixelHeight ?? 1080,
|
|
37
|
+
};
|
|
38
|
+
this.frame = new CameraFrame({
|
|
39
|
+
pixelWidth: this.config.pixelWidth,
|
|
40
|
+
pixelHeight: this.config.pixelHeight,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// ========== Frame Dimensions (Manim-compatible) ==========
|
|
44
|
+
get frameHeight() {
|
|
45
|
+
return MANIM_FRAME_HEIGHT;
|
|
46
|
+
}
|
|
47
|
+
get frameWidth() {
|
|
48
|
+
const aspectRatio = this.config.pixelWidth / this.config.pixelHeight;
|
|
49
|
+
return MANIM_FRAME_HEIGHT * aspectRatio;
|
|
50
|
+
}
|
|
51
|
+
get frameYRadius() {
|
|
52
|
+
return this.frameHeight / 2;
|
|
53
|
+
}
|
|
54
|
+
get frameXRadius() {
|
|
55
|
+
return this.frameWidth / 2;
|
|
56
|
+
}
|
|
57
|
+
// ========== Pixel Dimensions ==========
|
|
58
|
+
get pixelWidth() {
|
|
59
|
+
return this.config.pixelWidth;
|
|
60
|
+
}
|
|
61
|
+
get pixelHeight() {
|
|
62
|
+
return this.config.pixelHeight;
|
|
63
|
+
}
|
|
64
|
+
// ========== Camera Transform Properties (read from frame) ==========
|
|
65
|
+
get position() {
|
|
66
|
+
return this.frame.position;
|
|
67
|
+
}
|
|
68
|
+
get zoom() {
|
|
69
|
+
return 1 / this.frame.scale.x;
|
|
70
|
+
}
|
|
71
|
+
get rotation() {
|
|
72
|
+
return this.frame.rotation;
|
|
73
|
+
}
|
|
74
|
+
// ========== Pan Operations (proxy to frame) ==========
|
|
75
|
+
pan(delta) {
|
|
76
|
+
const current = this.frame.position;
|
|
77
|
+
this.frame.pos(current.x + delta.x, current.y + delta.y);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
panTo(position) {
|
|
81
|
+
this.frame.pos(position.x, position.y);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
// ========== Zoom Operations (proxy to frame) ==========
|
|
85
|
+
zoomTo(level) {
|
|
86
|
+
if (level <= 0) {
|
|
87
|
+
throw new Error('Zoom level must be positive');
|
|
88
|
+
}
|
|
89
|
+
const frameScale = 1 / level;
|
|
90
|
+
this.frame.setScale(frameScale, frameScale);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
// ========== Rotation Operations (proxy to frame) ==========
|
|
94
|
+
rotateTo(angle) {
|
|
95
|
+
this.frame.setRotation(angle);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
// ========== View Matrix ==========
|
|
99
|
+
getViewMatrix() {
|
|
100
|
+
const framePos = this.frame.position;
|
|
101
|
+
const frameScale = this.frame.scale;
|
|
102
|
+
const frameRotation = this.frame.rotation;
|
|
103
|
+
const zoomX = 1 / frameScale.x;
|
|
104
|
+
const zoomY = 1 / frameScale.y;
|
|
105
|
+
const translate = Matrix3x3.translation(-framePos.x, -framePos.y);
|
|
106
|
+
const rotate = Matrix3x3.rotation(-frameRotation);
|
|
107
|
+
const scale = Matrix3x3.scale(zoomX, zoomY);
|
|
108
|
+
return scale.multiply(rotate).multiply(translate);
|
|
109
|
+
}
|
|
110
|
+
// ========== Coordinate Transforms ==========
|
|
111
|
+
/**
|
|
112
|
+
* Transforms a world-space position to screen-space (pixel) coordinates.
|
|
113
|
+
*
|
|
114
|
+
* Screen coordinates have origin at top-left, with x increasing right
|
|
115
|
+
* and y increasing downward.
|
|
116
|
+
*
|
|
117
|
+
* @param pos - Position in world coordinates
|
|
118
|
+
* @returns Position in screen coordinates (pixels)
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const screenPos = camera.worldToScreen(circle.position);
|
|
122
|
+
* console.log(`Circle is at pixel (${screenPos.x}, ${screenPos.y})`);
|
|
123
|
+
*/
|
|
124
|
+
worldToScreen(pos) {
|
|
125
|
+
const viewMatrix = this.getViewMatrix();
|
|
126
|
+
const transformed = viewMatrix.transformPoint(pos);
|
|
127
|
+
const screenX = (transformed.x + 1) * 0.5 * this.config.pixelWidth;
|
|
128
|
+
const screenY = (1 - transformed.y) * 0.5 * this.config.pixelHeight;
|
|
129
|
+
return new Vector2(screenX, screenY);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Transforms a screen-space (pixel) position to world coordinates.
|
|
133
|
+
* This is the inverse of worldToScreen.
|
|
134
|
+
*
|
|
135
|
+
* @param pos - Position in screen coordinates (pixels, origin at top-left)
|
|
136
|
+
* @returns Position in world coordinates
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Convert a mouse click position to world coordinates
|
|
140
|
+
* const worldPos = camera.screenToWorld(new Vector2(mouseX, mouseY));
|
|
141
|
+
*/
|
|
142
|
+
screenToWorld(pos) {
|
|
143
|
+
const ndcX = (pos.x / this.config.pixelWidth) * 2 - 1;
|
|
144
|
+
const ndcY = 1 - (pos.y / this.config.pixelHeight) * 2;
|
|
145
|
+
const viewMatrix = this.getViewMatrix();
|
|
146
|
+
const inverseView = viewMatrix.inverse();
|
|
147
|
+
return inverseView.transformPoint(new Vector2(ndcX, ndcY));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Checks if a world-space position is currently visible within the camera frame.
|
|
151
|
+
*
|
|
152
|
+
* @param pos - Position in world coordinates to check
|
|
153
|
+
* @returns True if the position is within the visible frame bounds
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* if (camera.isInView(object.position)) {
|
|
157
|
+
* console.log('Object is visible');
|
|
158
|
+
* }
|
|
159
|
+
*/
|
|
160
|
+
isInView(pos) {
|
|
161
|
+
const framePos = this.frame.position;
|
|
162
|
+
const halfWidth = this.frame.width / 2;
|
|
163
|
+
const halfHeight = this.frame.height / 2;
|
|
164
|
+
return (pos.x >= framePos.x - halfWidth &&
|
|
165
|
+
pos.x <= framePos.x + halfWidth &&
|
|
166
|
+
pos.y >= framePos.y - halfHeight &&
|
|
167
|
+
pos.y <= framePos.y + halfHeight);
|
|
168
|
+
}
|
|
169
|
+
reset() {
|
|
170
|
+
this.frame.pos(0, 0);
|
|
171
|
+
this.frame.setScale(1, 1);
|
|
172
|
+
this.frame.setRotation(0);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Mobject } from '../../mobjects/Mobject';
|
|
2
|
+
import { Parallel } from '../animations/composition';
|
|
3
|
+
import type { Animation } from '../animations/Animation';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for CameraFrame.
|
|
6
|
+
*/
|
|
7
|
+
interface CameraFrameConfig {
|
|
8
|
+
/** Width of the viewport in pixels. Defaults to 1920. */
|
|
9
|
+
pixelWidth?: number;
|
|
10
|
+
/** Height of the viewport in pixels. Defaults to 1080. */
|
|
11
|
+
pixelHeight?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Camera bounds that limit how far the camera can pan.
|
|
15
|
+
*/
|
|
16
|
+
interface Bounds {
|
|
17
|
+
minX: number;
|
|
18
|
+
maxX: number;
|
|
19
|
+
minY: number;
|
|
20
|
+
maxY: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* CameraFrame represents the viewport window in world space.
|
|
24
|
+
* Extends Mobject (not VMobject - no visual representation).
|
|
25
|
+
* Its transform properties define what the camera shows:
|
|
26
|
+
* - scale(2) = zoom OUT (larger frame = see more)
|
|
27
|
+
* - scale(0.5) = zoom IN (smaller frame = see less)
|
|
28
|
+
*
|
|
29
|
+
* The CameraFrame is the primary way to control camera animations in Anima.
|
|
30
|
+
* Access it via `scene.frame` or `scene.camera.frame`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Zoom in over 1 second
|
|
34
|
+
* this.play(this.frame.zoomIn(2).duration(1));
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Pan to center on an object
|
|
38
|
+
* this.play(this.frame.centerOn(circle).duration(0.5));
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Fit multiple objects in view
|
|
42
|
+
* this.play(this.frame.fitTo([obj1, obj2, obj3]).duration(1));
|
|
43
|
+
*/
|
|
44
|
+
export declare class CameraFrame extends Mobject {
|
|
45
|
+
private readonly baseWidth;
|
|
46
|
+
private readonly baseHeight;
|
|
47
|
+
private bounds?;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new CameraFrame with the specified viewport dimensions.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Configuration options
|
|
52
|
+
* @param config.pixelWidth - Width of the viewport in pixels (default: 1920)
|
|
53
|
+
* @param config.pixelHeight - Height of the viewport in pixels (default: 1080)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const frame = new CameraFrame({ pixelWidth: 1920, pixelHeight: 1080 });
|
|
57
|
+
*/
|
|
58
|
+
constructor(config?: CameraFrameConfig);
|
|
59
|
+
/**
|
|
60
|
+
* The current width of the frame in world units, accounting for scale.
|
|
61
|
+
* @returns The frame width multiplied by the current scale.x
|
|
62
|
+
*/
|
|
63
|
+
get width(): number;
|
|
64
|
+
/**
|
|
65
|
+
* The current height of the frame in world units, accounting for scale.
|
|
66
|
+
* @returns The frame height multiplied by the current scale.y
|
|
67
|
+
*/
|
|
68
|
+
get height(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the scale of the camera frame.
|
|
71
|
+
* Overrides Mobject.setScale to prevent zero or negative scales.
|
|
72
|
+
*
|
|
73
|
+
* @param sx - Scale factor for the x-axis (must be positive)
|
|
74
|
+
* @param sy - Scale factor for the y-axis (must be positive)
|
|
75
|
+
* @returns This CameraFrame for method chaining
|
|
76
|
+
* @throws Error if sx or sy is zero or negative
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* frame.setScale(2, 2); // Zoom out 2x
|
|
80
|
+
* frame.setScale(0.5, 0.5); // Zoom in 2x
|
|
81
|
+
*/
|
|
82
|
+
setScale(sx: number, sy: number): this;
|
|
83
|
+
/**
|
|
84
|
+
* Sets bounds that limit how far the camera can pan.
|
|
85
|
+
* When bounds are set, the camera position is clamped to stay within them,
|
|
86
|
+
* accounting for the frame size so edges don't go outside bounds.
|
|
87
|
+
*
|
|
88
|
+
* @param minX - Minimum x coordinate
|
|
89
|
+
* @param minY - Minimum y coordinate
|
|
90
|
+
* @param maxX - Maximum x coordinate
|
|
91
|
+
* @param maxY - Maximum y coordinate
|
|
92
|
+
* @returns This CameraFrame for method chaining
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Limit camera to a 100x100 world area
|
|
96
|
+
* frame.setBounds(0, 0, 100, 100);
|
|
97
|
+
*/
|
|
98
|
+
setBounds(minX: number, minY: number, maxX: number, maxY: number): this;
|
|
99
|
+
/**
|
|
100
|
+
* Removes any bounds restrictions on camera movement.
|
|
101
|
+
*
|
|
102
|
+
* @returns This CameraFrame for method chaining
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* frame.clearBounds(); // Camera can now pan freely
|
|
106
|
+
*/
|
|
107
|
+
clearBounds(): this;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if the camera has bounds set.
|
|
110
|
+
*
|
|
111
|
+
* @returns True if bounds are set, false otherwise
|
|
112
|
+
*/
|
|
113
|
+
hasBounds(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Gets the current bounds configuration.
|
|
116
|
+
*
|
|
117
|
+
* @returns The bounds object or undefined if no bounds are set
|
|
118
|
+
*/
|
|
119
|
+
getBounds(): Bounds | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Sets the position of the camera frame.
|
|
122
|
+
* Overrides Mobject.pos to clamp position within bounds if set.
|
|
123
|
+
*
|
|
124
|
+
* @param x - The x coordinate in world space
|
|
125
|
+
* @param y - The y coordinate in world space
|
|
126
|
+
* @returns This CameraFrame for method chaining
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* frame.pos(5, 3); // Move camera center to (5, 3)
|
|
130
|
+
*/
|
|
131
|
+
pos(x: number, y: number): this;
|
|
132
|
+
/**
|
|
133
|
+
* Smoothly zoom the camera in by the given factor.
|
|
134
|
+
* Internally scales the frame down, which makes objects appear larger.
|
|
135
|
+
*
|
|
136
|
+
* @param factor - Zoom multiplier. 2 = objects appear 2x larger (default: 2)
|
|
137
|
+
* @returns FluentAnimation that can be chained with .duration() and .ease()
|
|
138
|
+
* @throws Error if factor is zero or negative
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* // Zoom in 2x over 1 second
|
|
142
|
+
* this.play(this.frame.zoomIn(2).duration(1));
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Zoom in 3x with easing
|
|
146
|
+
* this.play(this.frame.zoomIn(3).duration(1.5).ease(easeInOutQuad));
|
|
147
|
+
*/
|
|
148
|
+
zoomIn(factor?: number): this & {
|
|
149
|
+
toAnimation(): Animation<Mobject>;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Smoothly zoom the camera out by the given factor.
|
|
153
|
+
* Internally scales the frame up, which makes objects appear smaller.
|
|
154
|
+
*
|
|
155
|
+
* @param factor - Zoom multiplier. 2 = objects appear 2x smaller (default: 2)
|
|
156
|
+
* @returns FluentAnimation that can be chained with .duration() and .ease()
|
|
157
|
+
* @throws Error if factor is zero or negative
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // Zoom out 2x over 1 second
|
|
161
|
+
* this.play(this.frame.zoomOut(2).duration(1));
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* // Zoom out to show more of the scene
|
|
165
|
+
* this.play(this.frame.zoomOut(4).duration(2).ease(easeOutCubic));
|
|
166
|
+
*/
|
|
167
|
+
zoomOut(factor?: number): this & {
|
|
168
|
+
toAnimation(): Animation<Mobject>;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Move the camera to center on a target Mobject.
|
|
172
|
+
* The camera will smoothly pan so the target is at the center of the frame.
|
|
173
|
+
*
|
|
174
|
+
* @param target - The Mobject to center on
|
|
175
|
+
* @returns FluentAnimation that can be chained with .duration() and .ease()
|
|
176
|
+
* @throws Error if target is null or undefined
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* // Center on a circle over 0.5 seconds
|
|
180
|
+
* this.play(this.frame.centerOn(circle).duration(0.5));
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* // Pan to focus on different objects in sequence
|
|
184
|
+
* await this.play(this.frame.centerOn(obj1).duration(1));
|
|
185
|
+
* await this.play(this.frame.centerOn(obj2).duration(1));
|
|
186
|
+
*/
|
|
187
|
+
centerOn(target: Mobject): this & {
|
|
188
|
+
toAnimation(): Animation<Mobject>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Zoom in/out while keeping a specific world point fixed on screen.
|
|
192
|
+
* Like pinch-to-zoom behavior where the pinch point stays stationary.
|
|
193
|
+
*
|
|
194
|
+
* Uses the formula: C' = P * (1 - factor) + C * factor
|
|
195
|
+
* Where P = point, C = current center, factor = zoom factor.
|
|
196
|
+
*
|
|
197
|
+
* @param factor - Scale multiplier. Less than 1 for zoom in, greater than 1 for zoom out
|
|
198
|
+
* @param point - World coordinates to keep fixed on screen
|
|
199
|
+
* @returns Parallel animation combining move and scale
|
|
200
|
+
* @throws Error if factor is zero or negative
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* // Zoom in 2x on a specific point
|
|
204
|
+
* this.play(frame.zoomToPoint(0.5, { x: 5, y: 5 }).duration(1));
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* // Zoom out while keeping an object's position fixed
|
|
208
|
+
* this.play(frame.zoomToPoint(2, circle.position).duration(1));
|
|
209
|
+
*/
|
|
210
|
+
zoomToPoint(factor: number, point: {
|
|
211
|
+
x: number;
|
|
212
|
+
y: number;
|
|
213
|
+
}): Parallel;
|
|
214
|
+
/**
|
|
215
|
+
* Automatically frame one or more objects with optional margin.
|
|
216
|
+
* Calculates the bounding box of all targets and animates the camera
|
|
217
|
+
* to show them all with the specified margin around them.
|
|
218
|
+
*
|
|
219
|
+
* @param targets - Single Mobject or array of Mobjects to frame
|
|
220
|
+
* @param margin - Padding around the objects in world units (default: 0.5)
|
|
221
|
+
* @returns FluentAnimation that can be chained with .duration() and .ease()
|
|
222
|
+
* @throws Error if targets array is empty
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* // Fit a single object with default margin
|
|
226
|
+
* this.play(this.frame.fitTo(circle).duration(1));
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* // Fit multiple objects with custom margin
|
|
230
|
+
* this.play(this.frame.fitTo([obj1, obj2, obj3], 1.0).duration(1.5));
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* // Show all objects in the scene
|
|
234
|
+
* this.play(this.frame.fitTo(allObjects, 0).duration(2));
|
|
235
|
+
*/
|
|
236
|
+
fitTo(targets: Mobject | Mobject[], margin?: number): this & {
|
|
237
|
+
toAnimation(): Animation<Mobject>;
|
|
238
|
+
};
|
|
239
|
+
private calculateBounds;
|
|
240
|
+
private hasGetBoundingBox;
|
|
241
|
+
}
|
|
242
|
+
export {};
|