simulationjsv2 0.4.1 → 0.4.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.
@@ -27,6 +27,8 @@ export declare class Simulation {
27
27
  start(): void;
28
28
  stop(): void;
29
29
  setBackground(color: Color): void;
30
+ getScene(): SimSceneObjInfo[];
31
+ getSceneObjects(): SimulationElement<Vector3 | Vector2>[];
30
32
  private propagateDevice;
31
33
  render(device: GPUDevice, ctx: GPUCanvasContext): void;
32
34
  private renderScene;
@@ -42,6 +44,7 @@ export declare class SceneCollection extends SimulationElement3d {
42
44
  setWireframe(_: boolean): void;
43
45
  getName(): string;
44
46
  getScene(): SimSceneObjInfo[];
47
+ getSceneObjects(): SimulationElement<Vector3 | Vector2>[];
45
48
  setSceneObjects(newScene: SimulationElement<any>[]): void;
46
49
  setScene(newScene: SimSceneObjInfo[]): void;
47
50
  add(el: SimulationElement<any>): void;
@@ -1,9 +1,9 @@
1
1
  import { vec3 } from 'wgpu-matrix';
2
2
  import { SimulationElement3d } from './graphics.js';
3
3
  import { BUF_LEN } from './constants.js';
4
- import { Color, transitionValues, vector2, vector3 } from './utils.js';
4
+ import { Color, toSceneObjInfoMany, transitionValues, vector2, vector3 } from './utils.js';
5
5
  import { BlankGeometry } from './geometry.js';
6
- import { SimSceneObjInfo, addObject, buildDepthTexture, buildMultisampleTexture, buildProjectionMatrix, createPipeline, getOrthoMatrix, getTotalVertices, getTransformationMatrix, logger, removeObject, removeObjectId } from './internalUtils.js';
6
+ import { addObject, buildDepthTexture, buildMultisampleTexture, buildProjectionMatrix, createPipeline, getOrthoMatrix, getTotalVertices, getTransformationMatrix, logger, removeObject, removeObjectId } from './internalUtils.js';
7
7
  const shader = `
8
8
  struct Uniforms {
9
9
  modelViewProjectionMatrix : mat4x4<f32>,
@@ -210,6 +210,12 @@ export class Simulation {
210
210
  setBackground(color) {
211
211
  this.bgColor = color;
212
212
  }
213
+ getScene() {
214
+ return this.scene;
215
+ }
216
+ getSceneObjects() {
217
+ return this.scene.map((item) => item.getObj());
218
+ }
213
219
  propagateDevice(device) {
214
220
  for (let i = 0; i < this.scene.length; i++) {
215
221
  const obj = this.scene[i].getObj();
@@ -495,8 +501,11 @@ export class SceneCollection extends SimulationElement3d {
495
501
  getScene() {
496
502
  return this.scene;
497
503
  }
504
+ getSceneObjects() {
505
+ return this.scene.map((item) => item.getObj());
506
+ }
498
507
  setSceneObjects(newScene) {
499
- this.scene = newScene.map((item) => new SimSceneObjInfo(item));
508
+ this.scene = toSceneObjInfoMany(newScene);
500
509
  }
501
510
  setScene(newScene) {
502
511
  this.scene = newScene;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { SplinePoint2d } from './graphics.js';
1
+ import { SimulationElement, SplinePoint2d } from './graphics.js';
2
2
  import { FloatArray, Mat4, Shift, Vector2, Vector3, Vector4 } from './types.js';
3
+ import { SimSceneObjInfo } from './internalUtils.js';
3
4
  export declare class Color {
4
5
  r: number;
5
6
  g: number;
@@ -50,6 +51,12 @@ export declare function linearStep(t: number): number;
50
51
  export declare function easeInOutExpo(t: number): number;
51
52
  export declare function easeInOutQuart(t: number): number;
52
53
  export declare function easeInOutQuad(t: number): number;
54
+ export declare function easeInQuad(x: number): number;
55
+ export declare function easeOutQuad(x: number): number;
56
+ export declare function easeInQuart(x: number): number;
57
+ export declare function easeOutQuart(x: number): number;
58
+ export declare function easeInExpo(x: number): number;
59
+ export declare function easeOutExpo(x: number): number;
53
60
  export declare function cloneBuf<T extends FloatArray>(buf: T): T;
54
61
  export declare function vector4(x?: number, y?: number, z?: number, w?: number): Vector4;
55
62
  export declare function vector3(x?: number, y?: number, z?: number): Vector3;
@@ -71,3 +78,5 @@ export declare function continuousSplinePoint2d(end: Vertex, control: Vector2, d
71
78
  export declare function waitFor(t: number): Promise<unknown>;
72
79
  export declare function distance2d(vector1: Vector2, vector2: Vector2): number;
73
80
  export declare function distance3d(vector1: Vector3, vector2: Vector3): number;
81
+ export declare function toSceneObjInfo(el: SimulationElement<any>, id?: string): SimSceneObjInfo;
82
+ export declare function toSceneObjInfoMany(el: SimulationElement<any>[], id?: (string | undefined)[]): SimSceneObjInfo[];
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mat4, vec2, vec3, vec4 } from 'wgpu-matrix';
2
2
  import { SplinePoint2d } from './graphics.js';
3
- import { bufferGenerator } from './internalUtils.js';
3
+ import { SimSceneObjInfo, bufferGenerator } from './internalUtils.js';
4
4
  export class Color {
5
5
  r; // 0 - 255
6
6
  g; // 0 - 255
@@ -168,6 +168,24 @@ export function easeInOutQuart(t) {
168
168
  export function easeInOutQuad(t) {
169
169
  return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
170
170
  }
171
+ export function easeInQuad(x) {
172
+ return x * x;
173
+ }
174
+ export function easeOutQuad(x) {
175
+ return 1 - (1 - x) * (1 - x);
176
+ }
177
+ export function easeInQuart(x) {
178
+ return x * x * x * x;
179
+ }
180
+ export function easeOutQuart(x) {
181
+ return 1 - Math.pow(1 - x, 4);
182
+ }
183
+ export function easeInExpo(x) {
184
+ return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
185
+ }
186
+ export function easeOutExpo(x) {
187
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
188
+ }
171
189
  export function cloneBuf(buf) {
172
190
  return new Float32Array(buf);
173
191
  }
@@ -236,3 +254,9 @@ export function distance2d(vector1, vector2) {
236
254
  export function distance3d(vector1, vector2) {
237
255
  return vec3.distance(vector1, vector2);
238
256
  }
257
+ export function toSceneObjInfo(el, id) {
258
+ return new SimSceneObjInfo(el, id);
259
+ }
260
+ export function toSceneObjInfoMany(el, id) {
261
+ return el.map((item, index) => toSceneObjInfo(item, id ? id[index] : undefined));
262
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Jackson Otto",
7
7
  "description": "A simple graphics library using WebGPU",
8
- "version": "0.4.1",
8
+ "version": "0.4.2",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./dist/index.js",