-
Notifications
You must be signed in to change notification settings - Fork 319
Expand file tree
/
Copy path3dtiles_loader.html
More file actions
268 lines (213 loc) · 9.7 KB
/
Copy path3dtiles_loader.html
File metadata and controls
268 lines (213 loc) · 9.7 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<html>
<head>
<title>Itowns - 3D Tiles loader</title>
<script type="importmap">
{
"imports": {
"itowns": "../dist/itowns.js",
"debug": "../dist/debug.js",
"dat": "https://unpkg.com/dat.gui@0.7.9/build/dat.gui.module.js",
"LoadingScreen": "./jsm/GUI/LoadingScreen.js",
"three": "https://unpkg.com/three@0.182.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.182.0/examples/jsm/"
}
}
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/example.css">
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
<style type="text/css">
#description {
z-index: 2;
left: 10px;
}
#featureInfoText {
font-size: small;
}
#description .marg {
margin: 10px;
}
</style>
</head>
<body>
<div id="viewerDiv"></div>
<div id="description">Specify the URL of a tileset to load:
<input type="text" id="url" />
<button id="readURLButton">Load</button>
<div class="marg">
<button id="loadLyonButton">Load Lyon 1 (Mesh)</button>
<button id="loadSeteButton">Load Sete (Point Cloud)</button>
<button id="loadLilleButton">Load Lille (Mesh)</button>
<div id="share"></div>
</div>
<hr />
<p id="featureInfoText" class="marg"><em>Display feature information by clicking on it</em></p>
<p><b>Feature Information:</b></p>
<div id="featureInfo" class="marg"></div>
</div>
<script type="module">
import * as THREE from 'three';
import dat from 'dat';
import setupLoadingScreen from 'LoadingScreen';
import * as itowns from 'itowns';
import * as debug from 'debug';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
import {
zoomToLayer,
fillHTMLWithPickingInfo,
} from './jsm/OGC3DTilesHelper.js';
const {
TMSSource, WMTSSource, OGC3DTilesSource,
ColorLayer, ElevationLayer, OGC3DTilesLayer, PNTS_SIZE_MODE,
GlobeView, Coordinates, Fetcher,
} = itowns;
window.layer = null; // 3D Tiles layer
const uri = new URL(location);
const isEmbedded = window.self !== window.top;
window.gui = new dat.GUI();
// ---- Create a GlobeView ----
// Define camera initial position
const placement = {
coord: new Coordinates('EPSG:4326', 2.351323, 48.856712),
range: 12500000,
};
// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
const viewerDiv = document.getElementById('viewerDiv');
// Create a GlobeView
const view = new GlobeView(viewerDiv, placement, {
realisticLighting: true,
shadows: true,
controls: {
minDistance: 100,
}
});
// Enable various compression support for 3D Tiles tileset:
// - `KHR_draco_mesh_compression` mesh compression extension
// - `KHR_texture_basisu` texture compression extension
// - `EXT_meshopt_compression` data compression extension
itowns.enableDracoLoader('./libs/draco/');
itowns.enableKtx2Loader('./lib/basis/', view.renderer);
itowns.enableMeshoptDecoder(MeshoptDecoder);
// Setup loading screen
setupLoadingScreen(viewerDiv, view);
// ---- Add a basemap ----
// Add one imagery layer to the scene. This layer's properties are
// defined in a json file, but it cou ld be defined as a plain js
// object. See `Layer` documentation for more info.
const openSmConfig = await Fetcher.json('./layers/JSONLayers/OPENSM.json');
const colorLayer = new ColorLayer('Ortho', {
...openSmConfig,
source: new TMSSource(openSmConfig.source),
});
view.addLayer(colorLayer);
// ---- Add 3D terrain ----
// Add two elevation layers: world terrain and a more precise terrain for france
// These will deform iTowns globe geometry to represent terrain elevation.
function addElevationLayerFromConfig(config) {
config.source = new itowns.WMTSSource(config.source);
var elevationLayer = new itowns.ElevationLayer(config.id, config);
view.addLayer(elevationLayer);
}
const ignMntHighResConfig = await itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json');
addElevationLayerFromConfig(ignMntHighResConfig);
const worldDtmConfig = await itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json');
addElevationLayerFromConfig(worldDtmConfig);
// ---------- 3D Tiles loading
function readURL() {
const url = document.getElementById('url').value;
if (url) {
setUrl(url);
}
}
function setUrl(url) {
if (!url) return;
const input_url = document.getElementById('url');
if (!input_url) return;
uri.searchParams.set('3dtiles', url);
if (!isEmbedded){
history.replaceState(null, null, `?${uri.searchParams.toString()}`);
}
input_url.value = url;
load(url);
}
function load(url) {
const source = new OGC3DTilesSource({ url });
if (window.layer) {
gui.removeFolder('Layer 3DTiles');
view.removeLayer('3DTiles');
view.notifyChange();
window.layer.delete();
}
window.layer = new OGC3DTilesLayer('3DTiles', {
source,
pntsSizeMode: PNTS_SIZE_MODE.ATTENUATED,
});
// Add an event for picking the 3D Tiles layer and displaying
// information about the picked feature in an html div
const pickingArgs = {
htmlDiv: document.getElementById('featureInfo'),
view,
layer: window.layer,
};
// Add the layer to our view
view.addLayer(window.layer).then((layer) => {
zoomToLayer(view, layer);
window.addEventListener('click',
(event) => fillHTMLWithPickingInfo(event, pickingArgs), false);
});
window.layer.whenReady
.then(() => debug.createOGC3DTilesDebugUI(gui, view, window.layer));
}
// ---------- DATE/TIME CONTROLS ----------
// Add date/time controls to adjust sun position
const dateFolder = gui.addFolder('Date/Time');
const date = view.date;
dateFolder.add(
{ month: 1 + date.getMonth() }, 'month', 1, 12, 1
).onChange((v) => {
date.setMonth(v - 1);
view.notifyChange(view.sunLightLayer);
}).name('month (1-12)');
dateFolder.add(
{ hour: date.getHours() }, 'hour', 0, 24, 0.1
).onChange((v) => {
const hours = Math.floor(v);
const minutes = (v - hours) * 60;
date.setHours(hours, minutes);
view.notifyChange(view.sunLightLayer);
}).name('hour (24h)');
function loadLyon() {
setUrl("https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/refs/heads/master/3DTiles/lyon1-4978/tileset.json");
}
function loadSete() {
setUrl("https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/pnts-sete-2021-0756_6256/tileset.json");
}
function loadLille() {
setUrl("https://webimaging.lillemetropole.fr/externe/maillage/2020_mel_5cm/tileset.json");
}
const readUrlButton = document.getElementById('readURLButton');
const loadLyonButton = document.getElementById('loadLyonButton');
const loadSeteButton = document.getElementById('loadSeteButton');
const loadLilleButton = document.getElementById('loadLilleButton');
loadLyonButton.addEventListener('click', loadLyon);
loadSeteButton.addEventListener('click', loadSete);
loadLilleButton.addEventListener('click', loadLille);
readUrlButton.addEventListener('click', readURL);
window.readURL = readURL;
window.loadLyon = loadLyon;
window.loadSete = loadSete;
window.loadLille = loadLille;
window.view = view;
window.itowns = itowns;
window.THREE = THREE;
function loadPassedModel() {
const passedUrl = uri.searchParams.get('3dtiles');
if (passedUrl) {
setUrl(passedUrl);
}
}
loadPassedModel();
</script>
</body>
</html>