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/dist/utils.js CHANGED
@@ -36,12 +36,10 @@ export class Color {
36
36
  export class Vertex {
37
37
  pos;
38
38
  color;
39
- is3d;
40
39
  uv;
41
- constructor(x = 0, y = 0, z = 0, color, is3dPoint = true, uv = vector2()) {
40
+ constructor(x = 0, y = 0, z = 0, color, uv = vector2()) {
42
41
  this.pos = vector3(x, y, z);
43
42
  this.color = color || null;
44
- this.is3d = is3dPoint;
45
43
  this.uv = uv;
46
44
  }
47
45
  getPos() {
@@ -71,38 +69,34 @@ export class Vertex {
71
69
  setZ(z) {
72
70
  this.pos[2] = z;
73
71
  }
74
- setIs3d(is3d) {
75
- this.is3d = is3d;
76
- }
77
72
  clone() {
78
- return new Vertex(this.pos[0], this.pos[1], this.pos[2], this.color?.clone(), this.is3d, cloneBuf(this.uv));
73
+ return new Vertex(this.pos[0], this.pos[1], this.pos[2], this.color?.clone(), cloneBuf(this.uv));
79
74
  }
80
75
  toBuffer(defaultColor) {
81
- if (this.is3d)
82
- return bufferGenerator.generate(this.pos[0], this.pos[1], this.pos[2], this.color || defaultColor, this.uv);
83
- else
84
- return bufferGenerator.generate(this.pos[0], this.pos[1], 0, this.color || defaultColor, this.uv);
76
+ return bufferGenerator.generate(this.pos[0], this.pos[1], this.pos[2], this.color || defaultColor, this.uv);
85
77
  }
86
78
  }
87
79
  /**
88
- * @param callback1 - called every frame until the animation is finished
89
- * @param callback2 - called after animation is finished (called immediately when t = 0)
80
+ * @param onFrame - called every frame until the animation is finished
81
+ * @param adjustment - called after animation is finished (called immediately when t = 0) if t > 0 it will only be called if `transformAdjustments` is enabled in settings
90
82
  * @param t - animation time (seconds)
91
83
  * @returns {Promise<void>}
92
84
  */
93
- export function transitionValues(callback1, callback2, transitionLength, func) {
85
+ export function transitionValues(onFrame, adjustment, transitionLength, func) {
94
86
  return new Promise((resolve) => {
95
87
  if (transitionLength == 0) {
96
- callback2();
88
+ adjustment();
97
89
  resolve();
98
90
  }
99
91
  else {
100
92
  let prevPercent = 0;
101
93
  let prevTime = Date.now();
94
+ let totalTime = 0;
102
95
  const step = (t, f) => {
103
96
  const newT = f(t);
104
97
  const deltaT = newT - prevPercent;
105
- callback1(deltaT, t);
98
+ onFrame(deltaT, t, totalTime);
99
+ totalTime += deltaT;
106
100
  prevPercent = newT;
107
101
  const now = Date.now();
108
102
  let diff = now - prevTime;
@@ -114,7 +108,7 @@ export function transitionValues(callback1, callback2, transitionLength, func) {
114
108
  window.requestAnimationFrame(() => step(t + inc, f));
115
109
  }
116
110
  else {
117
- callback2();
111
+ adjustment();
118
112
  resolve();
119
113
  }
120
114
  };
@@ -221,8 +215,8 @@ export function randomInt(range, min = 0) {
221
215
  export function randomColor(a = 1) {
222
216
  return new Color(randomInt(255), randomInt(255), randomInt(255), a);
223
217
  }
224
- export function vertex(x, y, z, color, is3dPoint, uv) {
225
- return new Vertex(x, y, z, color, is3dPoint, uv);
218
+ export function vertex(x, y, z, color, uv) {
219
+ return new Vertex(x, y, z, color, uv);
226
220
  }
227
221
  export function color(r, g, b, a) {
228
222
  return new Color(r, g, b, a);
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.6.0",
8
+ "version": "0.7.2",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./dist/index.js",