simulationjsv2 0.1.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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/graphics.d.ts +90 -0
- package/dist/graphics.js +505 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/simulation.d.ts +73 -0
- package/dist/simulation.js +541 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +59 -0
- package/package.json +30 -0
- package/types/constants.d.ts +1 -0
- package/types/graphics.d.ts +90 -0
- package/types/index.d.ts +3 -0
- package/types/types.d.ts +5 -0
- package/types/utils.d.ts +18 -0
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "simulationjsv2",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"author": "Jackson Otto",
|
|
7
|
+
"description": "A simple graphics library using WebGPU",
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "npx nodemon --watch src -e ts --exec 'npx tsc || exit 1'",
|
|
18
|
+
"test": "vite --port 3000",
|
|
19
|
+
"build": "npx tsc"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"nodemon": "^3.0.1",
|
|
23
|
+
"typescript": "^5.1.6",
|
|
24
|
+
"vite": "^4.4.4"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@webgpu/types": "^0.1.34",
|
|
28
|
+
"wgpu-matrix": "^2.5.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BUF_LEN = 11;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Camera, Color } from './simulation.js';
|
|
2
|
+
import type { Vector2, Vector3, LerpFunc, VertexColorMap } from './types.js';
|
|
3
|
+
declare class VertexCache {
|
|
4
|
+
private vertices;
|
|
5
|
+
private hasUpdated;
|
|
6
|
+
constructor();
|
|
7
|
+
setCache(vertices: number[]): void;
|
|
8
|
+
getCache(): number[];
|
|
9
|
+
updated(): void;
|
|
10
|
+
shouldUpdate(): boolean;
|
|
11
|
+
getVertexCount(): number;
|
|
12
|
+
}
|
|
13
|
+
declare class Vertex {
|
|
14
|
+
private readonly pos;
|
|
15
|
+
private readonly color;
|
|
16
|
+
private readonly is3d;
|
|
17
|
+
private readonly uv;
|
|
18
|
+
constructor(x?: number, y?: number, z?: number, color?: Color, is3dPoint?: boolean, uv?: Vector2);
|
|
19
|
+
getPos(): Vector3;
|
|
20
|
+
getColor(): Color | null;
|
|
21
|
+
toBuffer(defaultColor: Color): number[];
|
|
22
|
+
}
|
|
23
|
+
export declare abstract class SimulationElement {
|
|
24
|
+
private pos;
|
|
25
|
+
private color;
|
|
26
|
+
camera: Camera | null;
|
|
27
|
+
vertexCache: VertexCache;
|
|
28
|
+
constructor(pos: Vector3, color?: Color);
|
|
29
|
+
setPos(pos: Vector3): void;
|
|
30
|
+
getPos(): Vector3;
|
|
31
|
+
setCamera(camera: Camera): void;
|
|
32
|
+
fill(newColor: Color, t?: number, f?: LerpFunc): Promise<void>;
|
|
33
|
+
getColor(): Color;
|
|
34
|
+
move(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
|
|
35
|
+
moveTo(pos: Vector3, t?: number, f?: LerpFunc): Promise<void>;
|
|
36
|
+
abstract getBuffer(camera: Camera, force: boolean): number[];
|
|
37
|
+
}
|
|
38
|
+
export declare class Plane extends SimulationElement {
|
|
39
|
+
private points;
|
|
40
|
+
private rotation;
|
|
41
|
+
constructor(pos: Vector3, points: Vertex[], rotation?: Vector3, color?: Color);
|
|
42
|
+
setPoints(newPoints: Vertex[]): void;
|
|
43
|
+
rotate(amount: Vector3, t?: number, f?: LerpFunc): Promise<void>;
|
|
44
|
+
rotateTo(angle: Vector3, t?: number, f?: LerpFunc): Promise<void>;
|
|
45
|
+
getBuffer(_: Camera, force: boolean): number[];
|
|
46
|
+
}
|
|
47
|
+
export declare class Square extends SimulationElement {
|
|
48
|
+
private width;
|
|
49
|
+
private height;
|
|
50
|
+
private rotation;
|
|
51
|
+
private vertexColors;
|
|
52
|
+
/**
|
|
53
|
+
* @param vertexColors{Record<number, Color>} - 0 is top left vertex, numbers increase clockwise
|
|
54
|
+
*/
|
|
55
|
+
constructor(pos: Vector2, width: number, height: number, color?: Color, rotation?: number, vertexColors?: VertexColorMap);
|
|
56
|
+
scaleWidth(amount: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
57
|
+
scaleHeight(amount: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
58
|
+
scale(amount: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
59
|
+
setWidth(num: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
60
|
+
setHeight(num: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
61
|
+
rotate(rotation: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
62
|
+
setRotation(newRotation: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
63
|
+
getBuffer(camera: Camera, force: boolean): number[];
|
|
64
|
+
}
|
|
65
|
+
export declare class Circle extends SimulationElement {
|
|
66
|
+
private radius;
|
|
67
|
+
private detail;
|
|
68
|
+
constructor(pos: Vector2, radius: number, color?: Color, detail?: number);
|
|
69
|
+
setRadius(num: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
70
|
+
scale(amount: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
71
|
+
getBuffer(camera: Camera, force: boolean): number[];
|
|
72
|
+
}
|
|
73
|
+
export declare class Polygon extends SimulationElement {
|
|
74
|
+
private points;
|
|
75
|
+
private rotation;
|
|
76
|
+
constructor(pos: Vector3, points: Vector2[], color?: Color);
|
|
77
|
+
rotate(amount: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
78
|
+
rotateTo(num: number, t?: number, f?: LerpFunc): Promise<void>;
|
|
79
|
+
setPoints(newPoints: Vector3[], t?: number, f?: LerpFunc): Promise<void>;
|
|
80
|
+
getBuffer(): never[];
|
|
81
|
+
}
|
|
82
|
+
export declare function vector3(x?: number, y?: number, z?: number): Vector3;
|
|
83
|
+
export declare function vector2(x?: number, y?: number): Vector2;
|
|
84
|
+
export declare function vec3fromVec2(vec: Vector2): Vector3;
|
|
85
|
+
export declare function randomInt(range: number, min?: number): number;
|
|
86
|
+
export declare function randomColor(a?: number): Color;
|
|
87
|
+
export declare function vertex(x?: number, y?: number, z?: number, color?: Color): Vertex;
|
|
88
|
+
export declare function color(r?: number, g?: number, b?: number, a?: number): Color;
|
|
89
|
+
export declare function colorf(val: number, a?: number): Color;
|
|
90
|
+
export {};
|
package/types/index.d.ts
ADDED
package/types/types.d.ts
ADDED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SimulationElement } from './graphics.js';
|
|
2
|
+
import { Vector3 } from './types.js';
|
|
3
|
+
import { Camera } from './simulation.js';
|
|
4
|
+
export declare const buildProjectionMatrix: (aspectRatio: number, zNear?: number, zFar?: number) => any;
|
|
5
|
+
export declare const getTransformationMatrix: (pos: Vector3, rotation: Vector3, projectionMatrix: mat4) => Float32Array;
|
|
6
|
+
export declare const getOrthoMatrix: (screenSize: [number, number]) => Float32Array;
|
|
7
|
+
export declare const buildDepthTexture: (device: GPUDevice, width: number, height: number) => any;
|
|
8
|
+
export declare const applyElementToScene: (scene: SimulationElement[], camera: Camera | null, el: SimulationElement) => void;
|
|
9
|
+
declare class Logger {
|
|
10
|
+
constructor();
|
|
11
|
+
private fmt;
|
|
12
|
+
log(msg: string): void;
|
|
13
|
+
error(msg: string): Error;
|
|
14
|
+
warn(msg: string): void;
|
|
15
|
+
log_error(msg: string): void;
|
|
16
|
+
}
|
|
17
|
+
export declare const logger: Logger;
|
|
18
|
+
export {};
|