simulationjsv2 0.6.0 → 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 +9 -5
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/geometry.d.ts +11 -1
- package/dist/geometry.js +31 -0
- package/dist/graphics.d.ts +70 -19
- package/dist/graphics.js +274 -101
- package/dist/internalUtils.d.ts +9 -8
- package/dist/internalUtils.js +33 -44
- package/dist/settings.d.ts +7 -0
- package/dist/settings.js +9 -0
- package/dist/simulation.d.ts +30 -69
- package/dist/simulation.js +145 -261
- package/dist/types.d.ts +4 -0
- package/dist/utils.d.ts +8 -8
- package/dist/utils.js +13 -19
- package/package.json +1 -1
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,
|
|
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(),
|
|
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
|
-
|
|
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
|
|
89
|
-
* @param
|
|
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(
|
|
85
|
+
export function transitionValues(onFrame, adjustment, transitionLength, func) {
|
|
94
86
|
return new Promise((resolve) => {
|
|
95
87
|
if (transitionLength == 0) {
|
|
96
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
225
|
-
return new Vertex(x, y, z, color,
|
|
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);
|