2
0

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

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