index.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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: Cesium ION</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. Use arrow keys, mouse wheel/trackpad, or right click to move around, and left click and drag to turn/rotate the camera.
  67. <p>
  68. <u>Available URL parameters:</u>
  69. <ul>
  70. <li><b>assetId</b>: Load another Cesium ion asset id.</li>
  71. <li><b>ionToken</b>: Set the Cesium ion access token.</li>
  72. </ul>
  73. </p>
  74. </div>
  75. <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.4/dist/es-module-shims.js"></script>
  76. <script type="importmap">
  77. {
  78. "imports": {
  79. "three": "https://cdn.skypack.dev/three@0.137.0",
  80. "three/examples/jsm/loaders/GLTFLoader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/GLTFLoader",
  81. "three/examples/jsm/loaders/DRACOLoader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/DRACOLoader",
  82. "three/examples/jsm/loaders/KTX2Loader.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/loaders/KTX2Loader",
  83. "three/examples/jsm/controls/OrbitControls": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/controls/OrbitControls",
  84. "three/examples/jsm/libs/stats.module.js": "https://cdn.skypack.dev/three@v0.137.0/examples/jsm/libs/stats.module",
  85. "@probe.gl/stats" : "https://cdn.skypack.dev/@probe.gl/stats@3.3.1",
  86. "@probe.gl/stats-widget" : "https://cdn.skypack.dev/@probe.gl/stats-widget@3.5.0",
  87. "three-loader-3dtiles" : "../../../dist/three-loader-3dtiles.esm.js"
  88. }
  89. }
  90. </script>
  91. <script type='module'>
  92. import {
  93. Scene,
  94. PerspectiveCamera,
  95. WebGLRenderer,
  96. GridHelper,
  97. Clock,
  98. Matrix4,
  99. Euler
  100. } from 'three';
  101. import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
  102. import { Loader3DTiles, PointCloudColoring } from 'three-loader-3dtiles';
  103. import Stats from 'three/examples/jsm/libs/stats.module.js';
  104. import StatsWidget from '@probe.gl/stats-widget';
  105. const ION_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWMxMzcyYy0zZjJkLTQwODctODNlNi01MDRkZmMzMjIxOWIiLCJpZCI6OTYyMCwic2NvcGVzIjpbImFzbCIsImFzciIsImdjIl0sImlhdCI6MTU2Mjg2NjI3M30.1FNiClUyk00YH_nWfSGpiQAjR5V2OvREDq1PJ5QMjWQ';
  106. const canvasParent = document.querySelector('#canvas-parent');
  107. const statsParent = document.querySelector('#stats-widget')
  108. const scene = new Scene();
  109. const camera = new PerspectiveCamera(
  110. 35,
  111. 1,
  112. 0.01,
  113. 10000,
  114. );
  115. camera.position.set(0, 2000, 0);
  116. const renderer = new WebGLRenderer();
  117. const clock = new Clock()
  118. const controls = new OrbitControls( camera, canvasParent);
  119. controls.listenToKeyEvents( window );
  120. canvasParent.appendChild(renderer.domElement);
  121. const threeJsStats = new Stats();
  122. threeJsStats.domElement.style.position = 'absolute';
  123. threeJsStats.domElement.style.top = '10px';
  124. threeJsStats.domElement.style.left = '10px';
  125. canvasParent.appendChild( threeJsStats.domElement );
  126. const queryParams = new URLSearchParams(document.location.search);
  127. loadTileset();
  128. let tilesRuntime = undefined;
  129. let statsRuntime = undefined;
  130. async function loadTileset() {
  131. const result = await Loader3DTiles.load(
  132. {
  133. url: `https://assets.cesium.com/${queryParams.get('assetId') ?? 43978}/tileset.json`,
  134. renderer: renderer,
  135. options: {
  136. cesiumIONToken: queryParams.get('ionToken') ?? ION_TOKEN,
  137. dracoDecoderPath: 'https://cdn.jsdelivr.net/npm/three@0.137.0/examples/js/libs/draco',
  138. pointCloudColoring: PointCloudColoring.RGB,
  139. maximumScreenSpaceError: 6
  140. }
  141. }
  142. );
  143. const {model, runtime} = result;
  144. model.rotation.set(-Math.PI / 2, 0, 0);
  145. tilesRuntime = runtime;
  146. scene.add(model);
  147. statsRuntime = new StatsWidget(runtime.getStats(), {container: statsParent });
  148. statsParent.style.visibility = 'visible';
  149. }
  150. function render(t) {
  151. const dt = clock.getDelta()
  152. controls.update();
  153. if (tilesRuntime) {
  154. tilesRuntime.update(dt, renderer, camera);
  155. }
  156. if (statsRuntime) {
  157. statsRuntime.update();
  158. }
  159. renderer.render(scene, camera);
  160. threeJsStats.update();
  161. window.requestAnimationFrame(render);
  162. }
  163. onWindowResize();
  164. function onWindowResize() {
  165. renderer.setSize(canvasParent.clientWidth, canvasParent.clientHeight);
  166. camera.aspect = canvasParent.clientWidth / canvasParent.clientHeight;
  167. camera.updateProjectionMatrix();
  168. }
  169. window.addEventListener('resize', onWindowResize)
  170. render();
  171. </script>
  172. <a id="button" target="_blank" href="https://github.com/nytimes/three-loader-3dtiles/blob/master/examples/demos/cesium/index.html" title="View source code for demo" style=""><img src="../ic_code_black_24dp.svg"></a>
  173. </body>
  174. </html>