-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.ts
More file actions
86 lines (77 loc) · 2.53 KB
/
index.ts
File metadata and controls
86 lines (77 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import './style.css';
import { vec3 } from 'gl-matrix';
import { animationFrames } from 'rxjs';
import { Viewport } from './viewport';
import { Camera, Gpu } from './graphics';
import { OceanFieldBuilder, OceanFieldBuoyancy } from './ocean';
import { Gui } from './gui';
import { readKtx, registerWorkerGlobals } from './utils';
import { FpsCameraController } from './controller';
import {
testButterflyTexture,
testDft,
testFft,
testDft2,
testFft2,
testOceanFieldIfft2,
testFft2Hermitian,
testFft2Combined,
testOceanFieldBuilderHermitianSpectrum,
} from './test';
import { World } from './physics';
// testButterflyTexture();
// testDft();
// testFft();
// testDft2();
// testFft2();
// testFft2Hermitian();
// testFft2Combined();
// testOceanFieldIfft2();
// testOceanFieldBuilderHermitianSpectrum();
registerWorkerGlobals();
(async () => {
const canvas = document.getElementById('viewport') as HTMLCanvasElement;
canvas.width = self.screen.width;
canvas.height = self.screen.height;
const context = canvas.getContext('webgl2');
if (!context) {
throw new Error('Failed to create webgl2 drawing context');
}
const gpu = new Gpu(context);
const camera = new Camera(45.0, canvas.width / canvas.height, 1.0, 1.0e4);
camera.lookAt(vec3.fromValues(-10, 2.5, -10), vec3.create());
const cameraController = new FpsCameraController(canvas, camera);
const gui = new Gui(document.getElementById('gui'));
const oceanBuilder = new OceanFieldBuilder(gpu);
const oceanField = oceanBuilder.build(gui.params);
const buoyancy = new OceanFieldBuoyancy(oceanField);
const world = new World();
const skybox = await fetch(
'https://raw.githubusercontent.com/codeagent/webgl-ocean/master/assets/cubemaps/sky_skybox.ktx'
)
.then((r) => r.arrayBuffer())
.then((skybox) => readKtx(skybox))
.then((ktx) => gpu.createCubeMap(ktx));
const viewport = new Viewport(
gpu,
oceanField,
world,
buoyancy,
cameraController,
skybox
);
gui.onChange$.subscribe((params) => {
oceanBuilder.update(oceanField, params);
viewport.tileRenderer.setSettings(params.tileRenderer);
viewport.plateRenderer.setSettings(params.plateRenderer);
viewport.projectedGridRenderer.setSettings(params.gridRenderer);
viewport.quadTreeRenderer.setSettings(params.quadTreeRenderer);
});
animationFrames().subscribe(({ elapsed }) => {
buoyancy.update();
world.integrate(1 / 60);
cameraController.update(1 / 60);
oceanField.update(elapsed / 1e3);
viewport.render(gui.params.renderer);
});
})();