voxel-geometry-culled-faces-ui.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <!-- Licensed under a BSD license. See license.html for license -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
  7. <title>Three.js - Voxel Geometry - UI</title>
  8. <style>
  9. html, body {
  10. height: 100%;
  11. margin: 0;
  12. }
  13. #c {
  14. width: 100%;
  15. height: 100%;
  16. display: block;
  17. }
  18. #ui {
  19. position: absolute;
  20. left: 10px;
  21. top: 10px;
  22. background: rgba(0, 0, 0, 0.8);
  23. padding: 5px;
  24. }
  25. #ui input[type=radio] {
  26. width: 0;
  27. height: 0;
  28. display: none;
  29. }
  30. #ui input[type=radio] + label {
  31. background-image: url('resources/images/minecraft/flourish-cc-by-nc-sa.png');
  32. background-size: 1600% 400%;
  33. image-rendering: pixelated;
  34. width: 64px;
  35. height: 64px;
  36. display: inline-block;
  37. }
  38. #ui input[type=radio]:checked + label {
  39. outline: 3px solid red;
  40. }
  41. @media (max-width: 600px), (max-height: 600px) {
  42. #ui input[type=radio] + label {
  43. width: 32px;
  44. height: 32px;
  45. }
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <canvas id="c"></canvas>
  51. <div id="ui">
  52. <div class="tiles">
  53. <input type="radio" name="voxel" id="voxel1" value="1"><label for="voxel1" style="background-position: -0% -0%"></label>
  54. <input type="radio" name="voxel" id="voxel2" value="2"><label for="voxel2" style="background-position: -100% -0%"></label>
  55. <input type="radio" name="voxel" id="voxel3" value="3"><label for="voxel3" style="background-position: -200% -0%"></label>
  56. <input type="radio" name="voxel" id="voxel4" value="4"><label for="voxel4" style="background-position: -300% -0%"></label>
  57. <input type="radio" name="voxel" id="voxel5" value="5"><label for="voxel5" style="background-position: -400% -0%"></label>
  58. <input type="radio" name="voxel" id="voxel6" value="6"><label for="voxel6" style="background-position: -500% -0%"></label>
  59. <input type="radio" name="voxel" id="voxel7" value="7"><label for="voxel7" style="background-position: -600% -0%"></label>
  60. <input type="radio" name="voxel" id="voxel8" value="8"><label for="voxel8" style="background-position: -700% -0%"></label>
  61. </div>
  62. <div class="tiles">
  63. <input type="radio" name="voxel" id="voxel9" value="9" ><label for="voxel9" style="background-position: -800% -0%"></label>
  64. <input type="radio" name="voxel" id="voxel10" value="10"><label for="voxel10" style="background-position: -900% -0%"></label>
  65. <input type="radio" name="voxel" id="voxel11" value="11"><label for="voxel11" style="background-position: -1000% -0%"></label>
  66. <input type="radio" name="voxel" id="voxel12" value="12"><label for="voxel12" style="background-position: -1100% -0%"></label>
  67. <input type="radio" name="voxel" id="voxel13" value="13"><label for="voxel13" style="background-position: -1200% -0%"></label>
  68. <input type="radio" name="voxel" id="voxel14" value="14"><label for="voxel14" style="background-position: -1300% -0%"></label>
  69. <input type="radio" name="voxel" id="voxel15" value="15"><label for="voxel15" style="background-position: -1400% -0%"></label>
  70. <input type="radio" name="voxel" id="voxel16" value="16"><label for="voxel16" style="background-position: -1500% -0%"></label>
  71. </div>
  72. </div>
  73. </body>
  74. <!-- Import maps polyfill -->
  75. <!-- Remove this when import maps will be widely supported -->
  76. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  77. <script type="importmap">
  78. {
  79. "imports": {
  80. "three": "../../build/three.module.js"
  81. }
  82. }
  83. </script>
  84. <script type="module">
  85. import * as THREE from 'three';
  86. import {OrbitControls} from '../../examples/jsm/controls/OrbitControls.js';
  87. class VoxelWorld {
  88. constructor(options) {
  89. this.cellSize = options.cellSize;
  90. this.tileSize = options.tileSize;
  91. this.tileTextureWidth = options.tileTextureWidth;
  92. this.tileTextureHeight = options.tileTextureHeight;
  93. const {cellSize} = this;
  94. this.cellSliceSize = cellSize * cellSize;
  95. this.cells = {};
  96. }
  97. computeVoxelOffset(x, y, z) {
  98. const {cellSize, cellSliceSize} = this;
  99. const voxelX = THREE.MathUtils.euclideanModulo(x, cellSize) | 0;
  100. const voxelY = THREE.MathUtils.euclideanModulo(y, cellSize) | 0;
  101. const voxelZ = THREE.MathUtils.euclideanModulo(z, cellSize) | 0;
  102. return voxelY * cellSliceSize +
  103. voxelZ * cellSize +
  104. voxelX;
  105. }
  106. computeCellId(x, y, z) {
  107. const {cellSize} = this;
  108. const cellX = Math.floor(x / cellSize);
  109. const cellY = Math.floor(y / cellSize);
  110. const cellZ = Math.floor(z / cellSize);
  111. return `${cellX},${cellY},${cellZ}`;
  112. }
  113. addCellForVoxel(x, y, z) {
  114. const cellId = this.computeCellId(x, y, z);
  115. let cell = this.cells[cellId];
  116. if (!cell) {
  117. const {cellSize} = this;
  118. cell = new Uint8Array(cellSize * cellSize * cellSize);
  119. this.cells[cellId] = cell;
  120. }
  121. return cell;
  122. }
  123. getCellForVoxel(x, y, z) {
  124. return this.cells[this.computeCellId(x, y, z)];
  125. }
  126. setVoxel(x, y, z, v, addCell = true) {
  127. let cell = this.getCellForVoxel(x, y, z);
  128. if (!cell) {
  129. if (!addCell) {
  130. return;
  131. }
  132. cell = this.addCellForVoxel(x, y, z);
  133. }
  134. const voxelOffset = this.computeVoxelOffset(x, y, z);
  135. cell[voxelOffset] = v;
  136. }
  137. getVoxel(x, y, z) {
  138. const cell = this.getCellForVoxel(x, y, z);
  139. if (!cell) {
  140. return 0;
  141. }
  142. const voxelOffset = this.computeVoxelOffset(x, y, z);
  143. return cell[voxelOffset];
  144. }
  145. generateGeometryDataForCell(cellX, cellY, cellZ) {
  146. const {cellSize, tileSize, tileTextureWidth, tileTextureHeight} = this;
  147. const positions = [];
  148. const normals = [];
  149. const uvs = [];
  150. const indices = [];
  151. const startX = cellX * cellSize;
  152. const startY = cellY * cellSize;
  153. const startZ = cellZ * cellSize;
  154. for (let y = 0; y < cellSize; ++y) {
  155. const voxelY = startY + y;
  156. for (let z = 0; z < cellSize; ++z) {
  157. const voxelZ = startZ + z;
  158. for (let x = 0; x < cellSize; ++x) {
  159. const voxelX = startX + x;
  160. const voxel = this.getVoxel(voxelX, voxelY, voxelZ);
  161. if (voxel) {
  162. // voxel 0 is sky (empty) so for UVs we start at 0
  163. const uvVoxel = voxel - 1;
  164. // There is a voxel here but do we need faces for it?
  165. for (const {dir, corners, uvRow} of VoxelWorld.faces) {
  166. const neighbor = this.getVoxel(
  167. voxelX + dir[0],
  168. voxelY + dir[1],
  169. voxelZ + dir[2]);
  170. if (!neighbor) {
  171. // this voxel has no neighbor in this direction so we need a face.
  172. const ndx = positions.length / 3;
  173. for (const {pos, uv} of corners) {
  174. positions.push(pos[0] + x, pos[1] + y, pos[2] + z);
  175. normals.push(...dir);
  176. uvs.push(
  177. (uvVoxel + uv[0]) * tileSize / tileTextureWidth,
  178. 1 - (uvRow + 1 - uv[1]) * tileSize / tileTextureHeight);
  179. }
  180. indices.push(
  181. ndx, ndx + 1, ndx + 2,
  182. ndx + 2, ndx + 1, ndx + 3,
  183. );
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. return {
  191. positions,
  192. normals,
  193. uvs,
  194. indices,
  195. };
  196. }
  197. // from
  198. // https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.42.3443&rep=rep1&type=pdf
  199. intersectRay(start, end) {
  200. let dx = end.x - start.x;
  201. let dy = end.y - start.y;
  202. let dz = end.z - start.z;
  203. const lenSq = dx * dx + dy * dy + dz * dz;
  204. const len = Math.sqrt(lenSq);
  205. dx /= len;
  206. dy /= len;
  207. dz /= len;
  208. let t = 0.0;
  209. let ix = Math.floor(start.x);
  210. let iy = Math.floor(start.y);
  211. let iz = Math.floor(start.z);
  212. const stepX = (dx > 0) ? 1 : -1;
  213. const stepY = (dy > 0) ? 1 : -1;
  214. const stepZ = (dz > 0) ? 1 : -1;
  215. const txDelta = Math.abs(1 / dx);
  216. const tyDelta = Math.abs(1 / dy);
  217. const tzDelta = Math.abs(1 / dz);
  218. const xDist = (stepX > 0) ? (ix + 1 - start.x) : (start.x - ix);
  219. const yDist = (stepY > 0) ? (iy + 1 - start.y) : (start.y - iy);
  220. const zDist = (stepZ > 0) ? (iz + 1 - start.z) : (start.z - iz);
  221. // location of nearest voxel boundary, in units of t
  222. let txMax = (txDelta < Infinity) ? txDelta * xDist : Infinity;
  223. let tyMax = (tyDelta < Infinity) ? tyDelta * yDist : Infinity;
  224. let tzMax = (tzDelta < Infinity) ? tzDelta * zDist : Infinity;
  225. let steppedIndex = -1;
  226. // main loop along raycast vector
  227. while (t <= len) {
  228. const voxel = this.getVoxel(ix, iy, iz);
  229. if (voxel) {
  230. return {
  231. position: [
  232. start.x + t * dx,
  233. start.y + t * dy,
  234. start.z + t * dz,
  235. ],
  236. normal: [
  237. steppedIndex === 0 ? -stepX : 0,
  238. steppedIndex === 1 ? -stepY : 0,
  239. steppedIndex === 2 ? -stepZ : 0,
  240. ],
  241. voxel,
  242. };
  243. }
  244. // advance t to next nearest voxel boundary
  245. if (txMax < tyMax) {
  246. if (txMax < tzMax) {
  247. ix += stepX;
  248. t = txMax;
  249. txMax += txDelta;
  250. steppedIndex = 0;
  251. } else {
  252. iz += stepZ;
  253. t = tzMax;
  254. tzMax += tzDelta;
  255. steppedIndex = 2;
  256. }
  257. } else {
  258. if (tyMax < tzMax) {
  259. iy += stepY;
  260. t = tyMax;
  261. tyMax += tyDelta;
  262. steppedIndex = 1;
  263. } else {
  264. iz += stepZ;
  265. t = tzMax;
  266. tzMax += tzDelta;
  267. steppedIndex = 2;
  268. }
  269. }
  270. }
  271. return null;
  272. }
  273. }
  274. VoxelWorld.faces = [
  275. { // left
  276. uvRow: 0,
  277. dir: [ -1, 0, 0, ],
  278. corners: [
  279. { pos: [ 0, 1, 0 ], uv: [ 0, 1 ], },
  280. { pos: [ 0, 0, 0 ], uv: [ 0, 0 ], },
  281. { pos: [ 0, 1, 1 ], uv: [ 1, 1 ], },
  282. { pos: [ 0, 0, 1 ], uv: [ 1, 0 ], },
  283. ],
  284. },
  285. { // right
  286. uvRow: 0,
  287. dir: [ 1, 0, 0, ],
  288. corners: [
  289. { pos: [ 1, 1, 1 ], uv: [ 0, 1 ], },
  290. { pos: [ 1, 0, 1 ], uv: [ 0, 0 ], },
  291. { pos: [ 1, 1, 0 ], uv: [ 1, 1 ], },
  292. { pos: [ 1, 0, 0 ], uv: [ 1, 0 ], },
  293. ],
  294. },
  295. { // bottom
  296. uvRow: 1,
  297. dir: [ 0, -1, 0, ],
  298. corners: [
  299. { pos: [ 1, 0, 1 ], uv: [ 1, 0 ], },
  300. { pos: [ 0, 0, 1 ], uv: [ 0, 0 ], },
  301. { pos: [ 1, 0, 0 ], uv: [ 1, 1 ], },
  302. { pos: [ 0, 0, 0 ], uv: [ 0, 1 ], },
  303. ],
  304. },
  305. { // top
  306. uvRow: 2,
  307. dir: [ 0, 1, 0, ],
  308. corners: [
  309. { pos: [ 0, 1, 1 ], uv: [ 1, 1 ], },
  310. { pos: [ 1, 1, 1 ], uv: [ 0, 1 ], },
  311. { pos: [ 0, 1, 0 ], uv: [ 1, 0 ], },
  312. { pos: [ 1, 1, 0 ], uv: [ 0, 0 ], },
  313. ],
  314. },
  315. { // back
  316. uvRow: 0,
  317. dir: [ 0, 0, -1, ],
  318. corners: [
  319. { pos: [ 1, 0, 0 ], uv: [ 0, 0 ], },
  320. { pos: [ 0, 0, 0 ], uv: [ 1, 0 ], },
  321. { pos: [ 1, 1, 0 ], uv: [ 0, 1 ], },
  322. { pos: [ 0, 1, 0 ], uv: [ 1, 1 ], },
  323. ],
  324. },
  325. { // front
  326. uvRow: 0,
  327. dir: [ 0, 0, 1, ],
  328. corners: [
  329. { pos: [ 0, 0, 1 ], uv: [ 0, 0 ], },
  330. { pos: [ 1, 0, 1 ], uv: [ 1, 0 ], },
  331. { pos: [ 0, 1, 1 ], uv: [ 0, 1 ], },
  332. { pos: [ 1, 1, 1 ], uv: [ 1, 1 ], },
  333. ],
  334. },
  335. ];
  336. function main() {
  337. const canvas = document.querySelector('#c');
  338. const renderer = new THREE.WebGLRenderer({canvas});
  339. const cellSize = 32;
  340. const fov = 75;
  341. const aspect = 2; // the canvas default
  342. const near = 0.1;
  343. const far = 1000;
  344. const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
  345. camera.position.set(-cellSize * .3, cellSize * .8, -cellSize * .3);
  346. const controls = new OrbitControls(camera, canvas);
  347. controls.target.set(cellSize / 2, cellSize / 3, cellSize / 2);
  348. controls.update();
  349. const scene = new THREE.Scene();
  350. scene.background = new THREE.Color('lightblue');
  351. const tileSize = 16;
  352. const tileTextureWidth = 256;
  353. const tileTextureHeight = 64;
  354. const loader = new THREE.TextureLoader();
  355. const texture = loader.load('resources/images/minecraft/flourish-cc-by-nc-sa.png', render);
  356. texture.magFilter = THREE.NearestFilter;
  357. texture.minFilter = THREE.NearestFilter;
  358. function addLight(x, y, z) {
  359. const color = 0xFFFFFF;
  360. const intensity = 1;
  361. const light = new THREE.DirectionalLight(color, intensity);
  362. light.position.set(x, y, z);
  363. scene.add(light);
  364. }
  365. addLight(-1, 2, 4);
  366. addLight( 1, -1, -2);
  367. const world = new VoxelWorld({
  368. cellSize,
  369. tileSize,
  370. tileTextureWidth,
  371. tileTextureHeight,
  372. });
  373. const material = new THREE.MeshLambertMaterial({
  374. map: texture,
  375. side: THREE.DoubleSide,
  376. alphaTest: 0.1,
  377. transparent: true,
  378. });
  379. const cellIdToMesh = {};
  380. function updateCellGeometry(x, y, z) {
  381. const cellX = Math.floor(x / cellSize);
  382. const cellY = Math.floor(y / cellSize);
  383. const cellZ = Math.floor(z / cellSize);
  384. const cellId = world.computeCellId(x, y, z);
  385. let mesh = cellIdToMesh[cellId];
  386. const geometry = mesh ? mesh.geometry : new THREE.BufferGeometry();
  387. const {positions, normals, uvs, indices} = world.generateGeometryDataForCell(cellX, cellY, cellZ);
  388. const positionNumComponents = 3;
  389. geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), positionNumComponents));
  390. const normalNumComponents = 3;
  391. geometry.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normals), normalNumComponents));
  392. const uvNumComponents = 2;
  393. geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(uvs), uvNumComponents));
  394. geometry.setIndex(indices);
  395. geometry.computeBoundingSphere();
  396. if (!mesh) {
  397. mesh = new THREE.Mesh(geometry, material);
  398. mesh.name = cellId;
  399. cellIdToMesh[cellId] = mesh;
  400. scene.add(mesh);
  401. mesh.position.set(cellX * cellSize, cellY * cellSize, cellZ * cellSize);
  402. }
  403. }
  404. const neighborOffsets = [
  405. [ 0, 0, 0], // self
  406. [-1, 0, 0], // left
  407. [ 1, 0, 0], // right
  408. [ 0, -1, 0], // down
  409. [ 0, 1, 0], // up
  410. [ 0, 0, -1], // back
  411. [ 0, 0, 1], // front
  412. ];
  413. function updateVoxelGeometry(x, y, z) {
  414. const updatedCellIds = {};
  415. for (const offset of neighborOffsets) {
  416. const ox = x + offset[0];
  417. const oy = y + offset[1];
  418. const oz = z + offset[2];
  419. const cellId = world.computeCellId(ox, oy, oz);
  420. if (!updatedCellIds[cellId]) {
  421. updatedCellIds[cellId] = true;
  422. updateCellGeometry(ox, oy, oz);
  423. }
  424. }
  425. }
  426. for (let y = 0; y < cellSize; ++y) {
  427. for (let z = 0; z < cellSize; ++z) {
  428. for (let x = 0; x < cellSize; ++x) {
  429. const height = (Math.sin(x / cellSize * Math.PI * 2) + Math.sin(z / cellSize * Math.PI * 3)) * (cellSize / 6) + (cellSize / 2);
  430. if (y < height) {
  431. world.setVoxel(x, y, z, randInt(1, 17));
  432. }
  433. }
  434. }
  435. }
  436. function randInt(min, max) {
  437. return Math.floor(Math.random() * (max - min) + min);
  438. }
  439. updateVoxelGeometry(1, 1, 1); // 0,0,0 will generate
  440. function resizeRendererToDisplaySize(renderer) {
  441. const canvas = renderer.domElement;
  442. const width = canvas.clientWidth;
  443. const height = canvas.clientHeight;
  444. const needResize = canvas.width !== width || canvas.height !== height;
  445. if (needResize) {
  446. renderer.setSize(width, height, false);
  447. }
  448. return needResize;
  449. }
  450. let renderRequested = false;
  451. function render() {
  452. renderRequested = undefined;
  453. if (resizeRendererToDisplaySize(renderer)) {
  454. const canvas = renderer.domElement;
  455. camera.aspect = canvas.clientWidth / canvas.clientHeight;
  456. camera.updateProjectionMatrix();
  457. }
  458. controls.update();
  459. renderer.render(scene, camera);
  460. }
  461. render();
  462. function requestRenderIfNotRequested() {
  463. if (!renderRequested) {
  464. renderRequested = true;
  465. requestAnimationFrame(render);
  466. }
  467. }
  468. let currentVoxel = 0;
  469. let currentId;
  470. document.querySelectorAll('#ui .tiles input[type=radio][name=voxel]').forEach((elem) => {
  471. elem.addEventListener('click', allowUncheck);
  472. });
  473. function allowUncheck() {
  474. if (this.id === currentId) {
  475. this.checked = false;
  476. currentId = undefined;
  477. currentVoxel = 0;
  478. } else {
  479. currentId = this.id;
  480. currentVoxel = parseInt(this.value);
  481. }
  482. }
  483. function getCanvasRelativePosition(event) {
  484. const rect = canvas.getBoundingClientRect();
  485. return {
  486. x: (event.clientX - rect.left) * canvas.width / rect.width,
  487. y: (event.clientY - rect.top ) * canvas.height / rect.height,
  488. };
  489. }
  490. function placeVoxel(event) {
  491. const pos = getCanvasRelativePosition(event);
  492. const x = (pos.x / canvas.width ) * 2 - 1;
  493. const y = (pos.y / canvas.height) * -2 + 1; // note we flip Y
  494. const start = new THREE.Vector3();
  495. const end = new THREE.Vector3();
  496. start.setFromMatrixPosition(camera.matrixWorld);
  497. end.set(x, y, 1).unproject(camera);
  498. const intersection = world.intersectRay(start, end);
  499. if (intersection) {
  500. const voxelId = event.shiftKey ? 0 : currentVoxel;
  501. // the intersection point is on the face. That means
  502. // the math imprecision could put us on either side of the face.
  503. // so go half a normal into the voxel if removing (currentVoxel = 0)
  504. // our out of the voxel if adding (currentVoxel > 0)
  505. const pos = intersection.position.map((v, ndx) => {
  506. return v + intersection.normal[ndx] * (voxelId > 0 ? 0.5 : -0.5);
  507. });
  508. world.setVoxel(...pos, voxelId);
  509. updateVoxelGeometry(...pos);
  510. requestRenderIfNotRequested();
  511. }
  512. }
  513. const mouse = {
  514. x: 0,
  515. y: 0,
  516. };
  517. function recordStartPosition(event) {
  518. mouse.x = event.clientX;
  519. mouse.y = event.clientY;
  520. mouse.moveX = 0;
  521. mouse.moveY = 0;
  522. }
  523. function recordMovement(event) {
  524. mouse.moveX += Math.abs(mouse.x - event.clientX);
  525. mouse.moveY += Math.abs(mouse.y - event.clientY);
  526. }
  527. function placeVoxelIfNoMovement(event) {
  528. if (mouse.moveX < 5 && mouse.moveY < 5) {
  529. placeVoxel(event);
  530. }
  531. window.removeEventListener('pointermove', recordMovement);
  532. window.removeEventListener('pointerup', placeVoxelIfNoMovement);
  533. }
  534. canvas.addEventListener('pointerdown', (event) => {
  535. event.preventDefault();
  536. recordStartPosition(event);
  537. window.addEventListener('pointermove', recordMovement);
  538. window.addEventListener('pointerup', placeVoxelIfNoMovement);
  539. }, {passive: false});
  540. canvas.addEventListener('touchstart', (event) => {
  541. // prevent scrolling
  542. event.preventDefault();
  543. }, {passive: false});
  544. controls.addEventListener('change', requestRenderIfNotRequested);
  545. window.addEventListener('resize', requestRenderIfNotRequested);
  546. }
  547. main();
  548. </script>
  549. </html>