manim-web 0.26.0 → 0.28.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/animation/text/index.d.ts +2 -0
- package/dist/animation/text/index.d.ts.map +1 -0
- package/dist/animation/text/kineticTypography.d.ts +144 -0
- package/dist/animation/text/kineticTypography.d.ts.map +1 -0
- package/dist/audio/MidiInput.d.ts +159 -0
- package/dist/audio/MidiInput.d.ts.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/integrations/notebook.d.ts +117 -0
- package/dist/integrations/notebook.d.ts.map +1 -0
- package/dist/integrations/notebook.js +60 -0
- package/dist/integrations/react.js +17 -17
- package/dist/integrations/vue.js +16 -16
- package/dist/manim-web.browser.js +9117 -7786
- package/dist/mobjects/graphing/GanttChart.d.ts +179 -0
- package/dist/mobjects/graphing/GanttChart.d.ts.map +1 -0
- package/dist/mobjects/graphing/ganttLayout.d.ts +36 -0
- package/dist/mobjects/graphing/ganttLayout.d.ts.map +1 -0
- package/dist/mobjects/graphing/index.d.ts +1 -0
- package/dist/mobjects/graphing/index.d.ts.map +1 -1
- package/dist/mobjects/ml/ConvolutionalLayer.d.ts +19 -0
- package/dist/mobjects/ml/ConvolutionalLayer.d.ts.map +1 -0
- package/dist/mobjects/ml/EdgePulse.d.ts +30 -0
- package/dist/mobjects/ml/EdgePulse.d.ts.map +1 -0
- package/dist/mobjects/ml/FeedForwardLayer.d.ts +31 -0
- package/dist/mobjects/ml/FeedForwardLayer.d.ts.map +1 -0
- package/dist/mobjects/ml/ImageLayer.d.ts +29 -0
- package/dist/mobjects/ml/ImageLayer.d.ts.map +1 -0
- package/dist/mobjects/ml/NeuralNetwork.d.ts +69 -0
- package/dist/mobjects/ml/NeuralNetwork.d.ts.map +1 -0
- package/dist/mobjects/ml/NeuralNetworkLayer.d.ts +54 -0
- package/dist/mobjects/ml/NeuralNetworkLayer.d.ts.map +1 -0
- package/dist/mobjects/ml/PoolingLayer.d.ts +19 -0
- package/dist/mobjects/ml/PoolingLayer.d.ts.map +1 -0
- package/dist/mobjects/ml/featureMapStack.d.ts +25 -0
- package/dist/mobjects/ml/featureMapStack.d.ts.map +1 -0
- package/dist/mobjects/ml/forwardPass.d.ts +28 -0
- package/dist/mobjects/ml/forwardPass.d.ts.map +1 -0
- package/dist/mobjects/ml/index.d.ts +18 -0
- package/dist/mobjects/ml/index.d.ts.map +1 -0
- package/dist/mobjects/ml/mlStyles.d.ts +52 -0
- package/dist/mobjects/ml/mlStyles.d.ts.map +1 -0
- package/dist/mobjects/physics/PhysicsWorld.d.ts +83 -0
- package/dist/mobjects/physics/PhysicsWorld.d.ts.map +1 -0
- package/dist/mobjects/physics/bodies.d.ts +91 -0
- package/dist/mobjects/physics/bodies.d.ts.map +1 -0
- package/dist/mobjects/physics/builders.d.ts +59 -0
- package/dist/mobjects/physics/builders.d.ts.map +1 -0
- package/dist/mobjects/physics/collisions.d.ts +29 -0
- package/dist/mobjects/physics/collisions.d.ts.map +1 -0
- package/dist/mobjects/physics/constraints.d.ts +67 -0
- package/dist/mobjects/physics/constraints.d.ts.map +1 -0
- package/dist/mobjects/physics/index.d.ts +13 -0
- package/dist/mobjects/physics/index.d.ts.map +1 -0
- package/dist/mobjects/physics/vec2.d.ts +17 -0
- package/dist/mobjects/physics/vec2.d.ts.map +1 -0
- package/dist/mobjects/shader/ShaderMobject.d.ts +105 -0
- package/dist/mobjects/shader/ShaderMobject.d.ts.map +1 -0
- package/dist/mobjects/shader/index.d.ts +2 -0
- package/dist/mobjects/shader/index.d.ts.map +1 -0
- package/dist/mobjects/sketch/index.d.ts +5 -0
- package/dist/mobjects/sketch/index.d.ts.map +1 -0
- package/dist/mobjects/sketch/sketch.d.ts +30 -0
- package/dist/mobjects/sketch/sketch.d.ts.map +1 -0
- package/dist/{src-B2lipHn1.js → src-D7e_dgYz.js} +3340 -2009
- package/package.json +6 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared style options and defaults for the neural-network diagram toolkit.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces describe how nodes (circles, feature maps, grids) and the
|
|
5
|
+
* connection lines between layers look. Every field is optional; the layer and
|
|
6
|
+
* network classes fill the gaps from the DEFAULT_* records below.
|
|
7
|
+
*/
|
|
8
|
+
/** Visual style for a single node (a circle, a feature-map square, a grid). */
|
|
9
|
+
export interface NodeStyleOptions {
|
|
10
|
+
/** Stroke color as a CSS color string. */
|
|
11
|
+
color?: string;
|
|
12
|
+
/** Fill color as a CSS color string. Defaults to `color`. */
|
|
13
|
+
fillColor?: string;
|
|
14
|
+
/** Fill opacity from 0 to 1. */
|
|
15
|
+
fillOpacity?: number;
|
|
16
|
+
/** Stroke width in pixels. */
|
|
17
|
+
strokeWidth?: number;
|
|
18
|
+
}
|
|
19
|
+
/** Visual style for a connection line (an edge) between two nodes. */
|
|
20
|
+
export interface ConnectionStyleOptions {
|
|
21
|
+
/** Stroke color as a CSS color string. */
|
|
22
|
+
color?: string;
|
|
23
|
+
/** Stroke width in pixels. */
|
|
24
|
+
strokeWidth?: number;
|
|
25
|
+
/** Resting stroke opacity from 0 to 1, before a forward pass activates it. */
|
|
26
|
+
opacity?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Fully resolved node style (no optional fields). */
|
|
29
|
+
export type ResolvedNodeStyle = Required<NodeStyleOptions>;
|
|
30
|
+
/** Fully resolved edge style (no optional fields). */
|
|
31
|
+
export type ResolvedEdgeStyle = Required<ConnectionStyleOptions>;
|
|
32
|
+
/** Default node style: a blue outline with a faint blue fill. */
|
|
33
|
+
export declare const DEFAULT_NODE_STYLE: ResolvedNodeStyle;
|
|
34
|
+
/** Default edge style: a thin grey line at a low resting opacity. */
|
|
35
|
+
export declare const DEFAULT_EDGE_STYLE: ResolvedEdgeStyle;
|
|
36
|
+
/** Default color a connection takes while a signal flows through it. */
|
|
37
|
+
export declare const DEFAULT_ACTIVATION_COLOR = "#FFFFFF";
|
|
38
|
+
/**
|
|
39
|
+
* Merge a partial node style over a resolved base style.
|
|
40
|
+
* @param base - The resolved style to start from.
|
|
41
|
+
* @param override - The partial style whose set fields win.
|
|
42
|
+
* @returns A new resolved node style.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveNodeStyle(base: ResolvedNodeStyle, override?: NodeStyleOptions): ResolvedNodeStyle;
|
|
45
|
+
/**
|
|
46
|
+
* Merge a partial edge style over a resolved base style.
|
|
47
|
+
* @param base - The resolved style to start from.
|
|
48
|
+
* @param override - The partial style whose set fields win.
|
|
49
|
+
* @returns A new resolved edge style.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveEdgeStyle(base: ResolvedEdgeStyle, override?: ConnectionStyleOptions): ResolvedEdgeStyle;
|
|
52
|
+
//# sourceMappingURL=mlStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mlStyles.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/mlStyles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,sEAAsE;AACtE,MAAM,WAAW,sBAAsB;IACrC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAE3D,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AAEjE,iEAAiE;AACjE,eAAO,MAAM,kBAAkB,EAAE,iBAKhC,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,EAAE,iBAIhC,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,YAAQ,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,iBAAiB,EACvB,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,iBAAiB,CAEnB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,iBAAiB,EACvB,QAAQ,CAAC,EAAE,sBAAsB,GAChC,iBAAiB,CAEnB"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Group } from '../../core/Group';
|
|
2
|
+
import { Body, BodyOptions } from './bodies';
|
|
3
|
+
import { Constraint } from './constraints';
|
|
4
|
+
import { Bounds } from './collisions';
|
|
5
|
+
import { Vec2 } from './vec2';
|
|
6
|
+
/** Options for a {@link PhysicsWorld}. */
|
|
7
|
+
export interface PhysicsWorldOptions {
|
|
8
|
+
/** Global acceleration `[x, y]` in units/sec^2. Default: `[0, -9.8]`. */
|
|
9
|
+
gravity?: Vec2;
|
|
10
|
+
/** World bounds for wall collisions. Default: open on every side. */
|
|
11
|
+
bounds?: Bounds;
|
|
12
|
+
/** Constraint position-solver iterations per step. Default: 4. */
|
|
13
|
+
iterations?: number;
|
|
14
|
+
/** Seed for the deterministic PRNG. Default: 0. */
|
|
15
|
+
seed?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A 2D rigid-body physics world. See the file overview for the model and an
|
|
19
|
+
* example.
|
|
20
|
+
*/
|
|
21
|
+
export declare class PhysicsWorld extends Group {
|
|
22
|
+
private readonly _bodies;
|
|
23
|
+
private readonly _constraints;
|
|
24
|
+
private _gravity;
|
|
25
|
+
private _bounds;
|
|
26
|
+
private readonly _iterations;
|
|
27
|
+
private _seed;
|
|
28
|
+
private _rng;
|
|
29
|
+
constructor(options?: PhysicsWorldOptions);
|
|
30
|
+
/** The seed that drives the deterministic PRNG. */
|
|
31
|
+
get seed(): number;
|
|
32
|
+
/** The current global gravity `[x, y]`. */
|
|
33
|
+
getGravity(): Vec2;
|
|
34
|
+
/** Set the global gravity `[x, y]`. */
|
|
35
|
+
setGravity(gravity: Vec2): this;
|
|
36
|
+
/** Set the world bounds for wall collisions. */
|
|
37
|
+
setBounds(bounds: Bounds): this;
|
|
38
|
+
/** The next deterministic random float in `[0, 1)`. */
|
|
39
|
+
random(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Add a body to the world. Accepts a {@link Body} or plain options. If the
|
|
42
|
+
* body carries a mobject, it is added as a child so the scene renders it.
|
|
43
|
+
*
|
|
44
|
+
* @returns The body that was added, for building constraints.
|
|
45
|
+
*/
|
|
46
|
+
addBody(bodyOrOptions: Body | BodyOptions): Body;
|
|
47
|
+
/** Add a constraint to the world. @returns The constraint, for chaining. */
|
|
48
|
+
addConstraint<T extends Constraint>(constraint: T): T;
|
|
49
|
+
/** All bodies, in insertion order. The array is a copy; the bodies are live. */
|
|
50
|
+
getBodies(): Body[];
|
|
51
|
+
/** The body at `index`, or undefined. */
|
|
52
|
+
getBody(index: number): Body | undefined;
|
|
53
|
+
/** All constraints, in insertion order. The array is a copy. */
|
|
54
|
+
getConstraints(): Constraint[];
|
|
55
|
+
/**
|
|
56
|
+
* Advance the simulation by `dt` seconds with semi-implicit Euler:
|
|
57
|
+
* accumulate forces, integrate velocity then position, solve constraint
|
|
58
|
+
* positions, resolve collisions, and move the attached mobjects.
|
|
59
|
+
*
|
|
60
|
+
* @param dt - Elapsed time in seconds. Values <= 0 are ignored.
|
|
61
|
+
*/
|
|
62
|
+
step(dt: number): this;
|
|
63
|
+
/** Add gravity and spring forces to every body for this step. */
|
|
64
|
+
private _accumulateForces;
|
|
65
|
+
/** Semi-implicit Euler: velocity from force, then position from velocity. */
|
|
66
|
+
private _integrate;
|
|
67
|
+
/** Run the position solver for each constraint, several iterations. */
|
|
68
|
+
private _solveConstraints;
|
|
69
|
+
/** Resolve every body against the bounds and every circle pair. */
|
|
70
|
+
private _resolveCollisions;
|
|
71
|
+
/** Move each attached mobject to its body position, keeping its z. */
|
|
72
|
+
private _syncMobjects;
|
|
73
|
+
/**
|
|
74
|
+
* Restore every body to its initial state and restart the PRNG from the
|
|
75
|
+
* seed. After a reset, the same sequence of {@link step} calls reproduces
|
|
76
|
+
* the same evolution.
|
|
77
|
+
*/
|
|
78
|
+
reset(): this;
|
|
79
|
+
copy(): PhysicsWorld;
|
|
80
|
+
/** Build a new body with the same state and a copied mobject. */
|
|
81
|
+
private _cloneBody;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=PhysicsWorld.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhysicsWorld.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/PhysicsWorld.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAsC,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAiB9B,0CAA0C;AAC1C,MAAM,WAAW,mBAAmB;IAClC,yEAAyE;IACzE,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoB;IACjD,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAe;gBAEf,OAAO,GAAE,mBAAwB;IAa7C,mDAAmD;IACnD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,2CAA2C;IAC3C,UAAU,IAAI,IAAI;IAIlB,uCAAuC;IACvC,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI;IAK/B,gDAAgD;IAChD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,uDAAuD;IACvD,MAAM,IAAI,MAAM;IAIhB;;;;;OAKG;IACH,OAAO,CAAC,aAAa,EAAE,IAAI,GAAG,WAAW,GAAG,IAAI;IAOhD,4EAA4E;IAC5E,aAAa,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC;IAKrD,gFAAgF;IAChF,SAAS,IAAI,IAAI,EAAE;IAInB,yCAAyC;IACzC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIxC,gEAAgE;IAChE,cAAc,IAAI,UAAU,EAAE;IAI9B;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAUtB,iEAAiE;IACjE,OAAO,CAAC,iBAAiB;IAWzB,6EAA6E;IAC7E,OAAO,CAAC,UAAU;IAgBlB,uEAAuE;IACvE,OAAO,CAAC,iBAAiB;IAQzB,mEAAmE;IACnE,OAAO,CAAC,kBAAkB;IAW1B,sEAAsE;IACtE,OAAO,CAAC,aAAa;IAQrB;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAOJ,IAAI,IAAI,YAAY;IAmB7B,iEAAiE;IACjE,OAAO,CAAC,UAAU;CAoBnB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Mobject } from '../../core/Mobject';
|
|
2
|
+
import { Vec2 } from './vec2';
|
|
3
|
+
/** A circle shape with a radius, centered on the body position. */
|
|
4
|
+
export interface CircleShape {
|
|
5
|
+
kind: 'circle';
|
|
6
|
+
/** Radius in scene units. */
|
|
7
|
+
radius: number;
|
|
8
|
+
}
|
|
9
|
+
/** A convex polygon shape, as vertices relative to the body position. */
|
|
10
|
+
export interface PolygonShape {
|
|
11
|
+
kind: 'polygon';
|
|
12
|
+
/** Vertices in local space, measured from the body position. */
|
|
13
|
+
vertices: Vec2[];
|
|
14
|
+
}
|
|
15
|
+
/** The collision shape of a {@link Body}. */
|
|
16
|
+
export type BodyShape = CircleShape | PolygonShape;
|
|
17
|
+
/** Options for {@link Body}. */
|
|
18
|
+
export interface BodyOptions {
|
|
19
|
+
/** Start position `[x, y]`. Default: `[0, 0]`. */
|
|
20
|
+
position?: Vec2;
|
|
21
|
+
/** Start velocity `[x, y]` in units/sec. Default: `[0, 0]`. */
|
|
22
|
+
velocity?: Vec2;
|
|
23
|
+
/** Mass in arbitrary units. Ignored when `isStatic` is true. Default: 1. */
|
|
24
|
+
mass?: number;
|
|
25
|
+
/** Bounciness from 0 (no bounce) to 1 (elastic). Default: 0.5. */
|
|
26
|
+
restitution?: number;
|
|
27
|
+
/** A static body never moves and has infinite mass. Default: false. */
|
|
28
|
+
isStatic?: boolean;
|
|
29
|
+
/** Collision shape. Default: a circle of radius 0.5. */
|
|
30
|
+
shape?: BodyShape;
|
|
31
|
+
/**
|
|
32
|
+
* Scale on the world gravity for this body, so a body can ignore gravity
|
|
33
|
+
* (0) or feel more or less than the rest. Default: 1.
|
|
34
|
+
*/
|
|
35
|
+
gravityScale?: number;
|
|
36
|
+
/** A mobject to move to the body position on each step. Default: none. */
|
|
37
|
+
mobject?: Mobject;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A rigid body in the physics world.
|
|
41
|
+
*
|
|
42
|
+
* The body is the single source of truth for its motion. An attached mobject
|
|
43
|
+
* follows the body, never the other way around.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const ball = new Body({
|
|
48
|
+
* position: [0, 3],
|
|
49
|
+
* shape: { kind: 'circle', radius: 0.2 },
|
|
50
|
+
* restitution: 0.8,
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare class Body {
|
|
55
|
+
/** Current position `[x, y]`. */
|
|
56
|
+
position: Vec2;
|
|
57
|
+
/** Current velocity `[x, y]` in units/sec. */
|
|
58
|
+
velocity: Vec2;
|
|
59
|
+
/** Force accumulator for the current step, cleared after integration. */
|
|
60
|
+
force: Vec2;
|
|
61
|
+
/** Mass in arbitrary units. A static body reports `Infinity`. */
|
|
62
|
+
readonly mass: number;
|
|
63
|
+
/** Inverse mass. Zero for a static body, which disables all motion. */
|
|
64
|
+
readonly invMass: number;
|
|
65
|
+
/** Bounciness from 0 to 1. */
|
|
66
|
+
readonly restitution: number;
|
|
67
|
+
/** Whether the body is static (never moves). */
|
|
68
|
+
readonly isStatic: boolean;
|
|
69
|
+
/** The collision shape. */
|
|
70
|
+
readonly shape: BodyShape;
|
|
71
|
+
/** Per-body scale on the world gravity. */
|
|
72
|
+
readonly gravityScale: number;
|
|
73
|
+
/** The attached mobject, or null. */
|
|
74
|
+
mobject: Mobject | null;
|
|
75
|
+
/** The z of the attached mobject at attach time, kept on every move. */
|
|
76
|
+
readonly z: number;
|
|
77
|
+
private readonly _initial;
|
|
78
|
+
constructor(options?: BodyOptions);
|
|
79
|
+
/** The circle radius, or 0 for a polygon body. */
|
|
80
|
+
get radius(): number;
|
|
81
|
+
/** Add a force `[x, y]` to the accumulator for the current step. */
|
|
82
|
+
applyForce(f: Vec2): this;
|
|
83
|
+
/**
|
|
84
|
+
* The axis-aligned bounds as `[minX, minY, maxX, maxY]` in world space.
|
|
85
|
+
* A circle uses its radius; a polygon uses its vertex extent.
|
|
86
|
+
*/
|
|
87
|
+
aabb(): [number, number, number, number];
|
|
88
|
+
/** Restore the position and velocity recorded when the body was created. */
|
|
89
|
+
reset(): this;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=bodies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodies.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/bodies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAa,MAAM,QAAQ,CAAC;AAEzC,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,gEAAgE;IAChE,QAAQ,EAAE,IAAI,EAAE,CAAC;CAClB;AAED,6CAA6C;AAC7C,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,YAAY,CAAC;AAEnD,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAQD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,IAAI;IACf,iCAAiC;IACjC,QAAQ,EAAE,IAAI,CAAC;IACf,8CAA8C;IAC9C,QAAQ,EAAE,IAAI,CAAC;IACf,yEAAyE;IACzE,KAAK,EAAE,IAAI,CAAU;IACrB,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,qCAAqC;IACrC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,OAAO,GAAE,WAAgB;IA8BrC,kDAAkD;IAClD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,oEAAoE;IACpE,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI;IAMzB;;;OAGG;IACH,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAyBxC,4EAA4E;IAC5E,KAAK,IAAI,IAAI;CAMd"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Mobject } from '../../core/Mobject';
|
|
2
|
+
import { PhysicsWorld } from './PhysicsWorld';
|
|
3
|
+
import { Vec2 } from './vec2';
|
|
4
|
+
/** Options for {@link pendulum}. */
|
|
5
|
+
export interface PendulumOptions {
|
|
6
|
+
/** Fixed pivot point `[x, y]`. Default: `[0, 2]`. */
|
|
7
|
+
pivot?: Vec2;
|
|
8
|
+
/** Rod length from the pivot to the bob. Default: 2. */
|
|
9
|
+
length?: number;
|
|
10
|
+
/** Bob mass. Default: 1. */
|
|
11
|
+
mass?: number;
|
|
12
|
+
/** Start angle in radians from straight down. Default: `Math.PI / 4`. */
|
|
13
|
+
angle?: number;
|
|
14
|
+
/** Bob radius. Default: 0.2. */
|
|
15
|
+
radius?: number;
|
|
16
|
+
/** Gravity `[x, y]`. Default: `[0, -9.8]`. */
|
|
17
|
+
gravity?: Vec2;
|
|
18
|
+
/** Mobject to attach to the bob. Default: none. */
|
|
19
|
+
bob?: Mobject;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build a pendulum: a bob body pinned to a fixed pivot by a rigid distance
|
|
23
|
+
* constraint. The bob starts at `angle` from straight down and swings under
|
|
24
|
+
* gravity while the constraint holds it a near-constant `length` from the
|
|
25
|
+
* pivot.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pendulum(options?: PendulumOptions): PhysicsWorld;
|
|
28
|
+
/** Options for {@link springChain}. */
|
|
29
|
+
export interface SpringChainOptions {
|
|
30
|
+
/** First link position `[x, y]`. Default: `[0, 3]`. */
|
|
31
|
+
start?: Vec2;
|
|
32
|
+
/** Number of bodies in the chain. Default: 4. */
|
|
33
|
+
count?: number;
|
|
34
|
+
/** Rest length between neighboring links. Default: 1. */
|
|
35
|
+
spacing?: number;
|
|
36
|
+
/** Mass of each body. Default: 1. */
|
|
37
|
+
mass?: number;
|
|
38
|
+
/** Spring stiffness. Default: 40. */
|
|
39
|
+
stiffness?: number;
|
|
40
|
+
/** Spring damping. Default: 2. */
|
|
41
|
+
damping?: number;
|
|
42
|
+
/** Gravity `[x, y]`. Default: `[0, -9.8]`. */
|
|
43
|
+
gravity?: Vec2;
|
|
44
|
+
/** Pin the first link to a fixed anchor at `start`. Default: true. */
|
|
45
|
+
anchored?: boolean;
|
|
46
|
+
/** Seeded horizontal jitter on the start positions. Default: 0. */
|
|
47
|
+
jitter?: number;
|
|
48
|
+
/** Seed for the jitter PRNG. Default: 0. */
|
|
49
|
+
seed?: number;
|
|
50
|
+
/** Mobjects to attach to the links, in order. Default: none. */
|
|
51
|
+
mobjects?: Mobject[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build a vertical chain of bodies linked by springs, hanging downward from
|
|
55
|
+
* `start`. With `anchored`, the top link is pinned to a fixed point, so the
|
|
56
|
+
* chain hangs and sways; without it, the whole chain is free.
|
|
57
|
+
*/
|
|
58
|
+
export declare function springChain(options?: SpringChainOptions): PhysicsWorld;
|
|
59
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,mDAAmD;IACnD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,YAAY,CAqBpE;AAED,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,sEAAsE;IACtE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,YAAY,CAyC1E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Body } from './bodies';
|
|
2
|
+
/**
|
|
3
|
+
* The rectangular bounds of the world. Any side left `undefined` is open, so
|
|
4
|
+
* a body passes through it freely.
|
|
5
|
+
*/
|
|
6
|
+
export interface Bounds {
|
|
7
|
+
/** Left wall x, or undefined for an open left side. */
|
|
8
|
+
minX?: number;
|
|
9
|
+
/** Floor y, or undefined for an open bottom. */
|
|
10
|
+
minY?: number;
|
|
11
|
+
/** Right wall x, or undefined for an open right side. */
|
|
12
|
+
maxX?: number;
|
|
13
|
+
/** Ceiling y, or undefined for an open top. */
|
|
14
|
+
maxY?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Push `body` back inside `bounds` and reflect the velocity that drove it out,
|
|
18
|
+
* scaled by the body restitution. A static body is never moved.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveBounds(body: Body, bounds: Bounds): void;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a collision between two circle bodies. Does nothing when either body
|
|
23
|
+
* is not a circle, when they do not overlap, or when both are static.
|
|
24
|
+
*
|
|
25
|
+
* The step separates the overlap by inverse mass, then applies an impulse
|
|
26
|
+
* along the contact normal with restitution `min(a, b)`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveCircleCircle(a: Body, b: Body): void;
|
|
29
|
+
//# sourceMappingURL=collisions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collisions.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/collisions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAqB9D;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAgC1D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Body } from './bodies';
|
|
2
|
+
import { Vec2 } from './vec2';
|
|
3
|
+
/** A constraint endpoint: a dynamic body or a fixed world point. */
|
|
4
|
+
export type Anchor = Body | Vec2;
|
|
5
|
+
/**
|
|
6
|
+
* A constraint on the physics world.
|
|
7
|
+
*
|
|
8
|
+
* The world runs two phases each step. It calls {@link accumulateForces} in
|
|
9
|
+
* the force phase (before integration) and {@link solvePositions} in the
|
|
10
|
+
* position phase (after integration). A constraint implements only the phase
|
|
11
|
+
* it needs.
|
|
12
|
+
*/
|
|
13
|
+
export interface Constraint {
|
|
14
|
+
/** Add forces to the linked bodies before integration. Optional. */
|
|
15
|
+
accumulateForces?(): void;
|
|
16
|
+
/** Correct the linked body positions after integration. Optional. */
|
|
17
|
+
solvePositions?(): void;
|
|
18
|
+
/** Return a copy of this constraint with bodies remapped through `map`. */
|
|
19
|
+
clone(map: Map<Body, Body>): Constraint;
|
|
20
|
+
}
|
|
21
|
+
/** Options for a {@link DistanceConstraint}. */
|
|
22
|
+
export interface DistanceConstraintOptions {
|
|
23
|
+
/** How strongly the constraint corrects, from 0 to 1. Default: 1. */
|
|
24
|
+
stiffness?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A rigid distance constraint. It keeps endpoint `a` and endpoint `b` a fixed
|
|
28
|
+
* `length` apart by correcting positions after integration. The correction
|
|
29
|
+
* splits between the endpoints by inverse mass, so a body pinned to a fixed
|
|
30
|
+
* point moves alone.
|
|
31
|
+
*/
|
|
32
|
+
export declare class DistanceConstraint implements Constraint {
|
|
33
|
+
private readonly _a;
|
|
34
|
+
private readonly _b;
|
|
35
|
+
private readonly _length;
|
|
36
|
+
private readonly _stiffness;
|
|
37
|
+
constructor(a: Anchor, b: Anchor, length: number, options?: DistanceConstraintOptions);
|
|
38
|
+
/** The target distance between the endpoints. */
|
|
39
|
+
get length(): number;
|
|
40
|
+
solvePositions(): void;
|
|
41
|
+
clone(map: Map<Body, Body>): DistanceConstraint;
|
|
42
|
+
}
|
|
43
|
+
/** Options for a {@link SpringConstraint}. */
|
|
44
|
+
export interface SpringConstraintOptions {
|
|
45
|
+
/** Spring stiffness (Hooke's constant). Default: 10. */
|
|
46
|
+
stiffness?: number;
|
|
47
|
+
/** Damping on the relative velocity along the spring. Default: 0. */
|
|
48
|
+
damping?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A spring between two endpoints. It applies a Hooke's-law force toward the
|
|
52
|
+
* rest length, plus optional damping on the closing speed, during the force
|
|
53
|
+
* phase. The endpoints oscillate around the rest length.
|
|
54
|
+
*/
|
|
55
|
+
export declare class SpringConstraint implements Constraint {
|
|
56
|
+
private readonly _a;
|
|
57
|
+
private readonly _b;
|
|
58
|
+
private readonly _restLength;
|
|
59
|
+
private readonly _stiffness;
|
|
60
|
+
private readonly _damping;
|
|
61
|
+
constructor(a: Anchor, b: Anchor, restLength: number, options?: SpringConstraintOptions);
|
|
62
|
+
/** The rest length the spring pulls toward. */
|
|
63
|
+
get restLength(): number;
|
|
64
|
+
accumulateForces(): void;
|
|
65
|
+
clone(map: Map<Body, Body>): SpringConstraint;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/constraints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,IAAI,EAAyB,MAAM,QAAQ,CAAC;AAErD,oEAAoE;AACpE,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,WAAW,UAAU;IACzB,oEAAoE;IACpE,gBAAgB,CAAC,IAAI,IAAI,CAAC;IAC1B,qEAAqE;IACrE,cAAc,CAAC,IAAI,IAAI,CAAC;IACxB,2EAA2E;IAC3E,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC;CACzC;AAyBD,gDAAgD;AAChD,MAAM,WAAW,yBAAyB;IACxC,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,yBAA8B;IAOzF,iDAAiD;IACjD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,cAAc,IAAI,IAAI;IA6BtB,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,kBAAkB;CAUhD;AAED,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;IAQ3F,+CAA+C;IAC/C,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,gBAAgB,IAAI,IAAI;IAyBxB,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,gBAAgB;CAW9C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2D rigid-body physics: a compact, self-contained solver for gravity,
|
|
3
|
+
* collisions, springs and pendulums. Bodies attach to repo mobjects (Circle,
|
|
4
|
+
* Dot, Polygon) and move under the simulation, driven by an updater like
|
|
5
|
+
* {@link ParticleSystem}. The simulation is deterministic from a seed.
|
|
6
|
+
*/
|
|
7
|
+
export { PhysicsWorld, type PhysicsWorldOptions } from './PhysicsWorld';
|
|
8
|
+
export { Body, type BodyOptions, type BodyShape, type CircleShape, type PolygonShape, } from './bodies';
|
|
9
|
+
export { type Constraint, type Anchor, DistanceConstraint, type DistanceConstraintOptions, SpringConstraint, type SpringConstraintOptions, } from './constraints';
|
|
10
|
+
export { type Bounds, resolveBounds, resolveCircleCircle } from './collisions';
|
|
11
|
+
export { pendulum, type PendulumOptions, springChain, type SpringChainOptions } from './builders';
|
|
12
|
+
export type { Vec2 } from './vec2';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EACL,IAAI,EACJ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,YAAY,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,MAAM,EACX,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClG,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal 2D vector helpers for the self-contained physics solver.
|
|
3
|
+
*
|
|
4
|
+
* The physics world runs in the XY plane. A {@link Vec2} is a plain `[x, y]`
|
|
5
|
+
* tuple, so it stays cheap to copy and compare in tests. Every helper is pure
|
|
6
|
+
* and returns a new value, which keeps the solver deterministic and easy to
|
|
7
|
+
* reason about.
|
|
8
|
+
*/
|
|
9
|
+
/** A 2D vector or point as an `[x, y]` tuple. */
|
|
10
|
+
export type Vec2 = [number, number];
|
|
11
|
+
/** Return a fresh copy of `v`. */
|
|
12
|
+
export declare function cloneVec2(v: Vec2): Vec2;
|
|
13
|
+
/** Return the dot product `a . b`. */
|
|
14
|
+
export declare function dotVec2(a: Vec2, b: Vec2): number;
|
|
15
|
+
/** Return the distance between points `a` and `b`. */
|
|
16
|
+
export declare function distanceVec2(a: Vec2, b: Vec2): number;
|
|
17
|
+
//# sourceMappingURL=vec2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vec2.d.ts","sourceRoot":"","sources":["../../../src/mobjects/physics/vec2.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iDAAiD;AACjD,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpC,kCAAkC;AAClC,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAEvC;AAED,sCAAsC;AACtC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAEhD;AAED,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Mobject } from '../../core/Mobject';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
/**
|
|
4
|
+
* Allowed value types for a ShaderMobject uniform.
|
|
5
|
+
*
|
|
6
|
+
* Floats map to GLSL `float`, vectors to `vecN`, `THREE.Color` to a `vec3`
|
|
7
|
+
* (THREE uploads its `.r/.g/.b`), `THREE.Texture` to a `sampler2D`, and a
|
|
8
|
+
* plain number array to the matching `vecN`/array uniform.
|
|
9
|
+
*/
|
|
10
|
+
export type ShaderUniformValue = number | boolean | THREE.Vector2 | THREE.Vector3 | THREE.Vector4 | THREE.Color | THREE.Texture | readonly number[];
|
|
11
|
+
/**
|
|
12
|
+
* Options for a {@link ShaderMobject}.
|
|
13
|
+
*/
|
|
14
|
+
export interface ShaderMobjectOptions {
|
|
15
|
+
/** The GLSL fragment shader source. Required. */
|
|
16
|
+
fragmentShader: string;
|
|
17
|
+
/** The GLSL vertex shader source. Default: a pass-through that exposes `vUv`. */
|
|
18
|
+
vertexShader?: string;
|
|
19
|
+
/** Plane width in world units. Default: 8 */
|
|
20
|
+
width?: number;
|
|
21
|
+
/** Plane height in world units. Default: 4.5 */
|
|
22
|
+
height?: number;
|
|
23
|
+
/** User-defined uniforms, keyed by GLSL name. */
|
|
24
|
+
uniforms?: Record<string, ShaderUniformValue>;
|
|
25
|
+
/** Expose the Shadertoy-style `iMouse` (vec4) uniform. Default: false */
|
|
26
|
+
mouse?: boolean;
|
|
27
|
+
/** Blending mode. Default: THREE.NormalBlending */
|
|
28
|
+
blending?: THREE.Blending;
|
|
29
|
+
/** Enable transparency. Default: true */
|
|
30
|
+
transparent?: boolean;
|
|
31
|
+
/** Opacity, stored on the mobject. Default: 1 */
|
|
32
|
+
opacity?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* ShaderMobject -- a plane rendered with a user-supplied GLSL fragment shader.
|
|
36
|
+
*
|
|
37
|
+
* It mirrors the Shadertoy convention with built-in uniforms updated each
|
|
38
|
+
* frame: `iTime` (seconds), `iResolution` (vec3 plane size), and an optional
|
|
39
|
+
* `iMouse` (vec4). User uniforms (floats, vectors, colors, textures) pass
|
|
40
|
+
* through an options map. A frame updater advances `iTime`, so animated
|
|
41
|
+
* shaders run on the timeline.
|
|
42
|
+
*
|
|
43
|
+
* Construction never touches a WebGL context, so it is headless-safe; the
|
|
44
|
+
* material is built lazily on the first {@link getThreeObject} call. Uniform
|
|
45
|
+
* and time updates made before that point are stored and applied on build.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const shader = new ShaderMobject({
|
|
50
|
+
* fragmentShader: `
|
|
51
|
+
* precision highp float;
|
|
52
|
+
* uniform float iTime;
|
|
53
|
+
* varying vec2 vUv;
|
|
54
|
+
* void main() {
|
|
55
|
+
* gl_FragColor = vec4(vUv, 0.5 + 0.5 * sin(iTime), 1.0);
|
|
56
|
+
* }
|
|
57
|
+
* `,
|
|
58
|
+
* });
|
|
59
|
+
* scene.add(shader);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class ShaderMobject extends Mobject {
|
|
63
|
+
private _width;
|
|
64
|
+
private _height;
|
|
65
|
+
private _fragmentShader;
|
|
66
|
+
private _vertexShader;
|
|
67
|
+
private _mouse;
|
|
68
|
+
private _blending;
|
|
69
|
+
private _transparent;
|
|
70
|
+
private _time;
|
|
71
|
+
private _resolution;
|
|
72
|
+
private readonly _uniformValues;
|
|
73
|
+
private _material;
|
|
74
|
+
constructor(options: ShaderMobjectOptions);
|
|
75
|
+
protected _createThreeObject(): THREE.Object3D;
|
|
76
|
+
/** Set a uniform value, creating it if it was not declared. */
|
|
77
|
+
setUniform(name: string, value: ShaderUniformValue): this;
|
|
78
|
+
/** Get a uniform value, or `undefined` if it is not set. */
|
|
79
|
+
getUniform(name: string): ShaderUniformValue | undefined;
|
|
80
|
+
/** Set the shader time `iTime` (seconds). */
|
|
81
|
+
syncToTime(t: number): this;
|
|
82
|
+
/** Get the current shader time in seconds. */
|
|
83
|
+
getTime(): number;
|
|
84
|
+
/** Set the `iResolution` uniform (in pixels or world units, caller's choice). */
|
|
85
|
+
setResolution(width: number, height: number): this;
|
|
86
|
+
/** Get the fragment shader source. */
|
|
87
|
+
getFragmentShader(): string;
|
|
88
|
+
/** Get the vertex shader source. */
|
|
89
|
+
getVertexShader(): string;
|
|
90
|
+
/** Set the plane width in world units. */
|
|
91
|
+
setWidth(width: number): this;
|
|
92
|
+
/** Get the plane width. */
|
|
93
|
+
getWidth(): number;
|
|
94
|
+
/** Set the plane height in world units. */
|
|
95
|
+
setHeight(height: number): this;
|
|
96
|
+
/** Get the plane height. */
|
|
97
|
+
getHeight(): number;
|
|
98
|
+
/** Get the underlying ShaderMaterial, or `null` before the mesh is built. */
|
|
99
|
+
getMaterial(): THREE.ShaderMaterial | null;
|
|
100
|
+
normalizeTransform(worldMatrix?: THREE.Matrix4): this;
|
|
101
|
+
copy(): ShaderMobject;
|
|
102
|
+
/** Free GPU resources. */
|
|
103
|
+
dispose(): void;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=ShaderMobject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShaderMobject.d.ts","sourceRoot":"","sources":["../../../src/mobjects/shader/ShaderMobject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,CAAC,OAAO,GACb,KAAK,CAAC,OAAO,GACb,KAAK,CAAC,OAAO,GACb,KAAK,CAAC,KAAK,GACX,KAAK,CAAC,OAAO,GACb,SAAS,MAAM,EAAE,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC9C,yEAAyE;IACzE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC1B,yCAAyC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyC;IACxE,OAAO,CAAC,SAAS,CAAqC;gBAE1C,OAAO,EAAE,oBAAoB;IAuCzC,SAAS,CAAC,kBAAkB,IAAI,KAAK,CAAC,QAAQ;IA6B9C,+DAA+D;IAC/D,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI;IAWzD,4DAA4D;IAC5D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAIxD,6CAA6C;IAC7C,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ3B,8CAA8C;IAC9C,OAAO,IAAI,MAAM;IAIjB,iFAAiF;IACjF,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAQlD,sCAAsC;IACtC,iBAAiB,IAAI,MAAM;IAI3B,oCAAoC;IACpC,eAAe,IAAI,MAAM;IAIzB,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM7B,2BAA2B;IAC3B,QAAQ,IAAI,MAAM;IAIlB,2CAA2C;IAC3C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM/B,4BAA4B;IAC5B,SAAS,IAAI,MAAM;IAInB,6EAA6E;IAC7E,WAAW,IAAI,KAAK,CAAC,cAAc,GAAG,IAAI;IAOjC,kBAAkB,CAAC,WAAW,GAAE,KAAK,CAAC,OAA2B,GAAG,IAAI;IAOxE,IAAI,IAAI,aAAa;IAsB9B,0BAA0B;IAC1B,OAAO,IAAI,IAAI;CAShB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mobjects/shader/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mobjects/sketch/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VMobject } from '../../core/VMobject';
|
|
2
|
+
/** Options for {@link sketch}. */
|
|
3
|
+
export interface SketchOptions {
|
|
4
|
+
/** Deviation scale. 0 keeps the source shape; 1 is a normal hand-drawn look. */
|
|
5
|
+
roughness?: number;
|
|
6
|
+
/** Side-bow of each edge, as a fraction of the edge length. */
|
|
7
|
+
bowing?: number;
|
|
8
|
+
/** Random stroke-width change, as a fraction of the source width (0..1). */
|
|
9
|
+
strokeWidthJitter?: number;
|
|
10
|
+
/** PRNG seed. The same seed gives the same output. */
|
|
11
|
+
seed?: number;
|
|
12
|
+
/** Number of overlapping strokes (1 or 2). 2 gives a double-stroke look. */
|
|
13
|
+
strokes?: 1 | 2;
|
|
14
|
+
/** Straight sub-segments per edge. More segments give a finer wobble. */
|
|
15
|
+
segments?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Return a hand-drawn (sketch) copy of a VMobject.
|
|
19
|
+
*
|
|
20
|
+
* The source is copied first, so it is never changed. Every family member that
|
|
21
|
+
* owns points is perturbed with a seeded PRNG, which keeps the output
|
|
22
|
+
* deterministic for a given seed. The copy keeps the source type, stroke and
|
|
23
|
+
* fill style, so it is a drop-in replacement.
|
|
24
|
+
*
|
|
25
|
+
* @param mobject - Source VMobject (line, polygon, circle, text, group, ...)
|
|
26
|
+
* @param options - Sketch options; see {@link SketchOptions}
|
|
27
|
+
* @returns A new VMobject with the hand-drawn path
|
|
28
|
+
*/
|
|
29
|
+
export declare function sketch<T extends VMobject>(mobject: T, options?: SketchOptions): T;
|
|
30
|
+
//# sourceMappingURL=sketch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch.d.ts","sourceRoot":"","sources":["../../../src/mobjects/sketch/sketch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA+JD;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAE,aAAkB,GAAG,CAAC,CASrF"}
|