Skip to content

Commit

Permalink
feat(webgpu-rendering-context): import webgpu renderer (#99)
Browse files Browse the repository at this point in the history
* feat(webgpu-rendering-context): import webgpu renderer from three.js and creates a renderer

* fix(WebGPU): bump build target to resolve error

this commits fix that vite is complaining about
top-level await used in threejs. it is ok to bump the version
since our support target is
2 most recent Chromium/Firefox/Safari version

Signed-off-by: Bill ZHANG <[email protected]>

* fix(webgpu-rendering-context): fix type declaration

* style(three-webgpu): run prettier formatting on the code

Signed-off-by: Bill ZHANG <[email protected]>

---------

Signed-off-by: Bill ZHANG <[email protected]>
Co-authored-by: Chenzhu <[email protected]>
Co-authored-by: Bill ZHANG <[email protected]>
  • Loading branch information
3 people authored Sep 14, 2023
1 parent 774b781 commit 089feed
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/components/Simulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import vertexShader from '../shaders/vert.glsl';
import fragmentShader from '../shaders/frag.glsl';
import { OutgoingMessage } from '../workers/modelWorkerMessage';

// WebGPU imports
import { default as WebGPU } from 'three/addons/capabilities/WebGPU.js';
import { default as WebGPURenderer } from 'three/addons/renderers/webgpu/WebGPURenderer.js';

class SimulationParams {
// render options
densityLowColour: t.Color = new t.Color('blue');
Expand Down Expand Up @@ -60,6 +64,15 @@ function DiffusionPlane(
): React.ReactElement {
// INITIALISATION

// WebGPU capability test
if (WebGPU.isAvailable() === true) {
const webgpuRenderer = new WebGPURenderer({ antialias: true });
console.log('browser supports webgpu rendering');
console.log('webgpu renderer context', webgpuRenderer);
} else {
console.log('browser does not support webgpu rendering');
}

// reference to the parent mesh
const ref = useRef<t.Mesh>(null!);

Expand Down
12 changes: 12 additions & 0 deletions src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ declare module '*.md' {
const html: string;
export default html;
}

declare module 'three/addons/capabilities/WebGPU.js' {
export default class WebGPU {
static isAvailable(): boolean;
static getErrorMessage(): HTMLDivElement;
}
}
declare module 'three/addons/renderers/webgpu/WebGPURenderer.js' {
export default class WebGPURenderer {
constructor(parameters: object);
}
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"types": [
Expand Down
8 changes: 8 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ export default defineConfig({
rehypePlugins: [rehypeSanitize],
}),
],
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
},
build: {
target: 'esnext',
},
});

0 comments on commit 089feed

Please sign in to comment.