simulationjsv2 0.5.2 → 0.7.1

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/TODO.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # TODO
2
2
 
3
- - [ ] Make input position vec3 not vec4
4
- - [ ] Change position/rotation to be matrix transform on gpu
5
- - [ ] Make getBuffer return cached Float32Array
3
+ - [ ] Fix transparency
4
+ - [x] Update `updateModelMatrix2d`
5
+ - [x] Trace line element (wireframe strip for tracing paths)
6
+ - [x] Test new transform things on 3d stuff
7
+ - [x] Fix rotating nested children elements
8
+ - [x] Fix instancing
9
+ - [x] Remove SceneCollection and replace by elements with children
10
+ - Test this
11
+ - [x] Change position/rotation to be matrix transform on gpu
12
+ - [x] Add update square center offset position in-place + not
13
+ - [x] Make getBuffer return cached Float32Array
14
+ - [x] Make input buffer position vec3 not vec4
15
+ - [x] Use line strip vertices for polygon buffers
16
+ - [x] Scene collection wireframe
17
+ - [ ] Add animation status handle to transition values
@@ -1,6 +1,12 @@
1
- export declare const vertexSize = 44;
1
+ export declare const vertexSize = 40;
2
2
  export declare const positionOffset = 0;
3
- export declare const colorOffset = 16;
4
- export declare const uvOffset = 32;
5
- export declare const drawingInstancesOffset = 40;
3
+ export declare const colorOffset = 12;
4
+ export declare const uvOffset = 28;
5
+ export declare const drawingInstancesOffset = 36;
6
6
  export declare const BUF_LEN: number;
7
+ export declare const worldProjMatOffset = 0;
8
+ export declare const modelProjMatOffset: number;
9
+ export declare const xAxis: import("./types.js").Vector3;
10
+ export declare const yAxis: import("./types.js").Vector3;
11
+ export declare const zAxis: import("./types.js").Vector3;
12
+ export declare const origin0: import("./types.js").Vector3;
package/dist/constants.js CHANGED
@@ -1,6 +1,13 @@
1
- export const vertexSize = 44; // 4 * 10
1
+ import { vector3 } from './utils.js';
2
+ export const vertexSize = 40; // 4 * 10
2
3
  export const positionOffset = 0;
3
- export const colorOffset = 16; // 4 * 4
4
- export const uvOffset = 32; // 4 * 8
5
- export const drawingInstancesOffset = 40;
4
+ export const colorOffset = 12; // 4 * 3
5
+ export const uvOffset = 28; // 4 * 8
6
+ export const drawingInstancesOffset = 36;
6
7
  export const BUF_LEN = vertexSize / 4;
8
+ export const worldProjMatOffset = 0;
9
+ export const modelProjMatOffset = 4 * 16;
10
+ export const xAxis = vector3(1);
11
+ export const yAxis = vector3(0, 1);
12
+ export const zAxis = vector3(0, 0, 1);
13
+ export const origin0 = vector3();
@@ -1,4 +1,4 @@
1
- import { VertexParamGeneratorInfo, CircleGeometryParams, CubeGeometryParams, EmptyParams, Line2dGeometryParams, Line3dGeometryParams, Mat4, PolygonGeometryParams, Spline2dGeometryParams, SquareGeometryParams, Vector2, Vector3, VertexColorMap } from './types.js';
1
+ import { VertexParamGeneratorInfo, CircleGeometryParams, CubeGeometryParams, EmptyParams, PolygonGeometryParams, Spline2dGeometryParams, SquareGeometryParams, Vector2, Vector3, VertexColorMap, LineGeometryParams, TraceLinesParams } from './types.js';
2
2
  import { Color, Vertex } from './utils.js';
3
3
  import { CubicBezierCurve2d, SplinePoint2d } from './graphics.js';
