simulationjsv2 0.6.0 → 0.7.2

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,13 +1,17 @@
1
1
  # TODO
2
2
 
3
- - [ ] Add animation status handle to transition values
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
4
11
  - [x] Change position/rotation to be matrix transform on gpu
5
12
  - [x] Add update square center offset position in-place + not
6
13
  - [x] Make getBuffer return cached Float32Array
7
14
  - [x] Make input buffer position vec3 not vec4
8
15
  - [x] Use line strip vertices for polygon buffers
9
16
  - [x] Scene collection wireframe
10
-
11
- ## Not Yet
12
-
13
- - [ ] Add rotateAround and rotateToAround methods to simulation element for absolute positioned vectors
17
+ - [ ] Add animation status handle to transition values
@@ -6,6 +6,8 @@ export declare const drawingInstancesOffset = 36;
6
6
  export declare const BUF_LEN: number;
7
7
  export declare const worldProjMatOffset = 0;
8
8
  export declare const modelProjMatOffset: number;
9
+ export declare const mat4ByteLength = 64;
9
10
  export declare const xAxis: import("./types.js").Vector3;
10
11
  export declare const yAxis: import("./types.js").Vector3;
11
12
  export declare const zAxis: import("./types.js").Vector3;
13
+ export declare const origin0: import("./types.js").Vector3;
package/dist/constants.js CHANGED
@@ -7,6 +7,8 @@ export const drawingInstancesOffset = 36;
7
7
  export const BUF_LEN = vertexSize / 4;
8
8
  export const worldProjMatOffset = 0;
9
9
  export const modelProjMatOffset = 4 * 16;
10
+ export const mat4ByteLength = 64;
10
11
  export const xAxis = vector3(1);
11
12
  export const yAxis = vector3(0, 1);
12
13
  export const zAxis = vector3(0, 0, 1);
