manim-web 0.18.0 → 0.19.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.
@@ -0,0 +1,130 @@
1
+ import { Mobject, Vector3Tuple } from '../../core/Mobject';
2
+ import { Mobject3D } from './Mobject3D';
3
+ import * as THREE from 'three';
4
+ /**
5
+ * A single instance of the shared template geometry.
6
+ *
7
+ * `position` is required. `rotation` is a Euler tuple in radians (`XYZ` order).
8
+ * `scale` is a uniform factor or a per-axis tuple. `color` is a CSS color string
9
+ * applied to this instance only; omit it to keep the material color.
10
+ */
11
+ export interface InstanceTransform {
12
+ /** Instance position [x, y, z]. */
13
+ position: Vector3Tuple;
14
+ /** Euler rotation [x, y, z] in radians (XYZ order). Default: no rotation. */
15
+ rotation?: Vector3Tuple;
16
+ /** Uniform scale, or per-axis [x, y, z] scale. Default: 1. */
17
+ scale?: number | Vector3Tuple;
18
+ /** Per-instance CSS color. Default: inherit the material color. */
19
+ color?: string;
20
+ }
21
+ /**
22
+ * Options for creating an {@link InstancedMobject}.
23
+ *
24
+ * Provide a template as either an explicit `geometry` + `material`, or a
25
+ * `template` mobject to derive both from. If none is given, a unit box with a
26
+ * standard material is used.
27
+ */
28
+ export interface InstancedMobjectOptions {
29
+ /** Geometry shared by every instance. Cloned on {@link InstancedMobject.copy}. */
30
+ geometry?: THREE.BufferGeometry;
31
+ /** Material shared by every instance. Cloned on {@link InstancedMobject.copy}. */
32
+ material?: THREE.Material;
33
+ /** Template mobject to derive geometry and material from (cloned, not kept). */
34
+ template?: Mobject;
35
+ /** Per-instance transforms. Default: empty (no instances). */
36
+ instances?: InstanceTransform[];
37
+ /** Base material color as a CSS color string. Default: '#ffffff'. */
38
+ color?: string;
39
+ /** Material opacity from 0 to 1. Default: 1. */
40
+ opacity?: number;
41
+ }
42
+ /**
43
+ * InstancedMobject - renders many copies of one template via `THREE.InstancedMesh`.
44
+ *
45
+ * This is a safe, opt-in mobject for large scenes. It draws `count` copies of a
46
+ * single geometry + material in ONE draw call, instead of one mesh per copy.
47
+ * It does not change the default render path: scenes that do not use it are
48
+ * unaffected.
49
+ *
50
+ * Each instance has its own transform (position, optional rotation and scale)
51
+ * and an optional per-instance color. Use {@link setInstances} to replace the
52
+ * whole set, or {@link setInstanceTransform} / {@link setInstanceColor} to
53
+ * update one instance in place.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const dots = new InstancedMobject({
58
+ * geometry: new THREE.SphereGeometry(0.1, 16, 16),
59
+ * material: new THREE.MeshStandardMaterial(),
60
+ * instances: [
61
+ * { position: [0, 0, 0], color: '#ff0000' },
62
+ * { position: [1, 0, 0], scale: 2 },
63
+ * ],
64
+ * });
65
+ * scene.add(dots);
66
+ * ```
67
+ */
68
+ export declare class InstancedMobject extends Mobject3D {
69
+ private _geometry;
70
+ private _material;
71
+ private _instances;
72
+ /** The single InstancedMesh; null until the Three.js object is built. */
73
+ private _mesh;
74
+ constructor(options?: InstancedMobjectOptions);
75
+ /**
76
+ * Resolve the shared geometry and material from the options.
77
+ * Order: explicit geometry/material, then a template mobject, then a default
78
+ * unit box. A geometry or material derived from a template is cloned so the
79
+ * template is never mutated or disposed by this mobject.
80
+ */
81
+ private static _resolveTemplate;
82
+ /** Find the first Mesh in a Three.js subtree, or null if there is none. */
83
+ private static _findMesh;
84
+ /** Deep-copy one instance transform so callers cannot alias our state. */
85
+ private static _cloneTransform;
86
+ /**
87
+ * Build the InstancedMesh with `count = instances.length` and fill its matrix
88
+ * and color buffers. Wrapped in a Group so a later count change can swap the
89
+ * mesh without touching the scene-graph parent.
90
+ */
91
+ protected _createThreeObject(): THREE.Object3D;
92
+ /** Create a fresh InstancedMesh for the current instances and populate it. */
93
+ private _buildMesh;
94
+ /** Write every instance matrix (and color, when present) into `mesh`. */
95
+ private _writeAllInstances;
96
+ /** Compose a transform matrix for one instance into `out`. */
97
+ private static _composeMatrix;
98
+ /** Sync base material color and opacity onto the shared material. */
99
+ protected _syncMaterialToThree(): void;
100
+ /**
101
+ * Replace all instances. Reuses the existing mesh when the count is unchanged;
102
+ * otherwise rebuilds the InstancedMesh (its count is fixed at construction).
103
+ */
104
+ setInstances(instances: InstanceTransform[]): this;
105
+ /** Update one instance transform in place and flag the matrix buffer. */
106
+ setInstanceTransform(index: number, transform: Partial<InstanceTransform>): this;
107
+ /** Update one instance color in place and flag the color buffer. */
108
+ setInstanceColor(index: number, color: string): this;
109
+ private _assertIndex;
110
+ /** Number of instances this mobject draws. */
111
+ getInstanceCount(): number;
112
+ /** The single backing InstancedMesh, building the Three.js object if needed. */
113
+ getInstancedMesh(): THREE.InstancedMesh;
114
+ /** The transform of instance `index` as a Matrix4 (reads back from the mesh). */
115
+ getInstanceMatrix(index: number, out?: THREE.Matrix4): THREE.Matrix4;
116
+ /** The shared geometry used by every instance. */
117
+ getGeometry(): THREE.BufferGeometry;
118
+ /** The shared material used by every instance. */
119
+ getMaterial(): THREE.Material;
120
+ /**
121
+ * An instance cloud is empty only when it has no instances. The base
122
+ * {@link Mobject.getCenter} / {@link Mobject.getBounds} then skip the bounding
123
+ * box, which would be empty and throw.
124
+ */
125
+ isEmpty(): boolean;
126
+ /** Dispose the InstancedMesh buffers, geometry, and material. No leaks. */
127
+ dispose(): void;
128
+ copy(): InstancedMobject;
129
+ }
130
+ //# sourceMappingURL=InstancedMobject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InstancedMobject.d.ts","sourceRoot":"","sources":["../../../src/mobjects/three-d/InstancedMobject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,QAAQ,EAAE,YAAY,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,YAA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E,GAAG,IAAI;IAgBlD,yEAAyE;IACzE,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;IAiBhF,oEAAoE;IACpE,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAWpD,OAAO,CAAC,YAAY;IAQpB,8CAA8C;IAC9C,gBAAgB,IAAI,MAAM;IAI1B,gFAAgF;IAChF,gBAAgB,IAAI,KAAK,CAAC,aAAa;IAQvC,iFAAiF;IACjF,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,KAAK,CAAC,OAA6B,GAAG,KAAK,CAAC,OAAO;IAMzF,kDAAkD;IAClD,WAAW,IAAI,KAAK,CAAC,cAAc;IAInC,kDAAkD;IAClD,WAAW,IAAI,KAAK,CAAC,QAAQ;IAI7B;;;;OAIG;IACM,OAAO,IAAI,OAAO;IAI3B,2EAA2E;IAClE,OAAO,IAAI,IAAI;IAOf,IAAI,IAAI,gBAAgB;CAWlC"}
@@ -20,4 +20,5 @@ export { Prism, Dot3D, ThreeDVMobject, type PrismOptions, type Dot3DOptions, typ
20
20
  export { ConvexHull3D, type ConvexHull3DOptions } from './ConvexHull3D';
21
21
  export { marchingCubes, type MarchingCubesOptions, type MarchingCubesResult, type ScalarField3D, } from './marchingCubes';
22
22
  export { ImplicitSurface, type ImplicitSurfaceOptions } from './ImplicitSurface';
23
+ export { InstancedMobject, type InstancedMobjectOptions, type InstanceTransform, } from './InstancedMobject';
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mobjects/three-d/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD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