4
4
  export declare abstract class Geometry<T extends EmptyParams> {
@@ -6,10 +6,8 @@ export declare abstract class Geometry<T extends EmptyParams> {
6
6
  protected abstract triangleOrder: number[];
7
7
  protected abstract params: T;
8
8
  protected vertices: Vector3[];
9
- protected matrix: Mat4;
10
9
  protected geometryType: 'list' | 'strip';
11
10
  constructor(vertices?: Vector3[], geometryType?: 'list' | 'strip');
12
- updateMatrix(matrix: Mat4): void;
13
11
  getType(): "list" | "strip";
14
12
  abstract recompute(): void;
15
13
  getTriangleVertexCount(): number;
@@ -44,6 +42,8 @@ export declare class SquareGeometry extends Geometry<SquareGeometryParams> {
44
42
  protected triangleOrder: number[];
45
43
  protected params: SquareGeometryParams;
46
44
  constructor(width: number, height: number, centerOffset?: Vector2);
45
+ setOffset(offset: Vector2): void;
46
+ getOffset(): Vector2;
47
47
  setVertexColorMap(colorMap: VertexColorMap): void;
48
48
  setWidth(width: number): void;
49
49
  setHeight(height: number): void;
@@ -86,18 +86,24 @@ export declare class Spline2dGeometry extends Geometry<Spline2dGeometryParams> {
86
86
  getWireframeBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
87
87
  getTriangleBuffer(_: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
88
88
  }
89
- export declare class Line2dGeometry extends Geometry<Line2dGeometryParams> {
89
+ export declare class Line2dGeometry extends Geometry<LineGeometryParams> {
90
90
  protected wireframeOrder: number[];
91
91
  protected triangleOrder: number[];
92
- protected params: Line2dGeometryParams;
93
- constructor(pos: Vector2, to: Vector2, thickness: number);
92
+ protected params: LineGeometryParams;
93
+ constructor(pos: Vector3, to: Vector3, thickness: number, fromColor?: Color | null, toColor?: Color | null);
94
+ private generateBuffer;
95
+ getTriangleBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
96
+ getWireframeBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
94
97
  recompute(): void;
95
98
  }
96
- export declare class Line3dGeometry extends Geometry<Line3dGeometryParams> {
99
+ export declare class Line3dGeometry extends Geometry<LineGeometryParams> {
97
100
  protected wireframeOrder: number[];
98
101
  protected triangleOrder: number[];
99
- protected params: Line3dGeometryParams;
100
- constructor(pos: Vector3, to: Vector3, thickness: number);
102
+ protected params: LineGeometryParams;
103
+ constructor(pos: Vector3, to: Vector3, thickness: number, fromColor?: Color | null, toColor?: Color | null);
104
+ private generateBuffer;
105
+ getTriangleBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
106
+ getWireframeBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
101
107
  recompute(): void;
102
108
  }
103
109
  export declare class PolygonGeometry extends Geometry<PolygonGeometryParams> {
@@ -108,3 +114,13 @@ export declare class PolygonGeometry extends Geometry<PolygonGeometryParams> {
108
114
  recompute(): void;
109
115
  getTriangleBuffer(color: Color): number[];
110
116
  }
117
+ export declare class TraceLines2dGeometry extends Geometry<EmptyParams> {
118
+ protected wireframeOrder: never[];
119
+ protected triangleOrder: never[];
120
+ protected params: TraceLinesParams;
121
+ constructor(maxLen?: number);
122
+ recompute(): void;
123
+ getWireframeBuffer(color: Color, vertexParamGenerator?: VertexParamGeneratorInfo | undefined): number[];
124
+ getWireframeVertexCount(): number;
125
+ addVertex(vert: Vertex): void;
126
+ }
package/dist/geometry.js CHANGED
@@ -2,19 +2,14 @@ import { mat4, vec2, vec3 } from 'wgpu-matrix';
2
2
  import { cloneBuf, interpolateColors, matrix4, vector2, vector2FromVector3, vector3, vector3FromVector2, vertex } from './utils.js';
3
3
  import { CubicBezierCurve2d } from './graphics.js';
4
4
  import { BUF_LEN } from './constants.js';
5
- import { bufferGenerator, lossyTriangulate, triangulateWireFrameOrder } from './internalUtils.js';
5
+ import { bufferGenerator, lossyTriangulate, lossyTriangulateStrip, triangulateWireFrameOrder } from './internalUtils.js';
6
6
  export class Geometry {
7
7
  vertices;
8
- matrix;
9
8
  geometryType;
10
9
  constructor(vertices = [], geometryType = 'list') {
11
10
  this.vertices = vertices;
12
- this.matrix = matrix4();
13
11
  this.geometryType = geometryType;
14
12
  }
15
- updateMatrix(matrix) {
16
- this.matrix = matrix;
17
- }
18
13
  getType() {
19
14
  return this.geometryType;
20
15
  }
@@ -27,8 +22,7 @@ export class Geometry {
27
22
  bufferFromOrder(order, color, vertexParamGenerator) {
28
23
  return order
29
24
  .map((vertexIndex) => {
30
- const pos = cloneBuf(this.vertices[vertexIndex]);
31
- vec3.transformMat4(pos, this.matrix, pos);
25
+ const pos = this.vertices[vertexIndex];
32
26
  return bufferGenerator.generate(pos[0], pos[1], pos[2], color, vector2(), vertexParamGenerator);
33
27
  })
34
28
  .flat();
@@ -65,8 +59,7 @@ export class PlaneGeometry extends Geometry {
65
59
  return this.triangleOrder
66
60
  .map((index) => {
67
61
  const vertex = this.rawVertices[index];
68
- const pos = cloneBuf(vertex.getPos());
69
- vec3.transformMat4(pos, this.matrix, pos);
62
+ const pos = vertex.getPos();
70
63
  return bufferGenerator.generate(pos[0], pos[1], pos[2], vertex.getColor() || color, vector2(), vertexParamGenerator);
71
64
  })
72
65
  .flat();
@@ -137,6 +130,12 @@ export class SquareGeometry extends Geometry {
137
130
  };
138
131
  this.recompute();
139
132
  }
133
+ setOffset(offset) {
134
+ this.params.centerOffset = offset;
135
+ }
136
+ getOffset() {
137
+ return this.params.centerOffset;
138
+ }
140
139
  setVertexColorMap(colorMap) {
141
140
  this.params.colorMap = colorMap;
142
141
  }
@@ -158,8 +157,7 @@ export class SquareGeometry extends Geometry {
158
157
  getTriangleBuffer(color, vertexParamGenerator) {
159
158
  return this.triangleOrder
160
159
  .map((vertexIndex) => {
161
- const pos = cloneBuf(this.vertices[vertexIndex]);
162
- vec3.transformMat4(pos, this.matrix, pos);
160
+ const pos = this.vertices[vertexIndex];
163
161
  return bufferGenerator.generate(pos[0], pos[1], pos[2], this.params.colorMap[vertexIndex] || color, vector2(), vertexParamGenerator);
164
162
  })
165
163
  .flat();
@@ -352,8 +350,7 @@ export class Spline2dGeometry extends Geometry {
352
350
  getWireframeBuffer(color, vertexParamGenerator) {
353
351
  return this.wireframeOrder
354
352
  .map((vertexIndex) => {
355
- const vertex = cloneBuf(this.vertices[vertexIndex]);
356
- vec3.transformMat4(vertex, this.matrix, vertex);
353
+ const vertex = this.vertices[vertexIndex];
357
354
  return bufferGenerator.generate(vertex[0], vertex[1], vertex[2], color, vector2(), vertexParamGenerator);
358
355
  })
359
356
  .flat();
@@ -361,8 +358,7 @@ export class Spline2dGeometry extends Geometry {
361
358
  getTriangleBuffer(_, vertexParamGenerator) {
362
359
  return this.triangleOrder
363
360
  .map((vertexIndex) => {
364
- const vertex = cloneBuf(this.vertices[vertexIndex]);
365
- vec3.transformMat4(vertex, this.matrix, vertex);
361
+ const vertex = this.vertices[vertexIndex];
366
362
  return bufferGenerator.generate(vertex[0], vertex[1], vertex[2], this.params.vertexColors[vertexIndex], vector2(), vertexParamGenerator);
367
363
  })
368
364
  .flat();
@@ -372,14 +368,31 @@ export class Line2dGeometry extends Geometry {
372
368
  wireframeOrder = [0, 1, 2, 3, 0, 2];
373
369
  triangleOrder = [0, 1, 3, 2];
374
370
  params;
375
- constructor(pos, to, thickness) {
371
+ constructor(pos, to, thickness, fromColor, toColor) {
376
372
  super([], 'strip');
377
373
  this.params = {
378
374
  pos,
379
375
  to,
380
- thickness
376
+ thickness,
377
+ fromColor: fromColor || null,
378
+ toColor: toColor || null
381
379
  };
382
380
  }
381
+ generateBuffer(order, color, vertexParamGenerator) {
382
+ return order
383
+ .map((vertexIndex) => {
384
+ const pos = this.vertices[vertexIndex];
385
+ const vertexColor = (vertexIndex > 1 ? this.params.toColor : this.params.fromColor) || color;
386
+ return bufferGenerator.generate(pos[0], pos[1], pos[2], vertexColor, vector2(), vertexParamGenerator);
387
+ })
388
+ .flat();
389
+ }
390
+ getTriangleBuffer(color, vertexParamGenerator) {
391
+ return this.generateBuffer(this.triangleOrder, color, vertexParamGenerator);
392
+ }
393
+ getWireframeBuffer(color, vertexParamGenerator) {
394
+ return this.generateBuffer(this.wireframeOrder, color, vertexParamGenerator);
395
+ }
383
396
  recompute() {
384
397
  const normal = vector2(-this.params.to[1], this.params.to[0]);
385
398
  vec2.normalize(normal, normal);
@@ -396,14 +409,31 @@ export class Line3dGeometry extends Geometry {
396
409
  wireframeOrder = [0, 1, 2, 3, 0, 2];
397
410
  triangleOrder = [0, 1, 2, 3, 0];
398
411
  params;
399
- constructor(pos, to, thickness) {
412
+ constructor(pos, to, thickness, fromColor, toColor) {
400
413
  super([], 'strip');
401
414
  this.params = {
402
415
  pos,
403
416
  to,
404
- thickness
417
+ thickness,
418
+ fromColor: fromColor || null,
419
+ toColor: toColor || null
405
420
  };
406
421
  }
422
+ generateBuffer(order, color, vertexParamGenerator) {
423
+ return order
424
+ .map((vertexIndex) => {
425
+ const pos = this.vertices[vertexIndex];
426
+ const vertexColor = (vertexIndex > 1 ? this.params.toColor : this.params.fromColor) || color;
427
+ return bufferGenerator.generate(pos[0], pos[1], pos[2], vertexColor, vector2(), vertexParamGenerator);
428
+ })
429
+ .flat();
430
+ }
431
+ getTriangleBuffer(color, vertexParamGenerator) {
432
+ return this.generateBuffer(this.triangleOrder, color, vertexParamGenerator);
433
+ }
434
+ getWireframeBuffer(color, vertexParamGenerator) {
435
+ return this.generateBuffer(this.wireframeOrder, color, vertexParamGenerator);
436
+ }
407
437
  recompute() {
408
438
  const normal = vector2(-this.params.to[1], this.params.to[0]);
409
439
  vec2.normalize(normal, normal);
@@ -421,7 +451,7 @@ export class PolygonGeometry extends Geometry {
421
451
  triangleOrder;
422
452
  params;
423
453
  constructor(points) {
424
- super();
454
+ super([], 'strip');
425
455
  this.wireframeOrder = [];
426
456
  this.triangleOrder = [];
427
457
  this.params = {
@@ -431,18 +461,48 @@ export class PolygonGeometry extends Geometry {
431
461
  }
432
462
  recompute() {
433
463
  this.vertices = this.params.points.map((point) => point.getPos());
434
- this.triangleOrder = lossyTriangulate(Array(this.vertices.length)
464
+ this.triangleOrder = lossyTriangulateStrip(Array(this.vertices.length)
435
465
  .fill(0)
436
- .map((_, index) => index)).flat();
466
+ .map((_, index) => index));
437
467
  this.wireframeOrder = triangulateWireFrameOrder(this.vertices.length);
438
468
  }
439
469
  getTriangleBuffer(color) {
440
470
  return this.triangleOrder
441
471
  .map((vertexIndex) => {
442
- const vertex = cloneBuf(this.vertices[vertexIndex]);
443
- vec3.transformMat4(vertex, this.matrix, vertex);
472
+ const vertex = this.vertices[vertexIndex];
444
473
  return bufferGenerator.generate(vertex[0], vertex[1], 0, this.params.points[vertexIndex].getColor() || color);
445
474
  })
446
475
  .flat();
447
476
  }
448
477
  }
478
+ export class TraceLines2dGeometry extends Geometry {
479
+ wireframeOrder = [];
480
+ triangleOrder = [];
481
+ params;
482
+ constructor(maxLen) {
483
+ super([], 'strip');
484
+ this.params = {
485
+ vertices: [],
486
+ maxLength: maxLen || null
487
+ };
488
+ this.wireframeOrder = [];
489
+ }
490
+ recompute() { }
491
+ getWireframeBuffer(color, vertexParamGenerator) {
492
+ return this.params.vertices
493
+ .map((item) => {
494
+ const pos = item.getPos();
495
+ return bufferGenerator.generate(pos[0], pos[1], pos[2], item.getColor() || color, vector2(), vertexParamGenerator);
496
+ })
497
+ .flat();
498
+ }
499
+ getWireframeVertexCount() {
500
+ return this.params.vertices.length;
501
+ }
502
+ addVertex(vert) {
503
+ this.params.vertices.push(vert);
504
+ if (this.params.maxLength && this.params.vertices.length > this.params.maxLength) {
505
+ this.params.vertices.shift();
506
+ }
507
+ }
508
+ }
@@ -1,62 +1,87 @@
1
1
  /// <reference types="@webgpu/types" />
2
- import { Camera } from './simulation.js';
3
- import type { Vector2, Vector3, LerpFunc, VertexColorMap, ElementRotation, Mat4, AnySimulationElement, VertexParamGeneratorInfo } from './types.js';
2
+ import type { Vector2, Vector3, LerpFunc, VertexColorMap, Mat4, AnySimulationElement, VertexParamGeneratorInfo } from './types.js';
4
3
  import { Vertex, Color } from './utils.js';
5
- import { BlankGeometry, CircleGeometry, CubeGeometry, Geometry, Line2dGeometry, Line3dGeometry, PlaneGeometry, PolygonGeometry, Spline2dGeometry, SquareGeometry } from './geometry.js';
6
- import { VertexCache } from './internalUtils.js';
7
- export declare abstract class SimulationElement<T extends Vector2 | Vector3 = Vector3> {
8
- protected abstract pos: T;
9
- protected abstract geometry: Geometry<any>;
4
+ import { BlankGeometry, CircleGeometry, CubeGeometry, Geometry, Line2dGeometry, Line3dGeometry, PlaneGeometry, PolygonGeometry, Spline2dGeometry, SquareGeometry, TraceLines2dGeometry as TraceLinesGeometry } from './geometry.js';
5
+ import { SimSceneObjInfo, VertexCache } from './internalUtils.js';
6
+ export declare abstract class SimulationElement3d {
7
+ private children;
8
+ private uniformBuffer;
9
+ protected parent: SimulationElement3d | null;
10
+ protected centerOffset: Vector3;
11
+ protected rotationOffset: Vector3;
12
+ protected pos: Vector3;
13
+ protected abstract geometry: Geometry<object>;
10
14
  protected color: Color;
11
15
  protected wireframe: boolean;
12
16
  protected vertexCache: VertexCache;
13
- protected rotation: ElementRotation<T>;
17
+ protected rotation: Vector3;
18
+ protected modelMatrix: Mat4;
19
+ isInstance: boolean;
14
20
  isInstanced: boolean;
21
+ is3d: boolean;
22
+ isEmpty: boolean;
15
23
  /**
16
24
  * @param pos - Expected to be adjusted to devicePixelRatio before reaching constructor
17
25
  */
18
- constructor(color: Color | undefined, rotation: ElementRotation<T>);
26
+ constructor(pos: Vector3, rotation: Vector3, color?: Color);
27
+ add(el: SimulationElement3d, id?: string): void;
28
+ remove(el: SimulationElement3d): void;
29
+ getChildren(): SimulationElement3d[];
30
+ getChildrenInfos(): SimSceneObjInfo[];
31
+ hasChildren(): boolean;
32
+ setParent(parent: SimulationElement3d): void;
33
+ getParent(): SimulationElement3d | null;
34
+ setCenterOffset(offset: Vector3): void;
35
+ setRotationOffset(offset: Vector3): void;
36
+ resetCenterOffset(): void;
37
+ propagateDevice(device: GPUDevice): void;
38
+ getModelMatrix(): Mat4;
39
+ getUniformBuffer(device: GPUDevice, mat: Mat4): GPUBuffer;
40
+ protected mirrorParentTransforms3d(mat: Mat4): void;
41
+ protected updateModelMatrix3d(): void;
42
+ protected mirrorParentTransforms2d(mat: Mat4): void;
43
+ protected updateModelMatrix2d(): void;
19
44
  getGeometryType(): "list" | "strip";
20
45
  setWireframe(wireframe: boolean): void;
21
46
  isWireframe(): boolean;
22
47
  getColor(): Color;
23
- getPos(): T;
24
- getRotation(): ElementRotation<T>;
48
+ getPos(): Vector3;
49
+ getAbsolutePos(): Vector3;
50
+ getRotation(): Vector3;
51
+ getCenterOffset(): Vector3;
25
52
  fill(newColor: Color, t?: number, f?: LerpFunc): Promise<void>;
26
- abstract move(amount: T, t?: number, f?: LerpFunc): Promise<void>;
27
- abstract moveTo(pos: T, t?: number, f?: LerpFunc): Promise<void>;
28
- abstract rotate(amount: ElementRotation<T>, t?: number, f?: LerpFunc): Promise<void>;
29
- abstract rotateTo(rotation: ElementRotation<T>, t?: number, f?: LerpFunc): Promise<void>;
30
- protected abstract updateMatrix(camera: Camera): void;
53
+ private moveChildren;
54
+ move(amount: Vector3, t?: number, f?: LerpFunc, fromDevicePixelRatio?: boolean): Promise<void>;
55
+ moveTo(pos: Vector3, t?: number, f?: LerpFunc, fromDevicePixelRatio?: boolean): Promise<void>;
56
+ rotateChildrenTo(angle: Vector3): void;
57
+ rotateChildren(angle: Vector3): void;
58
+ rotate(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
59
+ rotateTo(rot: Vector3, t?: number, f?: LerpFunc): Promise<void>;
31
60
  getVertexCount(): number;
32
- protected defaultUpdateMatrix(camera: Camera): void;
33
- getBuffer(camera: Camera, vertexParamGenerator?: VertexParamGeneratorInfo): number[];
61
+ getBuffer(vertexParamGenerator?: VertexParamGeneratorInfo): Float32Array | number[];
62
+ protected abstract onDeviceChange(device: GPUDevice): void;
34
63
  }
35
- export declare abstract class SimulationElement3d extends SimulationElement {
36
- protected pos: Vector3;
37
- protected rotation: Vector3;
64
+ export declare class EmptyElement extends SimulationElement3d {
65
+ protected geometry: BlankGeometry;
66
+ private label;
67
+ isEmpty: boolean;
68
+ constructor(label?: string);
69
+ getLabel(): string | null;
70
+ protected onDeviceChange(_device: GPUDevice): void;
71
+ }
72
+ export declare abstract class SimulationElement2d extends SimulationElement3d {
38
73
  is3d: boolean;
39
- constructor(pos: Vector3, rotation?: Vector3, color?: Color);
40
- rotate(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
41
- rotateTo(rot: Vector3, t?: number, f?: LerpFunc): Promise<void>;
42
- move(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
43
- moveTo(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
44
- }
45
- export declare abstract class SimulationElement2d extends SimulationElement<Vector2> {
46
- protected pos: Vector2;
47
- rotation: number;
48
- constructor(pos: Vector2, rotation?: number, color?: Color);
49
- rotate(rotation: number, t?: number, f?: LerpFunc): Promise<void>;
50
- rotateTo(newRotation: number, t?: number, f?: LerpFunc): Promise<void>;
51
- move(amount: Vector2, t?: number, f?: LerpFunc): Promise<void>;
52
- moveTo(newPos: Vector2, t?: number, f?: LerpFunc): Promise<void>;
74
+ constructor(pos: Vector2, rotation?: Vector3, color?: Color);
75
+ rotate2d(amount: number, t?: number, f?: LerpFunc): Promise<void>;
76
+ rotateTo2d(rot: number, t?: number, f?: LerpFunc): Promise<void>;
77
+ getModelMatrix(): Mat4;
53
78
  }
54
79
  export declare class Plane extends SimulationElement3d {
55
80
  protected geometry: PlaneGeometry;
56
81
  points: Vertex[];
57
82
  constructor(pos: Vector3, points: Vertex[], color?: Color, rotation?: Vector3);
58
83
  setPoints(newPoints: Vertex[]): void;
59
- protected updateMatrix(camera: Camera): void;
84
+ protected onDeviceChange(_device: GPUDevice): void;
60
85
  }
61
86
  export declare class Square extends SimulationElement2d {
62
87
  protected geometry: SquareGeometry;
@@ -68,6 +93,8 @@ export declare class Square extends SimulationElement2d {
68
93
  * @param vertexColors{Record<number, Color>} - 0 is top left vertex, numbers increase clockwise
69
94
  */
70
95
  constructor(pos: Vector2, width: number, height: number, color?: Color, rotation?: number, centerOffset?: Vector2, vertexColors?: VertexColorMap);
96
+ setOffset(offset: Vector2): void;
97
+ setOffsetInplace(offset: Vector2): void;
71
98
  private cloneColorMap;
72
99
  setVertexColors(newColorMap: VertexColorMap, t?: number, f?: LerpFunc): Promise<void>;
73
100
  scaleWidth(amount: number, t?: number, f?: LerpFunc): Promise<void>;
@@ -75,7 +102,7 @@ export declare class Square extends SimulationElement2d {
75
102
  scale(amount: number, t?: number, f?: LerpFunc): Promise<void>;
76
103
  setWidth(num: number, t?: number, f?: LerpFunc): Promise<void>;
77
104
  setHeight(num: number, t?: number, f?: LerpFunc): Promise<void>;
78
- protected updateMatrix(camera: Camera): void;
105
+ protected onDeviceChange(_device: GPUDevice): void;
79
106
  }
80
107
  export declare class Circle extends SimulationElement2d {
81
108
  protected geometry: CircleGeometry;
@@ -84,7 +111,7 @@ export declare class Circle extends SimulationElement2d {
84
111
  constructor(pos: Vector2, radius: number, color?: Color, detail?: number);
85
112
  setRadius(num: number, t?: number, f?: LerpFunc): Promise<void>;
86
113
  scale(amount: number, t?: number, f?: LerpFunc): Promise<void>;
87
- protected updateMatrix(camera: Camera): void;
114
+ protected onDeviceChange(_device: GPUDevice): void;
88
115
  }
89
116
  export declare class Polygon extends SimulationElement2d {
90
117
  protected geometry: PolygonGeometry;
@@ -92,7 +119,7 @@ export declare class Polygon extends SimulationElement2d {
92
119
  constructor(pos: Vector2, points: Vertex[], color?: Color, rotation?: number);
93
120
  getVertices(): Vertex[];
94
121
  setVertices(newVertices: Vertex[], t?: number, f?: LerpFunc): Promise<void>;
95
- protected updateMatrix(camera: Camera): void;
122
+ protected onDeviceChange(_device: GPUDevice): void;
96
123
  }
97
124
  export declare class Line3d extends SimulationElement3d {
98
125
  protected geometry: Line3dGeometry;
@@ -101,16 +128,16 @@ export declare class Line3d extends SimulationElement3d {
101
128
  constructor(pos: Vertex, to: Vertex, thickness: number);
102
129
  setStart(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
103
130
  setEnd(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
104
- protected updateMatrix(camera: Camera): void;
131
+ protected onDeviceChange(_device: GPUDevice): void;
105
132
  }
106
133
  export declare class Line2d extends SimulationElement2d {
107
134
  protected geometry: Line2dGeometry;
108
135
  private to;
109
136
  private thickness;
110
137
  constructor(from: Vertex, to: Vertex, thickness?: number);
111
- setStart(pos: Vector2, t?: number, f?: LerpFunc): Promise<void>;
112
- setEnd(pos: Vector2, t?: number, f?: LerpFunc): Promise<void>;
113
- protected updateMatrix(camera: Camera): void;
138
+ setStart(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
139
+ setEnd(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
140
+ protected onDeviceChange(_device: GPUDevice): void;
114
141
  }
115
142
  export declare class Cube extends SimulationElement3d {
116
143
  protected geometry: CubeGeometry;
@@ -122,7 +149,7 @@ export declare class Cube extends SimulationElement3d {
122
149
  setHeight(height: number, t?: number, f?: LerpFunc): Promise<void>;
123
150
  setDepth(depth: number, t?: number, f?: LerpFunc): Promise<void>;
124
151
  scale(amount: number, t?: number, f?: LerpFunc): Promise<void>;
125
- protected updateMatrix(camera: Camera): void;
152
+ protected onDeviceChange(_device: GPUDevice): void;
126
153
  }
127
154
  export declare class BezierCurve2d {
128
155
  private points;
@@ -175,27 +202,39 @@ export declare class Spline2d extends SimulationElement2d {
175
202
  setThickness(thickness: number, t?: number, f?: LerpFunc): Promise<void>;
176
203
  interpolateSlope(t: number): Vector2[] | readonly [Vector2, Vector2];
177
204
  interpolate(t: number): Vector2;
178
- protected updateMatrix(camera: Camera): void;
205
+ protected onDeviceChange(_device: GPUDevice): void;
179
206
  }
180
207
  export declare class Instance<T extends AnySimulationElement> extends SimulationElement3d {
181
208
  protected geometry: BlankGeometry;
182
209
  private obj;
183
210
  private instanceMatrix;
184
211
  private matrixBuffer;
185
- private device;
186
212
  private baseMat;
187
- private needsRemap;
213
+ isInstance: boolean;
188
214
  constructor(obj: T, numInstances: number);
189
215
  setNumInstances(numInstances: number): void;
190
216
  setInstance(instance: number, transformation: Mat4): void;
191
217
  private mapBuffer;
192
- private setMatrixBuffer;
193
218
  getInstances(): Mat4[];
194
219
  getNumInstances(): number;
195
- setDevice(device: GPUDevice): void;
196
- getMatrixBuffer(): GPUBuffer | null;
220
+ getMatrixBuffer(device: GPUDevice): GPUBuffer;
197
221
  getVertexCount(): number;
198
222
  getGeometryType(): "list" | "strip";
199
- protected updateMatrix(_: Camera): void;
200
- getBuffer(camera: Camera): number[];
223
+ getBuffer(): Float32Array | number[];
224
+ protected onDeviceChange(device: GPUDevice): void;
225
+ getModelMatrix(): Mat4;
226
+ }
227
+ export declare class TraceLines2d extends SimulationElement2d {
228
+ protected geometry: TraceLinesGeometry;
229
+ constructor(color?: Color, maxLen?: number);
230
+ addPoint(point: Vector2 | Vector3, color?: Color): void;
231
+ isWireframe(): boolean;
232
+ protected onDeviceChange(_: GPUDevice): void;
233
+ }
234
+ export declare class TraceLines3d extends SimulationElement3d {
235
+ protected geometry: TraceLinesGeometry;
236
+ constructor(color?: Color, maxLen?: number);
237
+ addPoint(point: Vector2 | Vector3, color?: Color): void;
238
+ isWireframe(): boolean;
239
+ protected onDeviceChange(_: GPUDevice): void;
201
240
  }