@jdultra/threedtiles 4.0.4 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -21,7 +21,9 @@ occlusionCullingService.setSide(THREE.DoubleSide);
|
|
|
21
21
|
const scene = initScene();
|
|
22
22
|
|
|
23
23
|
const domContainer = initDomContainer("screen");
|
|
24
|
-
const camera = initCamera();
|
|
24
|
+
const camera = initCamera(domContainer.offsetWidth, domContainer.offsetHeight);
|
|
25
|
+
const stats = initStats(domContainer);
|
|
26
|
+
const renderer = initRenderer(camera, domContainer);
|
|
25
27
|
//const ogc3DTiles = initTileset(scene);
|
|
26
28
|
|
|
27
29
|
|
|
@@ -30,8 +32,6 @@ initInstancedTilesets(instancedTileLoader);
|
|
|
30
32
|
|
|
31
33
|
const controller = initController(camera, domContainer);
|
|
32
34
|
|
|
33
|
-
const stats = initStats(domContainer);
|
|
34
|
-
const renderer = initRenderer(camera, domContainer);
|
|
35
35
|
const composer = initComposer(scene, camera, renderer);
|
|
36
36
|
|
|
37
37
|
|
|
@@ -69,8 +69,8 @@ function initComposer(scene, camera, renderer) {
|
|
|
69
69
|
function initScene() {
|
|
70
70
|
const scene = new THREE.Scene();
|
|
71
71
|
scene.matrixAutoUpdate = false;
|
|
72
|
-
scene.matrixWorldAutoUpdate = false;
|
|
73
|
-
scene.background = new THREE.Color(
|
|
72
|
+
//scene.matrixWorldAutoUpdate = false;
|
|
73
|
+
scene.background = new THREE.Color(0x404040);
|
|
74
74
|
scene.add(new THREE.AmbientLight(0xFFFFFF, 1.0));
|
|
75
75
|
|
|
76
76
|
/*const light = new THREE.PointLight(0xbbbbff, 2, 5000);
|
|
@@ -132,9 +132,10 @@ function initStats(dom) {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
function initCamera() {
|
|
136
|
-
const camera = new THREE.PerspectiveCamera(
|
|
137
|
-
camera.position.set(-
|
|
135
|
+
function initCamera(width, height) {
|
|
136
|
+
const camera = new THREE.PerspectiveCamera(60, width / height, 1, 100000);
|
|
137
|
+
camera.position.set(-400.060421028462592,-14.561785966685625,700.123058268059668);
|
|
138
|
+
|
|
138
139
|
camera.matrixAutoUpdate = true;
|
|
139
140
|
return camera;
|
|
140
141
|
}
|
|
@@ -145,17 +146,22 @@ function initTileset(scene) {
|
|
|
145
146
|
//// Insert code to be called on every newly decoded mesh e.g.:
|
|
146
147
|
mesh.material.wireframe = false;
|
|
147
148
|
mesh.material.side = THREE.DoubleSide;
|
|
149
|
+
mesh.material.metalness = 0.0
|
|
148
150
|
}, 1000)
|
|
149
151
|
const ogc3DTile = new OGC3DTile({
|
|
150
152
|
//url: "http://localhost:8080/tileset.json",
|
|
151
153
|
//url: "https://storage.googleapis.com/ogc-3d-tiles/droneship/tileset.json",
|
|
152
154
|
url: "https://storage.googleapis.com/ogc-3d-tiles/berlinTileset/tileset.json",
|
|
153
155
|
//url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/ands2ty8orz/tileset.json",
|
|
156
|
+
//url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/an7opcnyije/tileset.json",
|
|
157
|
+
//url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/ands2ty8orz/tileset.json",
|
|
158
|
+
//url: "https://s3.eu-central-2.wasabisys.com/construkted-assets-eu/a88b3sungng/tileset.json",
|
|
154
159
|
geometricErrorMultiplier: 0.01,
|
|
155
160
|
loadOutsideView: false,
|
|
156
161
|
tileLoader: tileLoader,
|
|
157
162
|
//occlusionCullingService: occlusionCullingService,
|
|
158
163
|
static: false,
|
|
164
|
+
renderer: renderer
|
|
159
165
|
|
|
160
166
|
});
|
|
161
167
|
|
|
@@ -164,7 +170,7 @@ function initTileset(scene) {
|
|
|
164
170
|
|
|
165
171
|
//// The OGC3DTile object is a threejs Object3D so you may do all the usual opperations like transformations e.g.:
|
|
166
172
|
ogc3DTile.rotateOnAxis(new THREE.Vector3(1, 0, 0), Math.PI * -0.5) // Z-UP to Y-UP
|
|
167
|
-
|
|
173
|
+
ogc3DTile.scale.set(100.0,100.0,100.0)
|
|
168
174
|
//// If the OGC3DTile object is marked as "static" (constructorParameter), these operations will not work.
|
|
169
175
|
|
|
170
176
|
|
|
@@ -227,6 +233,7 @@ function initInstancedTilesets(instancedTileLoader) {
|
|
|
227
233
|
loadOutsideView: true,
|
|
228
234
|
tileLoader: instancedTileLoader,
|
|
229
235
|
static: true,
|
|
236
|
+
renderer: renderer
|
|
230
237
|
});
|
|
231
238
|
//tileset.rotateOnAxis(new THREE.Vector3(1, 0, 0), Math.PI * -0.5) // Z-UP to Y-UP
|
|
232
239
|
tileset.translateOnAxis(new THREE.Vector3(1, 0, 0), 50 * x)
|
|
@@ -275,7 +282,7 @@ function initLODMultiplierSlider(instancedTilesets) {
|
|
|
275
282
|
function initController(camera, dom) {
|
|
276
283
|
const controller = new OrbitControls(camera, dom);
|
|
277
284
|
|
|
278
|
-
controller.target.set(0,
|
|
285
|
+
controller.target.set(0,0,0);
|
|
279
286
|
controller.minDistance = 0.01;
|
|
280
287
|
controller.maxDistance = 100000;
|
|
281
288
|
controller.update();
|
package/src/tileset/OGC3DTile.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as path from "path-browserify"
|
|
|
6
6
|
import { clamp } from "three/src/math/MathUtils";
|
|
7
7
|
|
|
8
8
|
const tempSphere = new THREE.Sphere(new THREE.Vector3(0, 0, 0, 1));
|
|
9
|
-
|
|
9
|
+
const rendererSize = new THREE.Vector2();
|
|
10
10
|
|
|
11
11
|
class OGC3DTile extends THREE.Object3D {
|
|
12
12
|
|
|
@@ -27,7 +27,8 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
27
27
|
* parentTile: OGC3DTile,
|
|
28
28
|
* onLoadCallback: function,
|
|
29
29
|
* occlusionCullingService: OcclusionCullingService,
|
|
30
|
-
* static: Boolean
|
|
30
|
+
* static: Boolean,
|
|
31
|
+
* renderer: Renderer
|
|
31
32
|
* } properties
|
|
32
33
|
*/
|
|
33
34
|
constructor(properties) {
|
|
@@ -43,10 +44,11 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
43
44
|
mesh.material.wireframe = false;
|
|
44
45
|
mesh.material.side = THREE.DoubleSide;
|
|
45
46
|
} : properties.meshCallback);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
}
|
|
48
|
+
// set properties general to the entire tileset
|
|
49
|
+
this.geometricErrorMultiplier = !!properties.geometricErrorMultiplier ? properties.geometricErrorMultiplier : 1.0;
|
|
50
|
+
|
|
51
|
+
this.renderer = properties.renderer;
|
|
50
52
|
this.meshCallback = properties.meshCallback;
|
|
51
53
|
this.loadOutsideView = properties.loadOutsideView;
|
|
52
54
|
this.cameraOnLoad = properties.cameraOnLoad;
|
|
@@ -58,7 +60,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
58
60
|
this.color.setHex(Math.random() * 0xffffff);
|
|
59
61
|
this.colorID = clamp(self.color.r * 255, 0, 255) << 16 ^ clamp(self.color.g * 255, 0, 255) << 8 ^ clamp(self.color.b * 255, 0, 255) << 0;
|
|
60
62
|
}
|
|
61
|
-
if(this.static){
|
|
63
|
+
if (this.static) {
|
|
62
64
|
this.matrixAutoUpdate = false;
|
|
63
65
|
}
|
|
64
66
|
// declare properties specific to the tile for clarity
|
|
@@ -176,7 +178,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
176
178
|
if (!!url) {
|
|
177
179
|
if (url.includes(".b3dm")) {
|
|
178
180
|
self.contentURL = url;
|
|
179
|
-
self.tileLoader.get(self.abortController,this.uuid, url, mesh => {
|
|
181
|
+
self.tileLoader.get(self.abortController, this.uuid, url, mesh => {
|
|
180
182
|
if (!!self.deleted) return;
|
|
181
183
|
mesh.traverse((o) => {
|
|
182
184
|
if (o.isMesh) {
|
|
@@ -189,13 +191,13 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
189
191
|
}
|
|
190
192
|
o.geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
|
|
191
193
|
}
|
|
192
|
-
if(self.static){
|
|
194
|
+
if (self.static) {
|
|
193
195
|
o.matrixAutoUpdate = false;
|
|
194
196
|
}
|
|
195
197
|
//o.material.visible = false;
|
|
196
198
|
}
|
|
197
199
|
});
|
|
198
|
-
|
|
200
|
+
|
|
199
201
|
self.add(mesh);
|
|
200
202
|
self.updateWorldMatrix(false, true);
|
|
201
203
|
// mesh.layers.disable(0);
|
|
@@ -204,7 +206,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
204
206
|
return self.calculateDistanceToCamera(self.cameraOnLoad);
|
|
205
207
|
}, () => self.getSiblings(), self.level);
|
|
206
208
|
} else if (url.includes(".json")) {
|
|
207
|
-
self.tileLoader.get(self.abortController,this.uuid, url, json => {
|
|
209
|
+
self.tileLoader.get(self.abortController, this.uuid, url, json => {
|
|
208
210
|
if (!!self.deleted) return;
|
|
209
211
|
if (!self.json.children) self.json.children = [];
|
|
210
212
|
json.rootPath = path.dirname(url);
|
|
@@ -273,7 +275,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
273
275
|
if (self.occlusionCullingService && self.hasMeshContent && !self.occlusionCullingService.hasID(self.colorID)) {
|
|
274
276
|
return;
|
|
275
277
|
}
|
|
276
|
-
if (!self.hasMeshContent || (metric < self.geometricError && !!self.meshContent)) {
|
|
278
|
+
if (!self.hasMeshContent || (metric < self.geometricErrorMultiplier * self.geometricError && !!self.meshContent)) {
|
|
277
279
|
if (!!self.json && !!self.json.children && self.childrenTiles.length != self.json.children.length) {
|
|
278
280
|
loadJsonChildren();
|
|
279
281
|
return;
|
|
@@ -307,10 +309,10 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
// has children
|
|
310
|
-
if (metric >= self.geometricError) { // Ideal LOD or before ideal lod
|
|
312
|
+
if (metric >= self.geometricErrorMultiplier * self.geometricError) { // Ideal LOD or before ideal lod
|
|
311
313
|
|
|
312
314
|
self.changeContentVisibility(true);
|
|
313
|
-
} else if (metric < self.geometricError) { // Ideal LOD is past this one
|
|
315
|
+
} else if (metric < self.geometricErrorMultiplier * self.geometricError) { // Ideal LOD is past this one
|
|
314
316
|
// if children are visible and have been displayed, can be hidden
|
|
315
317
|
let allChildrenReady = true;
|
|
316
318
|
self.childrenTiles.every(child => {
|
|
@@ -345,7 +347,7 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
345
347
|
updateNodeVisibility(metric);
|
|
346
348
|
return;
|
|
347
349
|
}
|
|
348
|
-
if (metric >= self.geometricError) {
|
|
350
|
+
if (metric >= self.geometricErrorMultiplier * self.geometricError) {
|
|
349
351
|
self.disposeChildren();
|
|
350
352
|
updateNodeVisibility();
|
|
351
353
|
return;
|
|
@@ -367,7 +369,8 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
367
369
|
level: self.level + 1,
|
|
368
370
|
tileLoader: self.tileLoader,
|
|
369
371
|
cameraOnLoad: camera,
|
|
370
|
-
occlusionCullingService:self.occlusionCullingService,
|
|
372
|
+
occlusionCullingService: self.occlusionCullingService,
|
|
373
|
+
renderer: self.renderer,
|
|
371
374
|
static: self.static
|
|
372
375
|
});
|
|
373
376
|
self.childrenTiles.push(childTile);
|
|
@@ -382,11 +385,11 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
382
385
|
const self = this;
|
|
383
386
|
this.childrenTiles.every(child => {
|
|
384
387
|
if (child.hasMeshContent) {
|
|
385
|
-
if(child.childrenTiles.length>0){
|
|
388
|
+
if (child.childrenTiles.length > 0) {
|
|
386
389
|
allLoadedAndHidden = false;
|
|
387
390
|
return false;
|
|
388
391
|
}
|
|
389
|
-
if (!child.inFrustum
|
|
392
|
+
if (!child.inFrustum) {
|
|
390
393
|
return true;
|
|
391
394
|
};
|
|
392
395
|
if (!child.materialVisibility || child.meshesToDisplay != child.meshesDisplayed) {
|
|
@@ -459,15 +462,15 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
459
462
|
|
|
460
463
|
changeContentVisibility(visibility) {
|
|
461
464
|
const self = this;
|
|
462
|
-
if(self.hasMeshContent && self.meshContent){
|
|
463
|
-
if(visibility){
|
|
464
|
-
|
|
465
|
+
if (self.hasMeshContent && self.meshContent) {
|
|
466
|
+
if (visibility) {
|
|
467
|
+
|
|
465
468
|
self.meshContent.traverse((o) => {
|
|
466
469
|
if (o.isMesh) {
|
|
467
470
|
o.layers.enable(0);
|
|
468
471
|
}
|
|
469
472
|
});
|
|
470
|
-
}else{
|
|
473
|
+
} else {
|
|
471
474
|
self.meshContent.traverse((o) => {
|
|
472
475
|
if (o.isMesh) {
|
|
473
476
|
o.layers.disable(0);
|
|
@@ -530,8 +533,18 @@ class OGC3DTile extends THREE.Object3D {
|
|
|
530
533
|
return 0;
|
|
531
534
|
}
|
|
532
535
|
const scale = this.matrixWorld.getMaxScaleOnAxis();
|
|
533
|
-
|
|
534
|
-
|
|
536
|
+
this.renderer.getDrawingBufferSize(rendererSize);
|
|
537
|
+
let s = rendererSize.y;
|
|
538
|
+
let fov = camera.fov;
|
|
539
|
+
if(camera.aspect < 1){
|
|
540
|
+
fov *= camera.aspect;
|
|
541
|
+
s = rendererSize.x;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
let lambda = 2.0 * Math.tan(0.5 * fov * 0.01745329251994329576923690768489) * distance;
|
|
545
|
+
|
|
546
|
+
return (window.devicePixelRatio * 16 * lambda) / (s * scale);
|
|
547
|
+
|
|
535
548
|
} else if (this.boundingVolume instanceof THREE.Box3) {
|
|
536
549
|
// Region
|
|
537
550
|
// Region not supported
|
|
@@ -19,12 +19,14 @@ class InstancedOGC3DTile extends THREE.Object3D {
|
|
|
19
19
|
* cameraOnLoad: camera,
|
|
20
20
|
* parentTile: OGC3DTile,
|
|
21
21
|
* onLoadCallback: function,
|
|
22
|
+
* renderer: Renderer
|
|
22
23
|
* static: Boolean
|
|
23
24
|
* } properties
|
|
24
25
|
*/
|
|
25
26
|
constructor(properties) {
|
|
26
27
|
super();
|
|
27
28
|
properties.master = this;
|
|
29
|
+
this.renderer = properties.renderer;
|
|
28
30
|
this.geometricErrorMultiplier = properties.geometricErrorMultiplier? properties.geometricErrorMultiplier:1.0;
|
|
29
31
|
this.tileset = new InstancedTile(properties);
|
|
30
32
|
if (properties.static) {
|
|
@@ -5,7 +5,7 @@ import * as path from "path-browserify";
|
|
|
5
5
|
import * as _ from "lodash";
|
|
6
6
|
|
|
7
7
|
const tempSphere = new THREE.Sphere(new THREE.Vector3(0, 0, 0, 1));
|
|
8
|
-
|
|
8
|
+
const rendererSize = new THREE.Vector2();
|
|
9
9
|
|
|
10
10
|
class InstancedTile extends THREE.Object3D {
|
|
11
11
|
|
|
@@ -250,7 +250,7 @@ class InstancedTile extends THREE.Object3D {
|
|
|
250
250
|
// If this tile does not have mesh content but it has children
|
|
251
251
|
if (metric < 0 && self.hasMeshContent) return;
|
|
252
252
|
|
|
253
|
-
if ((!self.hasMeshContent && self.rootPath) || (metric < self.geometricError && !!self.meshContent)) {
|
|
253
|
+
if ((!self.hasMeshContent && self.rootPath) || (metric < self.master.geometricErrorMultiplier * self.geometricError && !!self.meshContent)) {
|
|
254
254
|
if (!!self.json && !!self.jsonChildren && self.childrenTiles.length != self.jsonChildren.length) {
|
|
255
255
|
loadJsonChildren();
|
|
256
256
|
return;
|
|
@@ -284,10 +284,10 @@ class InstancedTile extends THREE.Object3D {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// has children
|
|
287
|
-
if (metric >= self.geometricError) { // Ideal LOD or before ideal lod
|
|
287
|
+
if (metric >= self.master.geometricErrorMultiplier * self.geometricError) { // Ideal LOD or before ideal lod
|
|
288
288
|
|
|
289
289
|
self.changeContentVisibility(true);
|
|
290
|
-
} else if (metric < self.geometricError) { // Ideal LOD is past this one
|
|
290
|
+
} else if (metric < self.master.geometricErrorMultiplier * self.geometricError) { // Ideal LOD is past this one
|
|
291
291
|
// if children are visible and have been displayed, can be hidden
|
|
292
292
|
let allChildrenReady = true;
|
|
293
293
|
self.childrenTiles.every(child => {
|
|
@@ -311,7 +311,7 @@ class InstancedTile extends THREE.Object3D {
|
|
|
311
311
|
updateNodeVisibility(metric);
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
|
-
if (metric >= self.geometricError) {
|
|
314
|
+
if (metric >= self.master.geometricErrorMultiplier * self.geometricError) {
|
|
315
315
|
self.disposeChildren();
|
|
316
316
|
updateNodeVisibility();
|
|
317
317
|
return;
|
|
@@ -455,8 +455,18 @@ class InstancedTile extends THREE.Object3D {
|
|
|
455
455
|
return 0;
|
|
456
456
|
}
|
|
457
457
|
const scale = this.master.matrixWorld.getMaxScaleOnAxis();
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
|
|
459
|
+
this.master.renderer.getDrawingBufferSize(rendererSize);
|
|
460
|
+
let s = rendererSize.y;
|
|
461
|
+
let fov = camera.fov;
|
|
462
|
+
if(camera.aspect < 1){
|
|
463
|
+
fov *= camera.aspect;
|
|
464
|
+
s = rendererSize.x;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
let lambda = 2.0 * Math.tan(0.5 * fov * 0.01745329251994329576923690768489) * distance;
|
|
468
|
+
|
|
469
|
+
return (window.devicePixelRatio * 16 * lambda) / (s * scale);
|
|
460
470
|
} else if (this.boundingVolume instanceof THREE.Box3) {
|
|
461
471
|
// Region
|
|
462
472
|
// Region not supported
|