manim-web 0.27.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/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/integrations/notebook.js +11 -11
- package/dist/integrations/react.js +17 -17
- package/dist/integrations/vue.js +16 -16
- package/dist/manim-web.browser.js +1732 -952
- 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-C3q2JQb_.js → src-D7e_dgYz.js} +1714 -934
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
2
|
+
import { NodeStyleOptions } from './mlStyles';
|
|
3
|
+
export interface ConvolutionalLayerOptions {
|
|
4
|
+
/** Number of feature-map squares in the stack. Default: 3. Must be >= 0. */
|
|
5
|
+
numFeatureMaps?: number;
|
|
6
|
+
/** Side length of each square feature map. Default: 0.5. */
|
|
7
|
+
mapSize?: number;
|
|
8
|
+
/** Diagonal offset between adjacent squares. Default: 0.15. */
|
|
9
|
+
offset?: number;
|
|
10
|
+
/** Node style overrides for the squares. */
|
|
11
|
+
nodeStyle?: NodeStyleOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare class ConvolutionalLayer extends NeuralNetworkLayer {
|
|
14
|
+
private readonly _width;
|
|
15
|
+
constructor(options?: ConvolutionalLayerOptions);
|
|
16
|
+
/** Horizontal extent of the feature-map stack, used for spacing. */
|
|
17
|
+
layerWidth(): number;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ConvolutionalLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConvolutionalLayer.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/ConvolutionalLayer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,yBAAyB;IACxC,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,kBAAmB,SAAQ,kBAAkB;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,GAAE,yBAA8B;IAgBnD,oEAAoE;IAC3D,UAAU,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VMobject } from '../../core/VMobject';
|
|
2
|
+
import { Animation, AnimationOptions } from '../../animation/Animation';
|
|
3
|
+
export interface EdgePulseOptions extends AnimationOptions {
|
|
4
|
+
/** Color the line takes when fully active. Default: white. */
|
|
5
|
+
activationColor?: string;
|
|
6
|
+
/** Peak stroke opacity at full activation. Default: 1. */
|
|
7
|
+
peakOpacity?: number;
|
|
8
|
+
/** When true, the line fades back to its resting look at alpha 1. Default: false. */
|
|
9
|
+
restore?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class EdgePulse extends Animation {
|
|
12
|
+
/** The activation level set on the most recent interpolate call, 0 to 1. */
|
|
13
|
+
activation: number;
|
|
14
|
+
private readonly _activationColor;
|
|
15
|
+
private readonly _peakOpacity;
|
|
16
|
+
private readonly _restore;
|
|
17
|
+
private _baseOpacity;
|
|
18
|
+
private _baseColor;
|
|
19
|
+
constructor(line: VMobject, options?: EdgePulseOptions);
|
|
20
|
+
begin(): void;
|
|
21
|
+
interpolate(alpha: number): void;
|
|
22
|
+
finish(): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an EdgePulse animation for one connection line.
|
|
26
|
+
* @param line - The connection line to animate.
|
|
27
|
+
* @param options - Activation color, peak opacity, restore and timing options.
|
|
28
|
+
*/
|
|
29
|
+
export declare function edgePulse(line: VMobject, options?: EdgePulseOptions): EdgePulse;
|
|
30
|
+
//# sourceMappingURL=EdgePulse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgePulse.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/EdgePulse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIxE,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,8DAA8D;IAC9D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,SAAU,SAAQ,SAAS;IACtC,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAK;IAEvB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,UAAU,CAAc;gBAEpB,IAAI,EAAE,QAAQ,EAAE,OAAO,GAAE,gBAAqB;IAWjD,KAAK,IAAI,IAAI;IAOtB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAYvB,MAAM,IAAI,IAAI;CAWxB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAE/E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
2
|
+
import { NodeStyleOptions } from './mlStyles';
|
|
3
|
+
export interface FeedForwardLayerOptions {
|
|
4
|
+
/** Number of nodes (circles) in the column. Default: 3. Must be >= 0. */
|
|
5
|
+
numNodes?: number;
|
|
6
|
+
/** Radius of each node circle. Default: 0.25. */
|
|
7
|
+
nodeRadius?: number;
|
|
8
|
+
/** Vertical gap between the centers of adjacent nodes. Default: 0.7. */
|
|
9
|
+
nodeSpacing?: number;
|
|
10
|
+
/** Node style overrides. */
|
|
11
|
+
nodeStyle?: NodeStyleOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare class FeedForwardLayer extends NeuralNetworkLayer {
|
|
14
|
+
private readonly _nodeRadius;
|
|
15
|
+
private readonly _nodeSpacing;
|
|
16
|
+
private readonly _nodeStyle;
|
|
17
|
+
constructor(options?: FeedForwardLayerOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Build `count` circles in a vertical column centered on the local origin.
|
|
20
|
+
* @param count - Number of circles to create (0 leaves the layer empty).
|
|
21
|
+
*/
|
|
22
|
+
private _buildNodes;
|
|
23
|
+
/** Get the radius of each node circle. */
|
|
24
|
+
getNodeRadius(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Horizontal extent of the column (one circle wide), used for spacing.
|
|
27
|
+
* Stays positive even with zero nodes so the network can place an empty layer.
|
|
28
|
+
*/
|
|
29
|
+
layerWidth(): number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=FeedForwardLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedForwardLayer.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/FeedForwardLayer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,OAAO,GAAE,uBAA4B;IAYjD;;;OAGG;IACH,OAAO,CAAC,WAAW;IAoBnB,0CAA0C;IAC1C,aAAa,IAAI,MAAM;IAIvB;;;OAGG;IACM,UAAU,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
2
|
+
import { NodeStyleOptions } from './mlStyles';
|
|
3
|
+
export interface ImageLayerOptions {
|
|
4
|
+
/** Number of pixel rows. Default: 3. Must be >= 0. */
|
|
5
|
+
rows?: number;
|
|
6
|
+
/** Number of pixel columns. Default: 3. Must be >= 0. */
|
|
7
|
+
cols?: number;
|
|
8
|
+
/** Side length of each pixel cell. Default: 0.25. */
|
|
9
|
+
cellSize?: number;
|
|
10
|
+
/** Cell style overrides. */
|
|
11
|
+
nodeStyle?: NodeStyleOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare class ImageLayer extends NeuralNetworkLayer {
|
|
14
|
+
private readonly _cols;
|
|
15
|
+
private readonly _cellSize;
|
|
16
|
+
private readonly _grid;
|
|
17
|
+
constructor(options?: ImageLayerOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Build the pixel grid centered on the local origin.
|
|
20
|
+
* @param rows - Number of rows.
|
|
21
|
+
* @param cols - Number of columns.
|
|
22
|
+
* @param style - Resolved cell style.
|
|
23
|
+
* @returns A VGroup of cell rectangles (empty when rows or cols is 0).
|
|
24
|
+
*/
|
|
25
|
+
private _buildGrid;
|
|
26
|
+
/** Horizontal extent of the grid, always positive for spacing. */
|
|
27
|
+
layerWidth(): number;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ImageLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageLayer.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/ImageLayer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,UAAW,SAAQ,kBAAkB;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,OAAO,GAAE,iBAAsB;IAiB3C;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAwBlB,kEAAkE;IACzD,UAAU,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { VGroup } from '../../core/VGroup';
|
|
2
|
+
import { Line } from '../geometry/Line';
|
|
3
|
+
import { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
4
|
+
import { ConnectionStyleOptions } from './mlStyles';
|
|
5
|
+
/**
|
|
6
|
+
* NeuralNetwork - a diagram of stacked layers with connection lines between
|
|
7
|
+
* adjacent layers (a manim-ml NeuralNetwork analogue).
|
|
8
|
+
*
|
|
9
|
+
* The network is a VGroup built from a list of layers. It places the layers
|
|
10
|
+
* left to right and, for every adjacent pair, draws a dense set of connection
|
|
11
|
+
* lines between their node anchors (n_i x n_{i+1} lines). Connections are added
|
|
12
|
+
* before the layers so they render behind the nodes.
|
|
13
|
+
*/
|
|
14
|
+
import * as THREE from 'three';
|
|
15
|
+
export interface NeuralNetworkOptions {
|
|
16
|
+
/** Horizontal gap between adjacent layers. Default: 1. */
|
|
17
|
+
layerSpacing?: number;
|
|
18
|
+
/** Connection line style overrides. */
|
|
19
|
+
edgeStyle?: ConnectionStyleOptions;
|
|
20
|
+
/** When false, no connection lines are drawn. Default: true. */
|
|
21
|
+
connectAdjacent?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class NeuralNetwork extends VGroup {
|
|
24
|
+
private readonly _layers;
|
|
25
|
+
private readonly _connections;
|
|
26
|
+
/** Connection lines grouped by the gap they cross (stage i joins layer i and i+1). */
|
|
27
|
+
private readonly _stages;
|
|
28
|
+
private readonly _edgeStyle;
|
|
29
|
+
/**
|
|
30
|
+
* @param layers - The layers, drawn left to right in array order.
|
|
31
|
+
* @param options - Spacing, edge style and whether to connect layers.
|
|
32
|
+
*/
|
|
33
|
+
constructor(layers?: NeuralNetworkLayer[], options?: NeuralNetworkOptions);
|
|
34
|
+
/**
|
|
35
|
+
* A container flattens its transform into its children (layers and lines)
|
|
36
|
+
* rather than baking its own geometry, matching GenericGraph.
|
|
37
|
+
*/
|
|
38
|
+
normalizeTransform(worldMatrix?: THREE.Matrix4): this;
|
|
39
|
+
/**
|
|
40
|
+
* Place each layer so its center sits on a strictly increasing x, spaced by
|
|
41
|
+
* the layers' own widths plus `layerSpacing`. Uses shift (not moveTo) so an
|
|
42
|
+
* empty layer is positioned without measuring absent geometry.
|
|
43
|
+
* @param layerSpacing - Horizontal gap between adjacent layer edges.
|
|
44
|
+
*/
|
|
45
|
+
private _placeLayers;
|
|
46
|
+
/**
|
|
47
|
+
* Build dense connection lines between every adjacent pair of layers.
|
|
48
|
+
* A pair contributes n_i x n_{i+1} lines; a 0-node layer contributes none.
|
|
49
|
+
*/
|
|
50
|
+
private _buildConnections;
|
|
51
|
+
/** Get the layers in left-to-right order. */
|
|
52
|
+
getLayers(): NeuralNetworkLayer[];
|
|
53
|
+
/**
|
|
54
|
+
* Get a single layer by index.
|
|
55
|
+
* @param index - Zero-based layer index.
|
|
56
|
+
* @returns The layer, or undefined when the index is out of range.
|
|
57
|
+
*/
|
|
58
|
+
getLayer(index: number): NeuralNetworkLayer | undefined;
|
|
59
|
+
/** Get the number of layers. */
|
|
60
|
+
get numLayers(): number;
|
|
61
|
+
/** Get every connection line, flattened across all gaps. */
|
|
62
|
+
getConnections(): Line[];
|
|
63
|
+
/**
|
|
64
|
+
* Get the connection lines grouped by gap. Entry i holds the lines that join
|
|
65
|
+
* layer i and layer i+1.
|
|
66
|
+
*/
|
|
67
|
+
getConnectionStages(): Line[][];
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=NeuralNetwork.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NeuralNetwork.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/NeuralNetwork.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,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{ Vector3Tuple } from '../../core/Mobject';
|
|
4
|
+
/**
|
|
5
|
+
* NeuralNetworkLayer - abstract base for every layer in a NeuralNetwork.
|
|
6
|
+
*
|
|
7
|
+
* A layer is a VGroup of node mobjects (circles, feature-map squares, a pixel
|
|
8
|
+
* grid). The NeuralNetwork places layers left to right and draws connection
|
|
9
|
+
* lines between the anchor points of adjacent layers. Each concrete layer
|
|
10
|
+
* exposes the same small interface so the network can treat them uniformly.
|
|
11
|
+
*/
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
export declare abstract class NeuralNetworkLayer extends VGroup {
|
|
14
|
+
/**
|
|
15
|
+
* The node mobjects of this layer, in top-to-bottom order.
|
|
16
|
+
*
|
|
17
|
+
* A connection attaches to a node's center, so this list defines how many
|
|
18
|
+
* edges the network draws to the next layer. It may be empty (a layer with
|
|
19
|
+
* zero nodes), which the network treats as "no connections".
|
|
20
|
+
*/
|
|
21
|
+
protected _nodes: VMobject[];
|
|
22
|
+
/**
|
|
23
|
+
* A container flattens its own transform into its children instead of baking
|
|
24
|
+
* geometry, exactly like GenericGraph. This keeps node centers and the
|
|
25
|
+
* connection lines (which the network positions in world space) correct when
|
|
26
|
+
* a scene normalizes the family.
|
|
27
|
+
*/
|
|
28
|
+
normalizeTransform(worldMatrix?: THREE.Matrix4): this;
|
|
29
|
+
/**
|
|
30
|
+
* Get the node mobjects of this layer.
|
|
31
|
+
* @returns The nodes in top-to-bottom order (an empty array for a 0-node layer).
|
|
32
|
+
*/
|
|
33
|
+
getNodes(): VMobject[];
|
|
34
|
+
/**
|
|
35
|
+
* Get the number of nodes (connection anchors) in this layer.
|
|
36
|
+
*/
|
|
37
|
+
get numNodes(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get the world-space anchor point of each node, in node order.
|
|
40
|
+
*
|
|
41
|
+
* The network calls this after it has positioned the layer, so the centers
|
|
42
|
+
* already include the layer's placement offset.
|
|
43
|
+
* @returns One center per node (an empty array for a 0-node layer).
|
|
44
|
+
*/
|
|
45
|
+
nodeAnchors(): Vector3Tuple[];
|
|
46
|
+
/**
|
|
47
|
+
* Get the horizontal extent used to space this layer from its neighbours.
|
|
48
|
+
*
|
|
49
|
+
* It must return a positive number even when the layer has zero nodes, so the
|
|
50
|
+
* network can lay out an empty layer without measuring absent geometry.
|
|
51
|
+
*/
|
|
52
|
+
abstract layerWidth(): number;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=NeuralNetworkLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NeuralNetworkLayer.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/NeuralNetworkLayer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,8BAAsB,kBAAmB,SAAQ,MAAM;IACrD;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAM;IAElC;;;;;OAKG;IACM,kBAAkB,CAAC,WAAW,GAAE,KAAK,CAAC,OAA2B,GAAG,IAAI;IAIjF;;;OAGG;IACH,QAAQ,IAAI,QAAQ,EAAE;IAItB;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;;;;OAMG;IACH,WAAW,IAAI,YAAY,EAAE;IAI7B;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,IAAI,MAAM;CAC9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
2
|
+
import { NodeStyleOptions } from './mlStyles';
|
|
3
|
+
export interface PoolingLayerOptions {
|
|
4
|
+
/** Number of feature-map squares in the stack. Default: 3. Must be >= 0. */
|
|
5
|
+
numFeatureMaps?: number;
|
|
6
|
+
/** Side length of each square feature map. Default: 0.3. */
|
|
7
|
+
mapSize?: number;
|
|
8
|
+
/** Diagonal offset between adjacent squares. Default: 0.12. */
|
|
9
|
+
offset?: number;
|
|
10
|
+
/** Node style overrides for the squares. */
|
|
11
|
+
nodeStyle?: NodeStyleOptions;
|
|
12
|
+
}
|
|
13
|
+
export declare class PoolingLayer extends NeuralNetworkLayer {
|
|
14
|
+
private readonly _width;
|
|
15
|
+
constructor(options?: PoolingLayerOptions);
|
|
16
|
+
/** Horizontal extent of the feature-map stack, used for spacing. */
|
|
17
|
+
layerWidth(): number;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=PoolingLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PoolingLayer.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/PoolingLayer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,qBAAa,YAAa,SAAQ,kBAAkB;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,GAAE,mBAAwB;IAgB7C,oEAAoE;IAC3D,UAAU,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VMobject } from '../../core/VMobject';
|
|
2
|
+
import { ResolvedNodeStyle } from './mlStyles';
|
|
3
|
+
export interface FeatureMapStackConfig {
|
|
4
|
+
/** Number of stacked feature-map squares. Must be >= 0. */
|
|
5
|
+
numFeatureMaps: number;
|
|
6
|
+
/** Side length of each square feature map. */
|
|
7
|
+
mapSize: number;
|
|
8
|
+
/** Diagonal offset between adjacent squares in the stack. */
|
|
9
|
+
offset: number;
|
|
10
|
+
/** Resolved node style for the squares. */
|
|
11
|
+
style: ResolvedNodeStyle;
|
|
12
|
+
}
|
|
13
|
+
export interface FeatureMapStackResult {
|
|
14
|
+
/** The feature-map squares, front (first) to back (last). */
|
|
15
|
+
nodes: VMobject[];
|
|
16
|
+
/** Horizontal extent of the stack, always positive. */
|
|
17
|
+
width: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a diagonal stack of square feature maps centered on the local origin.
|
|
21
|
+
* @param config - Count, size, offset and style of the stack.
|
|
22
|
+
* @returns The square nodes and the stack's horizontal extent.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildFeatureMapStack(config: FeatureMapStackConfig): FeatureMapStackResult;
|
|
25
|
+
//# sourceMappingURL=featureMapStack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"featureMapStack.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/featureMapStack.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,qBAAqB;IACpC,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,GAAG,qBAAqB,CAyBzF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Animation } from '../../animation/Animation';
|
|
2
|
+
import { NeuralNetwork } from './NeuralNetwork';
|
|
3
|
+
import { EdgePulseOptions } from './EdgePulse';
|
|
4
|
+
export interface ForwardPassOptions extends EdgePulseOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Overlap between consecutive gaps. 1 is strictly sequential (one gap fully
|
|
7
|
+
* lit before the next starts), 0 is all gaps at once. Default: 1.
|
|
8
|
+
*/
|
|
9
|
+
lagRatio?: number;
|
|
10
|
+
/** Duration of each gap's pulse in seconds. Default: 1. */
|
|
11
|
+
gapDuration?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Animate a forward pass: light each gap's connections from input to output.
|
|
15
|
+
* @param network - The network to animate.
|
|
16
|
+
* @param options - Pulse color/opacity, lagRatio and per-gap duration.
|
|
17
|
+
* @returns A LaggedStart over the gaps (an empty, zero-duration one for a
|
|
18
|
+
* network with fewer than two layers).
|
|
19
|
+
*/
|
|
20
|
+
export declare function forwardPass(network: NeuralNetwork, options?: ForwardPassOptions): Animation;
|
|
21
|
+
/**
|
|
22
|
+
* Animate a backward pass: light each gap's connections from output to input.
|
|
23
|
+
* @param network - The network to animate.
|
|
24
|
+
* @param options - Pulse color/opacity, lagRatio and per-gap duration.
|
|
25
|
+
* @returns A LaggedStart over the gaps in reverse order.
|
|
26
|
+
*/
|
|
27
|
+
export declare function backwardPass(network: NeuralNetwork, options?: ForwardPassOptions): Animation;
|
|
28
|
+
//# sourceMappingURL=forwardPass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forwardPass.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/forwardPass.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAItD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8BD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,GAAE,kBAAuB,GAAG,SAAS,CAG/F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,GAAE,kBAAuB,GAAG,SAAS,CAGhG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neural-network / ML diagram toolkit for manim-web.
|
|
3
|
+
*
|
|
4
|
+
* A manim-ml analogue built purely by composition: layers are VGroups of
|
|
5
|
+
* geometry, the network arranges them and draws connections, and forward /
|
|
6
|
+
* backward passes animate a signal flowing through the connections.
|
|
7
|
+
*/
|
|
8
|
+
export { type NodeStyleOptions, type ConnectionStyleOptions, type ResolvedNodeStyle, type ResolvedEdgeStyle, DEFAULT_NODE_STYLE, DEFAULT_EDGE_STYLE, DEFAULT_ACTIVATION_COLOR, resolveNodeStyle, resolveEdgeStyle, } from './mlStyles';
|
|
9
|
+
export { NeuralNetworkLayer } from './NeuralNetworkLayer';
|
|
10
|
+
export { FeedForwardLayer, type FeedForwardLayerOptions } from './FeedForwardLayer';
|
|
11
|
+
export { ConvolutionalLayer, type ConvolutionalLayerOptions } from './ConvolutionalLayer';
|
|
12
|
+
export { PoolingLayer, type PoolingLayerOptions } from './PoolingLayer';
|
|
13
|
+
export { ImageLayer, type ImageLayerOptions } from './ImageLayer';
|
|
14
|
+
export { buildFeatureMapStack, type FeatureMapStackConfig, type FeatureMapStackResult, } from './featureMapStack';
|
|
15
|
+
export { NeuralNetwork, type NeuralNetworkOptions } from './NeuralNetwork';
|
|
16
|
+
export { EdgePulse, edgePulse, type EdgePulseOptions } from './EdgePulse';
|
|
17
|
+
export { forwardPass, backwardPass, type ForwardPassOptions } from './forwardPass';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mobjects/ml/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -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,YA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7B,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;AAQ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