Skip to content

Commit 26561ed

Browse files
Merge branch 'main' into alena-tutorial
2 parents e337226 + f9cd436 commit 26561ed

21 files changed

+578
-1581
lines changed

threejs/index.html

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,6 @@
169169

170170
</div>
171171

172-
<!-- BOTTOM LEFT SIDEBAR CONTROLS -->
173-
<div id="bottom-left-sidebar-controls">
174-
<div id="bv-controls">
175-
<button id="bv-btn"><i class="fa-solid fa-street-view"></i></i></button>
176-
</div>
177-
178-
<div id="bv-storey-controls">
179-
<button id="bv-storey-btn"><i class="fa-solid fa-circle-info" alt="bv"></i></button>
180-
<div id="bv-dropdown"></div>
181-
</div>
182-
</div>
183-
184172
<div id="scene-container">
185173
<div id="storey-manager"></div>
186174
</div>

threejs/package-lock.json

Lines changed: 0 additions & 531 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

threejs/src/app.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import { LocationManager, LocationSceneManager } from "./location";
2727
import { BASEMAP_BOUNDARIES } from "./basemap";
2828
import { CjHelper } from "./cjHelper";
2929

30+
31+
/**
32+
* This class acts as a collection point for the instances of most other map functionality classes.
33+
* Additionally this is where the loading and rendering of the gltf file occurs.
34+
*/
3035
export class Map {
3136
/**
3237
*
@@ -98,6 +103,9 @@ export class Map {
98103
requestAnimationFrame(this.render);
99104
}
100105

106+
/**
107+
* Create the threejs scenes and initialize the skybox.
108+
*/
101109
_initScenes() {
102110
this.scene = new THREE.Scene();
103111
const loader = new THREE.CubeTextureLoader();
@@ -116,6 +124,9 @@ export class Map {
116124
this.iconsScene = new THREE.Scene();
117125
}
118126

127+
/**
128+
* Define the lights used in the scene.
129+
*/
119130
_initLights() {
120131
const color = 0xffffff;
121132

@@ -127,6 +138,9 @@ export class Map {
127138
this.scene.add(this.light.target);
128139
}
129140

141+
/**
142+
* Begin the loading of the basemap layers.
143+
*/
130144
setBasemap(url, layer) {
131145
if (this.activeBasemap) {
132146
this.scene.remove(this.activeBasemap);
@@ -155,6 +169,12 @@ export class Map {
155169
return getTileCacheStats();
156170
}
157171

172+
/**
173+
* Create the three renderers:
174+
* 1. glRenderer for the 3D objects
175+
* 2. css3D renderer for the position market
176+
* 3. css2D renderer for the icons and text objects
177+
*/
158178
_initRenderers() {
159179
// WebGL renderer for 3D objects
160180
this.glRenderer = new THREE.WebGLRenderer({
@@ -165,7 +185,7 @@ export class Map {
165185
this.glContainer = this.glRenderer.domElement;
166186
this.mainContainer.appendChild(this.glContainer);
167187

168-
// CSS3D renderer for location
188+
// CSS3D renderer for position
169189
this.css3dRenderer = new CSS3DRenderer();
170190
this.css3dContainer = this.css3dRenderer.domElement;
171191
this.css3dContainer.style.position = "absolute";
@@ -185,6 +205,9 @@ export class Map {
185205
this._resizeWindow();
186206
}
187207

208+
/**
209+
* Create the layerManager object
210+
*/
188211
_initLayerManager() {
189212
this.layerManager = new LayerManager(
190213
this.scene,
@@ -193,6 +216,9 @@ export class Map {
193216
);
194217
}
195218

219+
/**
220+
* Create the buildingView object
221+
*/
196222
_initBuildingView() {
197223
this.buildingView = new BuildingView(
198224
this.cameraManager,
@@ -202,6 +228,9 @@ export class Map {
202228
);
203229
}
204230

231+
/**
232+
* Create the picker object
233+
*/
205234
_initPicker() {
206235
this.pickHighlighter = new Highlighter(PICKED_COLOR);
207236
this.picker = new ObjectPicker(
@@ -214,6 +243,9 @@ export class Map {
214243
this.layerManager.picker = this.picker;
215244
}
216245

246+
/**
247+
* Create the searcher object
248+
*/
217249
_initSearcher() {
218250
this.searcher = new Searcher(
219251
this.cameraManager,
@@ -225,12 +257,18 @@ export class Map {
225257
initSearchBar(this.searcher, search_delay, search_result_count);
226258
}
227259

260+
/**
261+
* Create the geometryColorManager object
262+
*/
228263
_initGeometryColorManager() {
229264
this.geometryColorManager = new GeometryColorManager(
230265
this.scene
231266
);
232267
}
233268

269+
/**
270+
* Create a variety of eventListeners
271+
*/
234272
_attachEvents() {
235273
var hasMouseMoved = false;
236274
// this.hasMouseMovedInFrame = false;
@@ -323,6 +361,9 @@ export class Map {
323361
);
324362
}
325363

364+
/**
365+
* Handles resizing of the window
366+
*/
326367
_resizeWindow() {
327368
const { clientWidth: width, clientHeight: height } = this.glContainer;
328369
this.cameraManager.resizeCameras(width, height);
@@ -331,6 +372,9 @@ export class Map {
331372
this.css3dRenderer.setSize(width, height);
332373
}
333374

375+
/**
376+
* Loads the gltf file containing all scene geometry
377+
*/
334378
loadGLTF(path) {
335379
// const allBuildingsObjectKeys = this.cjHelper.getAllBuildingsObjectKeys();
336380
const loader = new GLTFLoader();
@@ -395,6 +439,9 @@ export class Map {
395439
);
396440
}
397441

442+
/**
443+
* Handles operations that require being updated every frame.
444+
*/
398445
render(time) {
399446
setTimeout(() => {
400447
requestAnimationFrame(this.render);
@@ -408,6 +455,9 @@ export class Map {
408455
this.light.target.position.copy(this.cameraManager.controls.target);
409456
}
410457

458+
/**
459+
* Enables visibility of lod_2 objects (the buildings)
460+
*/
411461
lodVis(lod = "lod_2") {
412462
this.model.traverse((child) => {
413463
child.visible = false;

threejs/src/buildingView.js

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ import { Scene } from "three";
44
import { OutlineManager } from "./outlines";
55
import { CjHelper } from "./cjHelper";
66
import cityjson from "../assets/threejs/buildings/attributes.city.json" assert { type: "json" };
7-
import { LayerManager } from "./layers";
87
import { StoreyManager } from "./storeyManager"
98

109
const NOT_INITIALISED = 0;
1110
const INITIALISED = 1;
1211
const ACTIVATED = 2;
1312

13+
14+
/**
15+
* This function handles all operations related to "building view".
16+
* With "building view" is meant the state that the map enters when viewing the floor plan of a building.
17+
* In this state the camera is locked to orthographic mode, the exterior of the building being view disappears,
18+
* and the interior of this building becomes visible.
19+
*
20+
* Building view can be one of three states:
21+
* 1. Not initialized: when no building is selected and the map is not in building view.
22+
* 2. Initialized: when a building is selected, but building has not be activated yet.
23+
* 3. Activated: when building view has been activated.
24+
*
25+
*/
1426
export class BuildingView {
1527
/**
1628
*
@@ -55,6 +67,12 @@ export class BuildingView {
5567
this._updateStatus(INITIALISED);
5668
}
5769

70+
/**
71+
* @param {string} buildingObjectKey: The cityjson key of the building object that building view
72+
* should be activated for.
73+
*
74+
* Set the current building.
75+
*/
5876
setBuilding(buildingObjectKey) {
5977
if (this._isActivated()) {
6078
console.error("Cannot update the building without deactivating.");
@@ -76,6 +94,11 @@ export class BuildingView {
7694
);
7795
}
7896

97+
/**
98+
* @param {string} storeyCode: The code of the new storey that needs to be switched to.
99+
*
100+
* Sets the new storey, and calls the necessary update functions.
101+
*/
79102
setStorey(storeyCode) {
80103
if (this.storeyCode == storeyCode) {
81104
return;
@@ -87,6 +110,9 @@ export class BuildingView {
87110
}
88111
}
89112

113+
/**
114+
* Enables the viewing of the current storey.
115+
*/
90116
_updateView() {
91117
// Get the storeys
92118
const roomsObjectKeys = this._getRoomsObjectKeys();
@@ -105,6 +131,9 @@ export class BuildingView {
105131
this._applyOutlines(roomsObjects, "lod_0", "interior");
106132
}
107133

134+
/**
135+
* Makes all changes necessary when enabling building view.
136+
*/
108137
activate() {
109138
if (this._isActivated()) {
110139
return;
@@ -134,9 +163,6 @@ export class BuildingView {
134163
this.buildingTranslationZ = -bbox.min.y + 1;
135164
this.buildingObject.translateZ(this.buildingTranslationZ);
136165

137-
// Populate the buttons to switch between storeys
138-
this._populateStoreyButtons();
139-
140166
const available_storeys = this._getStoreyObjectKeys();
141167

142168
this.storeyManager.activate(this.buildingObjectKey, this.storeyCode, available_storeys);
@@ -146,6 +172,9 @@ export class BuildingView {
146172
this._updateStatus(ACTIVATED);
147173
}
148174

175+
/**
176+
* Resets everything necessary to leave building view.
177+
*/
149178
deactivate() {
150179
if (this._isInitialisedNotActivated()) {
151180
return;
@@ -179,6 +208,9 @@ export class BuildingView {
179208
this._updateStatus(INITIALISED);
180209
}
181210

211+
/**
212+
* Clears building data when uninitializing a building
213+
*/
182214
uninitialise() {
183215
if (this._isNotInitialised()) {
184216
return;
@@ -191,7 +223,7 @@ export class BuildingView {
191223

192224
this.buildingObjectKey = null;
193225
this.buildingMeshKey = null;
194-
this.floor = null;
226+
// this.floor = null;
195227
this._updateStatus(NOT_INITIALISED);
196228
}
197229

@@ -251,6 +283,11 @@ export class BuildingView {
251283
return sortedStoreyObjectKeys;
252284
}
253285

286+
/**
287+
* Returns the keys for all room objects of the current storey
288+
*
289+
* @return {array}: An array containing all objects keys of the rooms of the current storey.
290+
*/
254291
_getRoomsObjectKeys() {
255292
// Get the keys of the storeys
256293
const storeysObjectKeys = this._getStoreyObjectKeys();
@@ -310,27 +347,4 @@ export class BuildingView {
310347
}
311348
});
312349
}
313-
314-
_populateStoreyButtons() {
315-
const storey_dropdown = document.getElementById("bv-dropdown");
316-
storey_dropdown.innerHTML = "";
317-
318-
const storeysObjectKeys = this._getStoreyObjectKeys();
319-
for (var storeyCode of Object.keys(storeysObjectKeys)) {
320-
var a = document.createElement("a");
321-
a.appendChild(document.createTextNode(storeyCode));
322-
a.addEventListener("click", (event) => {
323-
this.setStorey(storeyCode);
324-
325-
// Close the dropdown after selecting a storey
326-
const bvDropdown = document.getElementById("bv-dropdown");
327-
if (bvDropdown) {
328-
bvDropdown.style.display = "none";
329-
}
330-
});
331-
332-
a.href = "#";
333-
storey_dropdown.appendChild(a);
334-
}
335-
}
336350
}

0 commit comments

Comments
 (0)