wgpu-kit 0.9.10
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 +96 -0
- package/README.zh-CN.md +99 -0
- package/dist/core/buffer.d.ts +21 -0
- package/dist/core/context.d.ts +15 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/kernel.d.ts +52 -0
- package/dist/core/layout.d.ts +32 -0
- package/dist/core/pingpong.d.ts +24 -0
- package/dist/core/raw.d.ts +9 -0
- package/dist/fields.js +585 -0
- package/dist/image.js +318 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +484 -0
- package/dist/interop/three.d.ts +37 -0
- package/dist/life.js +1407 -0
- package/dist/media.d.ts +22 -0
- package/dist/packs/fields/index.d.ts +27 -0
- package/dist/packs/image/index.d.ts +32 -0
- package/dist/packs/life/boids.d.ts +28 -0
- package/dist/packs/life/index.d.ts +9 -0
- package/dist/packs/life/map.d.ts +20 -0
- package/dist/packs/life/physarum.d.ts +28 -0
- package/dist/packs/life/tentacles.d.ts +29 -0
- package/dist/packs/life/turing.d.ts +40 -0
- package/dist/packs/particles/config.d.ts +47 -0
- package/dist/packs/particles/grid.d.ts +25 -0
- package/dist/packs/particles/index.d.ts +51 -0
- package/dist/packs/particles/presets.d.ts +25 -0
- package/dist/packs/particles/render.d.ts +20 -0
- package/dist/packs/particles/wgsl.d.ts +13 -0
- package/dist/particles.js +1245 -0
- package/dist/react/index.d.ts +18 -0
- package/dist/react.js +1289 -0
- package/dist/three.js +33 -0
- package/dist/vite.d.ts +38 -0
- package/dist/vite.js +30 -0
- package/package.json +93 -0
package/dist/three.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/interop/three.ts
|
|
2
|
+
function threePoints(sim, THREE, opts = {}) {
|
|
3
|
+
const { pos } = sim.buffers();
|
|
4
|
+
const count = pos.length;
|
|
5
|
+
const positions = new Float32Array(count * 3);
|
|
6
|
+
const geometry = new THREE.BufferGeometry();
|
|
7
|
+
const attr = new THREE.BufferAttribute(positions, 3);
|
|
8
|
+
geometry.setAttribute("position", attr);
|
|
9
|
+
const material = new THREE.PointsMaterial({
|
|
10
|
+
size: opts.size ?? 0.015,
|
|
11
|
+
color: opts.color ?? 9417983,
|
|
12
|
+
sizeAttenuation: true
|
|
13
|
+
});
|
|
14
|
+
const points = new THREE.Points(geometry, material);
|
|
15
|
+
return {
|
|
16
|
+
points,
|
|
17
|
+
async update() {
|
|
18
|
+
const data = await pos.read();
|
|
19
|
+
for (let i = 0; i < count; i++) {
|
|
20
|
+
positions[i * 3] = data[i * 2] ?? 0;
|
|
21
|
+
positions[i * 3 + 1] = data[i * 2 + 1] ?? 0;
|
|
22
|
+
positions[i * 3 + 2] = 0;
|
|
23
|
+
}
|
|
24
|
+
attr.needsUpdate = true;
|
|
25
|
+
},
|
|
26
|
+
dispose() {
|
|
27
|
+
sim.destroy();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
threePoints
|
|
33
|
+
};
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ElementKernel } from './core/kernel.ts';
|
|
2
|
+
/**
|
|
3
|
+
* kernel 热重载(Vite 插件 + 客户端助手)。
|
|
4
|
+
*
|
|
5
|
+
* 服务端:`wgpuKitHotReload()` 监听 *.wgsl 文件变化,把新代码推给浏览器;
|
|
6
|
+
* 客户端:`hotKernel(kernel, import.meta.hot, './sim.wgsl')` 收到推送后调 kernel.replace。
|
|
7
|
+
*
|
|
8
|
+
* 用法(配合 Vite 的 ?raw 导入):
|
|
9
|
+
* import simSrc from './sim.wgsl?raw';
|
|
10
|
+
* const k = elementKernel({ state: {...}, code: simSrc });
|
|
11
|
+
* hotKernel(k, import.meta.hot, './sim.wgsl');
|
|
12
|
+
*/
|
|
13
|
+
interface HotContext {
|
|
14
|
+
on(event: string, cb: (data: unknown) => void): void;
|
|
15
|
+
off?(event: string, cb: (data: unknown) => void): void;
|
|
16
|
+
}
|
|
17
|
+
interface ViteHotUpdateCtx {
|
|
18
|
+
file: string;
|
|
19
|
+
read(): string | Promise<string>;
|
|
20
|
+
server: {
|
|
21
|
+
ws: {
|
|
22
|
+
send(payload: {
|
|
23
|
+
type: string;
|
|
24
|
+
event: string;
|
|
25
|
+
data: unknown;
|
|
26
|
+
}): void;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface VitePluginLike {
|
|
31
|
+
name: string;
|
|
32
|
+
apply?: string;
|
|
33
|
+
handleHotUpdate?(ctx: ViteHotUpdateCtx): unknown;
|
|
34
|
+
}
|
|
35
|
+
export declare function wgpuKitHotReload(): VitePluginLike;
|
|
36
|
+
/** 把 kernel 注册进热重载:对应 .wgsl 文件一变,自动 kernel.replace */
|
|
37
|
+
export declare function hotKernel(kernel: ElementKernel, hot: HotContext | undefined, file: string): void;
|
|
38
|
+
export {};
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
function wgpuKitHotReload() {
|
|
3
|
+
return {
|
|
4
|
+
name: "wgpu-kit:hot-reload",
|
|
5
|
+
handleHotUpdate(ctx) {
|
|
6
|
+
if (!ctx.file.endsWith(".wgsl")) return;
|
|
7
|
+
void (async () => {
|
|
8
|
+
const code = await ctx.read();
|
|
9
|
+
ctx.server.ws.send({ type: "custom", event: "wgpu-kit:kernel", data: { file: ctx.file, code } });
|
|
10
|
+
})();
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function hotKernel(kernel, hot, file) {
|
|
16
|
+
if (!hot) return;
|
|
17
|
+
const suffix = file.slice(file.lastIndexOf("/"));
|
|
18
|
+
hot.on("wgpu-kit:kernel", (data) => {
|
|
19
|
+
const d = data;
|
|
20
|
+
if (typeof d?.code === "string" && typeof d.file === "string" && d.file.endsWith(suffix)) {
|
|
21
|
+
void kernel.replace(d.code).catch((e) => {
|
|
22
|
+
console.error("[wgpu-kit] \u70ED\u91CD\u8F7D\u5931\u8D25,\u4FDD\u7559\u65E7\u7248 kernel:", e.message);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
hotKernel,
|
|
29
|
+
wgpuKitHotReload
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wgpu-kit",
|
|
3
|
+
"version": "0.9.10",
|
|
4
|
+
"description": "Browser GPGPU middle layer: 100k particles in 5 lines. WebGPU compute without the boilerplate.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"webgpu",
|
|
9
|
+
"gpgpu",
|
|
10
|
+
"compute",
|
|
11
|
+
"wgsl",
|
|
12
|
+
"particles",
|
|
13
|
+
"simulation",
|
|
14
|
+
"creative-coding",
|
|
15
|
+
"threejs"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./particles": {
|
|
27
|
+
"types": "./dist/packs/particles/index.d.ts",
|
|
28
|
+
"import": "./dist/particles.js"
|
|
29
|
+
},
|
|
30
|
+
"./three": {
|
|
31
|
+
"types": "./dist/interop/three.d.ts",
|
|
32
|
+
"import": "./dist/three.js"
|
|
33
|
+
},
|
|
34
|
+
"./life": {
|
|
35
|
+
"types": "./dist/packs/life/index.d.ts",
|
|
36
|
+
"import": "./dist/life.js"
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"types": "./dist/react/index.d.ts",
|
|
40
|
+
"import": "./dist/react.js"
|
|
41
|
+
},
|
|
42
|
+
"./fields": {
|
|
43
|
+
"types": "./dist/packs/fields/index.d.ts",
|
|
44
|
+
"import": "./dist/fields.js"
|
|
45
|
+
},
|
|
46
|
+
"./image": {
|
|
47
|
+
"types": "./dist/packs/image/index.d.ts",
|
|
48
|
+
"import": "./dist/image.js"
|
|
49
|
+
},
|
|
50
|
+
"./vite": {
|
|
51
|
+
"types": "./dist/vite.d.ts",
|
|
52
|
+
"import": "./dist/vite.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": ">=18"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist"
|
|
60
|
+
],
|
|
61
|
+
"scripts": {
|
|
62
|
+
"dev": "vite playground",
|
|
63
|
+
"build": "node scripts/build.mjs",
|
|
64
|
+
"build:playground": "vite build playground",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"bundle:tests": "esbuild tests/gpu/smoke.ts --bundle --format=esm --outfile=tests/gpu/smoke.bundle.js --log-level=warning && esbuild tests/gpu/bench.ts --bundle --format=esm --outfile=tests/gpu/bench.bundle.js --log-level=warning && esbuild tests/gpu/packages.ts --bundle --format=esm --outfile=tests/gpu/packages.bundle.js --log-level=warning",
|
|
68
|
+
"verify": "node scripts/verify.mjs"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/node": "^24.0.0",
|
|
72
|
+
"@types/react": "^18.3.31",
|
|
73
|
+
"@types/react-dom": "^18.3.7",
|
|
74
|
+
"@webgpu/types": "^0.1.64",
|
|
75
|
+
"esbuild": "^0.28.0",
|
|
76
|
+
"react": "^18.3.1",
|
|
77
|
+
"react-dom": "^18.3.1",
|
|
78
|
+
"typescript": "^5.6.0",
|
|
79
|
+
"vite": "^7.0.0",
|
|
80
|
+
"vitest": "^3.0.0"
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=20"
|
|
84
|
+
},
|
|
85
|
+
"repository": {
|
|
86
|
+
"type": "git",
|
|
87
|
+
"url": "git+https://github.com/nanfengw0w/wgpu-kit.git"
|
|
88
|
+
},
|
|
89
|
+
"bugs": {
|
|
90
|
+
"url": "https://github.com/nanfengw0w/wgpu-kit/issues"
|
|
91
|
+
},
|
|
92
|
+
"homepage": "https://github.com/nanfengw0w/wgpu-kit#readme"
|
|
93
|
+
}
|