index.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <title>3D Tiles Loader: RealityCapture</title>
  6. <style>
  7. * {
  8. margin: 0;
  9. padding: 0;
  10. }
  11. body {
  12. width: 100vw;
  13. height: 100vh;
  14. overflow: hidden;
  15. }
  16. #canvas-parent {
  17. width: 100vw;
  18. height: 100vh;
  19. touch-action: none;
  20. }
  21. #guide {
  22. position: fixed;
  23. top: 0;
  24. right: 0;
  25. width: 300px;
  26. padding: 1rem 2rem;
  27. font-family:'Courier New', Courier, monospace;
  28. line-height: 1.2;
  29. background-color: white;
  30. color: black;
  31. }
  32. #guide p {
  33. margin-top: 10px;
  34. }
  35. #stats-widget {
  36. position: absolute;
  37. top: 70px;
  38. left: 10px;
  39. background-color: rgb(255 255 255 / 83%);
  40. padding: 10px;
  41. width: 300px;
  42. word-break: break-all;
  43. visibility: hidden;
  44. }
  45. #button {
  46. position: fixed;
  47. bottom: 16px;
  48. right: 16px;
  49. padding: 12px;
  50. border-radius: 50%;
  51. margin-bottom: 0px;
  52. background-color: #FFF;
  53. opacity: .9;
  54. z-index: 999;
  55. box-shadow: 0 0 4px rgb(0 0 0 / 15%);
  56. }
  57. @media (max-width:480px) {
  58. #guide, #stats-widget { display: none; }
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div id='canvas-parent'></div>
  64. <div id="stats-widget"></div>
  65. <div id="guide">
  66. <span id="example-desc">
  67. <b>Freeman Alley, New York.</b> Captured using iPhone 12 Pro Max and processed via RealityCapture.
  68. </span>
  69. <p>Use arrow/WASD keys or mouse wheel/trackpad to move around, and click and drag to turn/rotate the camera.</p>
  70. <p>
  71. <u>Available URL parameters:</u>
  72. <ul>
  73. <li><b>tilesetUrl</b>: Load another tileset json.</li>
  74. <li><b>sse</b>: Change the maximum screen space error.</li>
  75. </ul>
  76. </p>
  77. </div>
  78. <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.4/dist/es-module-shims.js"></script>
  79. <script type="importmap">
  80. {
  81. "imports": {
  82. "three": "https://cdn.skypack.dev/three@0.137.0",
  83. "three/examples/jsm/loaders/GLTFLoader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/GLTFLoader",
  84. "three/examples/jsm/loaders/DRACOLoader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/DRACOLoader",
  85. "three/examples/jsm/loaders/KTX2Loader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/KTX2Loader",
  86. "three/examples/jsm/libs/stats.module.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/libs/stats.module",
  87. "three/examples/jsm/controls/OrbitControls": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/controls/OrbitControls",
  88. "@probe.gl/stats" : "https://cdn.skypack.dev/@probe.gl/stats@3.3.1",
  89. "@probe.gl/stats-widget" : "https://cdn.skypack.dev/@probe.gl/stats-widget@3.5.0",
  90. "three-loader-3dtiles" : "../../../dist/three-loader-3dtiles.esm.js",
  91. "gsap": "https://cdn.skypack.dev/gsap@3.6.1",
  92. "three-story-controls" : "https://cdn.skypack.dev/three-story-controls@1.0.0"
  93. }
  94. }
  95. </script>
  96. <script type='module'>
  97. import {
  98. Scene,
  99. PerspectiveCamera,
  100. WebGLRenderer,
  101. Clock,
  102. Matrix4,
  103. Euler,
  104. sRGBEncoding,
  105. Math as ThreeMath
  106. } from 'three';
  107. import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
  108. import { Loader3DTiles } from 'three-loader-3dtiles';
  109. import { CameraRig, FreeMovementControls } from 'three-story-controls'
  110. import Stats from 'three/examples/jsm/libs/stats.module.js';
  111. import StatsWidget from '@probe.gl/stats-widget';
  112. const queryParams = new URLSearchParams(document.location.search);
  113. const canvasParent = document.querySelector('#canvas-parent');
  114. const statsParent = document.querySelector('#stats-widget')
  115. const scene = new Scene();
  116. const camera = new PerspectiveCamera(
  117. 35,
  118. 1,
  119. 0.01,
  120. 1000,
  121. );
  122. const renderer = new WebGLRenderer();
  123. renderer.outputEncoding = sRGBEncoding;
  124. const clock = new Clock()
  125. const rig = new CameraRig(camera, scene)
  126. let controls = undefined;
  127. if (queryParams.get('orbit')) {
  128. controls = new OrbitControls( camera, canvasParent);
  129. controls.listenToKeyEvents( document.body );
  130. camera.position.set(0,200,0);
  131. controls.update();
  132. } else {
  133. controls = new FreeMovementControls(rig, {
  134. panDegreeFactor: 2,
  135. wheelScaleFactor: 0.01,
  136. keyboardScaleFactor: 0.015,
  137. keyboardDampFactor: 0
  138. });
  139. controls.enable();
  140. }
  141. canvasParent.appendChild(renderer.domElement);
  142. const threeJsStats = new Stats();
  143. threeJsStats.domElement.style.position = 'absolute';
  144. threeJsStats.domElement.style.top = '10px';
  145. threeJsStats.domElement.style.left = '10px';
  146. canvasParent.appendChild( threeJsStats.domElement );
  147. let tilesRuntime = undefined;
  148. let statsRuntime = undefined;
  149. if (queryParams.get('tilesetUrl')) {
  150. document.querySelector('#example-desc').style.display = 'none';
  151. }
  152. loadTileset();
  153. async function loadTileset() {
  154. const result = await Loader3DTiles.load(
  155. {
  156. url:
  157. queryParams.get('tilesetUrl') ??
  158. 'https://int.nyt.com/data/3dscenes/ONA360/TILESET/0731_FREEMAN_ALLEY_10M_A_36x8K__10K-PN_50P_DB/tileset_tileset.json',
  159. renderer: renderer,
  160. options: {
  161. dracoDecoderPath: 'https://cdn.jsdelivr.net/npm/three@0.137.0/examples/js/libs/draco',
  162. basisTranscoderPath: 'https://cdn.jsdelivr.net/npm/three@0.137.0/examples/js/libs/basis',
  163. maximumScreenSpaceError: queryParams.get('sse') ?? 48,
  164. }
  165. }
  166. );
  167. const {model, runtime} = result;
  168. model.rotation.set(-Math.PI / 2, 0, Math.PI / 2);
  169. if (!queryParams.get('tilesetUrl')) {
  170. model.position.set(-1, 4, -16);
  171. }
  172. tilesRuntime = runtime;
  173. scene.add(model);
  174. statsRuntime = new StatsWidget(runtime.getStats(), {container: statsParent });
  175. statsParent.style.visibility = 'visible';
  176. }
  177. function render(t) {
  178. const dt = clock.getDelta()
  179. controls.update(t);
  180. if (tilesRuntime) {
  181. tilesRuntime.update(dt, renderer, camera);
  182. }
  183. if (statsRuntime) {
  184. statsRuntime.update();
  185. }
  186. renderer.render(scene, camera);
  187. threeJsStats.update();
  188. window.requestAnimationFrame(render);
  189. }
  190. onWindowResize();
  191. function onWindowResize() {
  192. renderer.setSize(canvasParent.clientWidth, canvasParent.clientHeight);
  193. camera.aspect = canvasParent.clientWidth / canvasParent.clientHeight;
  194. camera.updateProjectionMatrix();
  195. }
  196. window.addEventListener('resize', onWindowResize)
  197. render();
  198. </script>
  199. <a id="button" target="_blank" href="https://github.com/nytimes/three-loader-3dtiles/blob/master/examples/demos/realitycapture/index.html" title="View source code for demo" style=""><img src="../ic_code_black_24dp.svg"></a>
  200. </body>
  201. </html>