@jdultra/threedtiles 3.1.3 → 3.1.4
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/README.md +7 -25
- package/package.json +1 -1
- package/src/index.js +4 -3
- package/src/tileset/TileLoader.js +22 -12
package/README.md
CHANGED
|
@@ -34,8 +34,7 @@ setInterval(function () {
|
|
|
34
34
|
- callback on loaded geometry to assign a custom material or use the meshes for computations.
|
|
35
35
|
- Optionally load low detail tiles outside of view frustum for correct shadows and basic mesh present when the camera moves quickly.
|
|
36
36
|
- Share a cache between tileset instances
|
|
37
|
-
-
|
|
38
|
-
- Automatic scaling of the cache
|
|
37
|
+
- Optimal tile load order
|
|
39
38
|
|
|
40
39
|
### geometric Error Multiplier
|
|
41
40
|
The geometric error multiplier allows you to multiply the geometric error by a factor.
|
|
@@ -53,27 +52,6 @@ const ogc3DTile = new OGC3DTile({
|
|
|
53
52
|
A lower value will result in lower detail tiles being loaded and a higher value results in higher detail tiles being loaded.
|
|
54
53
|
A value of 1.0 is the default.
|
|
55
54
|
|
|
56
|
-
#### Automatic Geometric error multiplier
|
|
57
|
-
In order to reach a steady 60 FPS, you can specify a TilesetStats object.
|
|
58
|
-
This object is basically the Stats object from the Three.js samples without the UI component.
|
|
59
|
-
It must be updated in the animate function and given to the tileset at construction.
|
|
60
|
-
```
|
|
61
|
-
import TilesetStats from '@jdultra/threedtiles/src/tileset/TilesetStats';
|
|
62
|
-
|
|
63
|
-
const tilesetStats = TilesetStats();
|
|
64
|
-
|
|
65
|
-
const ogc3DTile = new OGC3DTile({
|
|
66
|
-
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
|
|
67
|
-
stats: tilesetStats
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
function animate() {
|
|
71
|
-
|
|
72
|
-
...
|
|
73
|
-
|
|
74
|
-
tilesetStats.update();
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
55
|
|
|
78
56
|
|
|
79
57
|
### load tiles outside of view
|
|
@@ -98,12 +76,14 @@ const ogc3DTile = new OGC3DTile({
|
|
|
98
76
|
}
|
|
99
77
|
});
|
|
100
78
|
```
|
|
79
|
+
If using a shared cache between tilesets, check out the next section.
|
|
101
80
|
|
|
102
81
|
### Cache
|
|
103
82
|
You may instanciate a cache through the TileLoader class and re-use it for several or all your tilesets.
|
|
104
83
|
The limitation is that all the tilesets using the same cache will have the same callback.
|
|
105
84
|
|
|
106
|
-
|
|
85
|
+
The TileLoader constructor takes 2 arguments. The first is a callback for meshes (see above section) and the second is
|
|
86
|
+
the maximum number of items in the cache (default is 1000).
|
|
107
87
|
|
|
108
88
|
```
|
|
109
89
|
import { TileLoader } from "@jdultra/threedtiles/src/tileset/TileLoader";
|
|
@@ -114,7 +94,9 @@ const ogc3DTile = new OGC3DTile({
|
|
|
114
94
|
//// Insert code to be called on every newly decoded mesh e.g.:
|
|
115
95
|
mesh.material.wireframe = false;
|
|
116
96
|
mesh.material.side = THREE.DoubleSide;
|
|
117
|
-
|
|
97
|
+
},
|
|
98
|
+
2000
|
|
99
|
+
),
|
|
118
100
|
meshCallback: mesh => { mesh.material.wireframe = true;} // This callback will not be used as the callback provided to the TileLoader takes priority
|
|
119
101
|
});
|
|
120
102
|
```
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import Stats from 'three/examples/jsm/libs/stats.module.js';
|
|
|
4
4
|
import { OGC3DTile } from "./tileset/OGC3DTile";
|
|
5
5
|
import { TileLoader } from "./tileset/TileLoader";
|
|
6
6
|
import { MapControls, OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
|
7
|
+
import { setIntervalAsync } from 'set-interval-async/dynamic';
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
const scene = initScene();
|
|
@@ -76,14 +77,14 @@ function initCamera() {
|
|
|
76
77
|
function initTileset(scene) {
|
|
77
78
|
|
|
78
79
|
const ogc3DTile = new OGC3DTile({
|
|
79
|
-
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
|
|
80
|
+
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tiledWithSkirts/tileset.json",
|
|
80
81
|
geometricErrorMultiplier: 1.0,
|
|
81
82
|
loadOutsideView: true,
|
|
82
83
|
tileLoader: new TileLoader(mesh => {
|
|
83
84
|
//// Insert code to be called on every newly decoded mesh e.g.:
|
|
84
85
|
mesh.material.wireframe = false;
|
|
85
86
|
mesh.material.side = THREE.DoubleSide;
|
|
86
|
-
},
|
|
87
|
+
}, 1000)
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
|
|
@@ -112,7 +113,7 @@ function initTileset(scene) {
|
|
|
112
113
|
}
|
|
113
114
|
});
|
|
114
115
|
function startInterval(){
|
|
115
|
-
interval =
|
|
116
|
+
interval = setIntervalAsync(function () {
|
|
116
117
|
ogc3DTile.update(camera);
|
|
117
118
|
}, 20);
|
|
118
119
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LinkedHashMap } from 'js-utils-z';
|
|
2
2
|
import { B3DMDecoder } from "../decoder/B3DMDecoder";
|
|
3
|
+
import { setIntervalAsync } from 'set-interval-async/dynamic';
|
|
3
4
|
|
|
4
5
|
const ready = [];
|
|
5
6
|
const downloads = [];
|
|
@@ -8,29 +9,28 @@ const nextDownloads = [];
|
|
|
8
9
|
|
|
9
10
|
function scheduleDownload(f) {
|
|
10
11
|
downloads.unshift(f);
|
|
11
|
-
//setTimeout(()=>download(),0);
|
|
12
12
|
}
|
|
13
13
|
function download() {
|
|
14
14
|
if (nextDownloads.length == 0) {
|
|
15
15
|
getNextDownloads();
|
|
16
|
-
if (nextDownloads.length == 0) return;
|
|
16
|
+
if (nextDownloads.length == 0) return 0;
|
|
17
17
|
}
|
|
18
18
|
const nextDownload = nextDownloads.shift();
|
|
19
19
|
if (!!nextDownload && nextDownload.shouldDoDownload()) {
|
|
20
20
|
nextDownload.doDownload();
|
|
21
21
|
}
|
|
22
|
+
return 1;
|
|
22
23
|
}
|
|
23
24
|
function meshReceived(cache, register, key, distanceFunction, getSiblings, level, uuid) {
|
|
24
25
|
ready.unshift([cache, register, key, distanceFunction, getSiblings, level, uuid]);
|
|
25
|
-
//setTimeout(()=>loadBatch(),1);
|
|
26
26
|
}
|
|
27
27
|
function loadBatch() {
|
|
28
28
|
if (nextReady.length == 0) {
|
|
29
29
|
getNextReady();
|
|
30
|
-
if (nextReady.length == 0) return;
|
|
30
|
+
if (nextReady.length == 0) return 0;
|
|
31
31
|
}
|
|
32
32
|
const data = nextReady.shift();
|
|
33
|
-
if (!data) return;
|
|
33
|
+
if (!data) return 0;
|
|
34
34
|
const cache = data[0];
|
|
35
35
|
const register = data[1];
|
|
36
36
|
const key = data[2];
|
|
@@ -44,6 +44,7 @@ function loadBatch() {
|
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
return 1;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
function getNextDownloads() {
|
|
@@ -115,12 +116,22 @@ function getNextReady() {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
119
|
+
setIntervalAsync(()=>{
|
|
120
|
+
const start = Date.now();
|
|
121
|
+
let uploaded = 0;
|
|
122
|
+
do{
|
|
123
|
+
uploaded = download();
|
|
124
|
+
}while(uploaded > 0 && (Date.now() - start)<= 2 )
|
|
125
|
+
|
|
126
|
+
},10);
|
|
127
|
+
setIntervalAsync(()=>{
|
|
128
|
+
const start = Date.now();
|
|
129
|
+
let loaded = 0;
|
|
130
|
+
do{
|
|
131
|
+
loaded = loadBatch();
|
|
132
|
+
}while(loaded > 0 && (Date.now() - start)<= 2 )
|
|
133
|
+
|
|
134
|
+
},10);
|
|
124
135
|
|
|
125
136
|
class TileLoader {
|
|
126
137
|
constructor(meshCallback, maxCachedItems) {
|
|
@@ -208,7 +219,6 @@ class TileLoader {
|
|
|
208
219
|
let i = 0;
|
|
209
220
|
|
|
210
221
|
while (self.cache.size() > self.maxCachedItems && i < self.cache.size()) {
|
|
211
|
-
console.log(self.cache.size())
|
|
212
222
|
i++;
|
|
213
223
|
const entry = self.cache.head();
|
|
214
224
|
const reg = self.register[entry.key];
|