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,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"}
|