simulationjsv2 0.4.2 → 0.4.3
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/geometry.js +2 -2
- package/dist/internalUtils.d.ts +0 -1
- package/dist/internalUtils.js +1 -26
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +25 -0
- package/package.json +1 -1
package/dist/geometry.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mat4, vec2, vec3 } from 'wgpu-matrix';
|
|
2
|
-
import { cloneBuf, matrix4, vector2, vector2FromVector3, vector3, vector3FromVector2, vertex } from './utils.js';
|
|
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,
|
|
5
|
+
import { bufferGenerator, lossyTriangulate, triangulateWireFrameOrder } from './internalUtils.js';
|
|
6
6
|
export class Geometry {
|
|
7
7
|
vertices;
|
|
8
8
|
matrix;
|
package/dist/internalUtils.d.ts
CHANGED
|
@@ -58,7 +58,6 @@ declare class BufferGenerator {
|
|
|
58
58
|
export declare const bufferGenerator: BufferGenerator;
|
|
59
59
|
export declare function vector3ToPixelRatio(vec: Vector3): void;
|
|
60
60
|
export declare function vector2ToPixelRatio(vec: Vector2): void;
|
|
61
|
-
export declare function interpolateColors(colors: Color[], t: number): Color;
|
|
62
61
|
export declare function matrixFromRotation(rotation: Vector3): Mat4;
|
|
63
62
|
export declare function rotateMat4(mat: Mat4, rotation: Vector3): void;
|
|
64
63
|
export declare function createPipeline(device: GPUDevice, module: GPUShaderModule, bindGroupLayout: GPUBindGroupLayout, presentationFormat: GPUTextureFormat, entryPoint: string, topology: GPUPrimitiveTopology): GPURenderPipeline;
|
package/dist/internalUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mat4, vec3 } from 'wgpu-matrix';
|
|
2
2
|
import { BUF_LEN, colorOffset, drawingInstancesOffset, uvOffset, vertexSize } from './constants.js';
|
|
3
|
-
import {
|
|
3
|
+
import { vector2, vector3 } from './utils.js';
|
|
4
4
|
import { SimulationElement } from './graphics.js';
|
|
5
5
|
export class VertexCache {
|
|
6
6
|
vertices = [];
|
|
@@ -192,31 +192,6 @@ export function vector2ToPixelRatio(vec) {
|
|
|
192
192
|
vec[0] *= devicePixelRatio;
|
|
193
193
|
vec[1] *= devicePixelRatio;
|
|
194
194
|
}
|
|
195
|
-
export function interpolateColors(colors, t) {
|
|
196
|
-
t = Math.min(1, Math.max(0, t));
|
|
197
|
-
if (colors.length === 0)
|
|
198
|
-
return color();
|
|
199
|
-
if (colors.length === 1)
|
|
200
|
-
return colors[0];
|
|
201
|
-
const colorInterval = 1 / colors.length;
|
|
202
|
-
let index = Math.floor(t / colorInterval);
|
|
203
|
-
if (index >= colors.length)
|
|
204
|
-
index = colors.length - 1;
|
|
205
|
-
const from = index === colors.length - 1 ? colors[index - 1] : colors[index];
|
|
206
|
-
const to = index === colors.length - 1 ? colors[index] : colors[index + 1];
|
|
207
|
-
const diff = to.diff(from);
|
|
208
|
-
const scale = t / (colorInterval * colors.length);
|
|
209
|
-
diff.r *= scale;
|
|
210
|
-
diff.g *= scale;
|
|
211
|
-
diff.b *= scale;
|
|
212
|
-
diff.a *= scale;
|
|
213
|
-
const res = from.clone();
|
|
214
|
-
res.r += diff.r;
|
|
215
|
-
res.g += diff.g;
|
|
216
|
-
res.b += diff.b;
|
|
217
|
-
res.a += diff.a;
|
|
218
|
-
return res;
|
|
219
|
-
}
|
|
220
195
|
export function matrixFromRotation(rotation) {
|
|
221
196
|
let rotMatrix = mat4.identity();
|
|
222
197
|
mat4.rotateZ(rotMatrix, rotation[2], rotMatrix);
|
package/dist/utils.d.ts
CHANGED
|
@@ -80,3 +80,4 @@ export declare function distance2d(vector1: Vector2, vector2: Vector2): number;
|
|
|
80
80
|
export declare function distance3d(vector1: Vector3, vector2: Vector3): number;
|
|
81
81
|
export declare function toSceneObjInfo(el: SimulationElement<any>, id?: string): SimSceneObjInfo;
|
|
82
82
|
export declare function toSceneObjInfoMany(el: SimulationElement<any>[], id?: (string | undefined)[]): SimSceneObjInfo[];
|
|
83
|
+
export declare function interpolateColors(colors: Color[], t: number): Color;
|
package/dist/utils.js
CHANGED
|
@@ -260,3 +260,28 @@ export function toSceneObjInfo(el, id) {
|
|
|
260
260
|
export function toSceneObjInfoMany(el, id) {
|
|
261
261
|
return el.map((item, index) => toSceneObjInfo(item, id ? id[index] : undefined));
|
|
262
262
|
}
|
|
263
|
+
export function interpolateColors(colors, t) {
|
|
264
|
+
t = Math.min(1, Math.max(0, t));
|
|
265
|
+
if (colors.length === 0)
|
|
266
|
+
return color();
|
|
267
|
+
if (colors.length === 1)
|
|
268
|
+
return colors[0];
|
|
269
|
+
const colorInterval = 1 / colors.length;
|
|
270
|
+
let index = Math.floor(t / colorInterval);
|
|
271
|
+
if (index >= colors.length)
|
|
272
|
+
index = colors.length - 1;
|
|
273
|
+
const from = index === colors.length - 1 ? colors[index - 1] : colors[index];
|
|
274
|
+
const to = index === colors.length - 1 ? colors[index] : colors[index + 1];
|
|
275
|
+
const diff = to.diff(from);
|
|
276
|
+
const scale = t / (colorInterval * colors.length);
|
|
277
|
+
diff.r *= scale;
|
|
278
|
+
diff.g *= scale;
|
|
279
|
+
diff.b *= scale;
|
|
280
|
+
diff.a *= scale;
|
|
281
|
+
const res = from.clone();
|
|
282
|
+
res.r += diff.r;
|
|
283
|
+
res.g += diff.g;
|
|
284
|
+
res.b += diff.b;
|
|
285
|
+
res.a += diff.a;
|
|
286
|
+
return res;
|
|
287
|
+
}
|