simulationjsv2 0.7.3 → 0.8.0
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/README.md +1 -3
- package/TODO.md +6 -5
- package/dist/buffers.d.ts +13 -0
- package/dist/buffers.js +44 -0
- package/dist/constants.d.ts +0 -6
- package/dist/constants.js +1 -6
- package/dist/geometry.d.ts +23 -41
- package/dist/geometry.js +85 -204
- package/dist/globals.d.ts +26 -0
- package/dist/globals.js +51 -0
- package/dist/graphics.d.ts +44 -29
- package/dist/graphics.js +252 -229
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internalUtils.d.ts +14 -31
- package/dist/internalUtils.js +83 -153
- package/dist/materials.d.ts +20 -0
- package/dist/materials.js +51 -0
- package/dist/shaders.d.ts +37 -0
- package/dist/shaders.js +330 -0
- package/dist/simulation.d.ts +7 -24
- package/dist/simulation.js +72 -338
- package/dist/types.d.ts +51 -45
- package/dist/utils.d.ts +8 -3
- package/dist/utils.js +36 -8
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
import { SimulationElement3d, SplinePoint2d } from './graphics.js';
|
|
2
3
|
import { AnySimulationElement, FloatArray, Mat4, Vector2, Vector3, Vector4 } from './types.js';
|
|
3
4
|
import { SimSceneObjInfo } from './internalUtils.js';
|
|
5
|
+
import { Shader } from './shaders.js';
|
|
4
6
|
export declare class Color {
|
|
5
7
|
r: number;
|
|
6
8
|
g: number;
|
|
7
9
|
b: number;
|
|
8
10
|
a: number;
|
|
9
11
|
constructor(r?: number, g?: number, b?: number, a?: number);
|
|
12
|
+
static fromVec4(vec: Vector4): Color;
|
|
10
13
|
clone(): Color;
|
|
11
14
|
toBuffer(): readonly [number, number, number, number];
|
|
12
15
|
toVec4(): Vector4;
|
|
@@ -17,6 +20,8 @@ export declare class Color {
|
|
|
17
20
|
a: number;
|
|
18
21
|
};
|
|
19
22
|
diff(color: Color): Color;
|
|
23
|
+
isTransparent(): boolean;
|
|
24
|
+
setValues(color: Color): void;
|
|
20
25
|
}
|
|
21
26
|
export declare class Vertex {
|
|
22
27
|
private pos;
|
|
@@ -33,7 +38,6 @@ export declare class Vertex {
|
|
|
33
38
|
setY(y: number): void;
|
|
34
39
|
setZ(z: number): void;
|
|
35
40
|
clone(): Vertex;
|
|
36
|
-
toBuffer(defaultColor: Color): number[];
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* @param onFrame - called every frame until the animation is finished
|
|
@@ -64,7 +68,6 @@ export declare function vector2(x?: number, y?: number): Vector2;
|
|
|
64
68
|
export declare function matrix4(): Mat4;
|
|
65
69
|
export declare function vector3FromVector2(vec: Vector2): Vector3;
|
|
66
70
|
export declare function vector2FromVector3(vec: Vector3): Vector2;
|
|
67
|
-
export declare function colorFromVector4(vec: Vector4): Color;
|
|
68
71
|
export declare function randomInt(range: number, min?: number): number;
|
|
69
72
|
export declare function randomColor(a?: number): Color;
|
|
70
73
|
export declare function vertex(x?: number, y?: number, z?: number, color?: Color, uv?: Vector2): Vertex;
|
|
@@ -81,4 +84,6 @@ export declare function distance3d(vector1: Vector3, vector2: Vector3): number;
|
|
|
81
84
|
export declare function toSceneObjInfo(el: AnySimulationElement, id?: string): SimSceneObjInfo;
|
|
82
85
|
export declare function toSceneObjInfoMany(el: AnySimulationElement[], id?: (string | undefined)[]): SimSceneObjInfo[];
|
|
83
86
|
export declare function interpolateColors(colors: Color[], t: number): Color;
|
|
87
|
+
export declare function createBindGroup(shader: Shader, bindGroupIndex: number, buffers: GPUBuffer[]): GPUBindGroup;
|
|
88
|
+
export declare function writeUniformWorldMatrix(el: SimulationElement3d): void;
|
|
84
89
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { mat4, vec2, vec3, vec4 } from 'wgpu-matrix';
|
|
2
2
|
import { SplinePoint2d } from './graphics.js';
|
|
3
|
-
import { SimSceneObjInfo
|
|
3
|
+
import { SimSceneObjInfo } from './internalUtils.js';
|
|
4
|
+
import { globalInfo } from './globals.js';
|
|
5
|
+
import { orthogonalMatrix, worldProjectionMatrix } from './simulation.js';
|
|
6
|
+
import { worldProjMatOffset } from './constants.js';
|
|
4
7
|
export class Color {
|
|
5
8
|
r; // 0 - 255
|
|
6
9
|
g; // 0 - 255
|
|
@@ -12,6 +15,9 @@ export class Color {
|
|
|
12
15
|
this.b = b;
|
|
13
16
|
this.a = a;
|
|
14
17
|
}
|
|
18
|
+
static fromVec4(vec) {
|
|
19
|
+
return new Color(vec[0], vec[1], vec[2], vec[3]);
|
|
20
|
+
}
|
|
15
21
|
clone() {
|
|
16
22
|
return new Color(this.r, this.g, this.b, this.a);
|
|
17
23
|
}
|
|
@@ -32,6 +38,15 @@ export class Color {
|
|
|
32
38
|
diff(color) {
|
|
33
39
|
return new Color(this.r - color.r, this.g - color.g, this.b - color.b, this.a - color.a);
|
|
34
40
|
}
|
|
41
|
+
isTransparent() {
|
|
42
|
+
return this.a < 1;
|
|
43
|
+
}
|
|
44
|
+
setValues(color) {
|
|
45
|
+
this.r = color.r;
|
|
46
|
+
this.g = color.g;
|
|
47
|
+
this.b = color.b;
|
|
48
|
+
this.a = color.a;
|
|
49
|
+
}
|
|
35
50
|
}
|
|
36
51
|
export class Vertex {
|
|
37
52
|
pos;
|
|
@@ -39,7 +54,7 @@ export class Vertex {
|
|
|
39
54
|
uv;
|
|
40
55
|
constructor(x = 0, y = 0, z = 0, color, uv = vector2()) {
|
|
41
56
|
this.pos = vector3(x, y, z);
|
|
42
|
-
this.color = color
|
|
57
|
+
this.color = color ?? null;
|
|
43
58
|
this.uv = uv;
|
|
44
59
|
}
|
|
45
60
|
getPos() {
|
|
@@ -72,9 +87,6 @@ export class Vertex {
|
|
|
72
87
|
clone() {
|
|
73
88
|
return new Vertex(this.pos[0], this.pos[1], this.pos[2], this.color?.clone(), cloneBuf(this.uv));
|
|
74
89
|
}
|
|
75
|
-
toBuffer(defaultColor) {
|
|
76
|
-
return bufferGenerator.generate(this.pos[0], this.pos[1], this.pos[2], this.color || defaultColor, this.uv);
|
|
77
|
-
}
|
|
78
90
|
}
|
|
79
91
|
/**
|
|
80
92
|
* @param onFrame - called every frame until the animation is finished
|
|
@@ -206,9 +218,6 @@ export function vector3FromVector2(vec) {
|
|
|
206
218
|
export function vector2FromVector3(vec) {
|
|
207
219
|
return vector2(vec[0], vec[1]);
|
|
208
220
|
}
|
|
209
|
-
export function colorFromVector4(vec) {
|
|
210
|
-
return new Color(vec[0], vec[1], vec[2], vec[3]);
|
|
211
|
-
}
|
|
212
221
|
export function randomInt(range, min = 0) {
|
|
213
222
|
return Math.floor(Math.random() * (range - min)) + min;
|
|
214
223
|
}
|
|
@@ -284,3 +293,22 @@ export function interpolateColors(colors, t) {
|
|
|
284
293
|
res.a += diff.a;
|
|
285
294
|
return res;
|
|
286
295
|
}
|
|
296
|
+
export function createBindGroup(shader, bindGroupIndex, buffers) {
|
|
297
|
+
const device = globalInfo.errorGetDevice();
|
|
298
|
+
const layout = shader.getBindGroupLayouts()[bindGroupIndex];
|
|
299
|
+
return device.createBindGroup({
|
|
300
|
+
layout: layout,
|
|
301
|
+
entries: buffers.map((buffer, index) => ({
|
|
302
|
+
binding: index,
|
|
303
|
+
resource: {
|
|
304
|
+
buffer
|
|
305
|
+
}
|
|
306
|
+
}))
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
export function writeUniformWorldMatrix(el) {
|
|
310
|
+
const device = globalInfo.errorGetDevice();
|
|
311
|
+
const uniformBuffer = el.getUniformBuffer();
|
|
312
|
+
const projBuf = el.is3d ? worldProjectionMatrix : orthogonalMatrix;
|
|
313
|
+
device.queue.writeBuffer(uniformBuffer, worldProjMatOffset, projBuf.buffer, projBuf.byteOffset, projBuf.byteLength);
|
|
314
|
+
}
|