14
+ export const origin0 = vector3();
@@ -1,4 +1,4 @@
1
- import { VertexParamGeneratorInfo, CircleGeometryParams, CubeGeometryParams, EmptyParams, PolygonGeometryParams, Spline2dGeometryParams, SquareGeometryParams, Vector2, Vector3, VertexColorMap, LineGeometryParams } 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> {
@@ -114,3 +114,13 @@ export declare class PolygonGeometry extends Geometry<PolygonGeometryParams> {
114
114
  recompute(): void;
115
115
  getTriangleBuffer(color: Color): number[];
116
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
@@ -475,3 +475,34 @@ export class PolygonGeometry extends Geometry {
475
475
  .flat();
476
476
  }
477
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,53 +1,77 @@
1
1
  /// <reference types="@webgpu/types" />
2
- import { Camera } from './simulation.js';
3
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 {
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;
8
12
  protected pos: Vector3;
9
- protected abstract geometry: Geometry<any>;
13
+ protected abstract geometry: Geometry<object>;
10
14
  protected color: Color;
11
15
  protected wireframe: boolean;
12
16
  protected vertexCache: VertexCache;
13
17
  protected rotation: Vector3;
14
18
  protected modelMatrix: Mat4;
15
- private uniformBuffer;
19
+ isInstance: boolean;
16
20
  isInstanced: boolean;
21
+ is3d: boolean;
22
+ isEmpty: boolean;
17
23
  /**
18
24
  * @param pos - Expected to be adjusted to devicePixelRatio before reaching constructor
19
25
  */
20
26
  constructor(pos: Vector3, rotation: Vector3, color?: Color);
21
- getModelMatrix(_: Camera): Mat4;
22
- getUniformBuffer(device: GPUDevice, mat: Mat4): GPUBuffer;
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
+ getModelMatrix(): Mat4;
38
+ getUniformBuffer(mat: Mat4): GPUBuffer;
39
+ protected mirrorParentTransforms3d(mat: Mat4): void;
23
40
  protected updateModelMatrix3d(): void;
41
+ protected mirrorParentTransforms2d(mat: Mat4): void;
42
+ protected updateModelMatrix2d(): void;
24
43
  getGeometryType(): "list" | "strip";
25
44
  setWireframe(wireframe: boolean): void;
26
45
  isWireframe(): boolean;
27
46
  getColor(): Color;
28
47
  getPos(): Vector3;
48
+ getAbsolutePos(): Vector3;
29
49
  getRotation(): Vector3;
50
+ getCenterOffset(): Vector3;
30
51
  fill(newColor: Color, t?: number, f?: LerpFunc): Promise<void>;
31
- move(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
32
- moveTo(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
52
+ private moveChildren;
53
+ move(amount: Vector3, t?: number, f?: LerpFunc, fromDevicePixelRatio?: boolean): Promise<void>;
54
+ moveTo(pos: Vector3, t?: number, f?: LerpFunc, fromDevicePixelRatio?: boolean): Promise<void>;
55
+ rotateChildrenTo(angle: Vector3): void;
56
+ rotateChildren(angle: Vector3): void;
33
57
  rotate(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
34
58
  rotateTo(rot: Vector3, t?: number, f?: LerpFunc): Promise<void>;
35
59
  getVertexCount(): number;
36
- protected defaultUpdateMatrix(_: Camera): void;
37
60
  getBuffer(vertexParamGenerator?: VertexParamGeneratorInfo): Float32Array | number[];
38
61
  }
39
- export declare abstract class SimulationElement3d extends SimulationElement {
40
- protected pos: Vector3;
41
- protected rotation: Vector3;
42
- is3d: boolean;
43
- constructor(pos: Vector3, rotation?: Vector3, color?: Color);
62
+ export declare class EmptyElement extends SimulationElement3d {
63
+ protected geometry: BlankGeometry;
64
+ private label;
65
+ isEmpty: boolean;
66
+ constructor(label?: string);
67
+ getLabel(): string | null;
44
68
  }
45
- export declare abstract class SimulationElement2d extends SimulationElement {
69
+ export declare abstract class SimulationElement2d extends SimulationElement3d {
70
+ is3d: boolean;
46
71
  constructor(pos: Vector2, rotation?: Vector3, color?: Color);
47
72
  rotate2d(amount: number, t?: number, f?: LerpFunc): Promise<void>;
48
73
  rotateTo2d(rot: number, t?: number, f?: LerpFunc): Promise<void>;
49
- private updateModelMatrix2d;
50
- getModelMatrix(camera: Camera): Mat4;
74
+ getModelMatrix(): Mat4;
51
75
  }
52
76
  export declare class Plane extends SimulationElement3d {
53
77
  protected geometry: PlaneGeometry;
@@ -174,16 +198,31 @@ export declare class Instance<T extends AnySimulationElement> extends Simulation
174
198
  private obj;
175
199
  private instanceMatrix;
176
200
  private matrixBuffer;
177
- private device;
178
201
  private baseMat;
202
+ private maxInstances;
203
+ isInstance: boolean;
179
204
  constructor(obj: T, numInstances: number);
180
205
  setNumInstances(numInstances: number): void;
181
206
  setInstance(instance: number, transformation: Mat4): void;
207
+ private allocBuffer;
182
208
  private mapBuffer;
183
209
  getInstances(): Mat4[];
184
210
  getNumInstances(): number;
185
- getMatrixBuffer(device: GPUDevice): GPUBuffer;
211
+ getMatrixBuffer(): GPUBuffer;
186
212
  getVertexCount(): number;
187
213
  getGeometryType(): "list" | "strip";
188
214
  getBuffer(): Float32Array | number[];
215
+ getModelMatrix(): Mat4;
216
+ }
217
+ export declare class TraceLines2d extends SimulationElement2d {
218
+ protected geometry: TraceLinesGeometry;
219
+ constructor(color?: Color, maxLen?: number);
220
+ addPoint(point: Vector2 | Vector3, color?: Color): void;
221
+ isWireframe(): boolean;
222
+ }
223
+ export declare class TraceLines3d extends SimulationElement3d {
224
+ protected geometry: TraceLinesGeometry;
225
+ constructor(color?: Color, maxLen?: number);
226
+ addPoint(point: Vector2 | Vector3, color?: Color): void;
227
+ isWireframe(): boolean;
189
228
  }