@jdultra/threedtiles 8.0.1 → 9.0.1
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 +6 -2
- package/dist/threedtiles.min.js +2 -0
- package/package.json +17 -13
- package/.babelrc +0 -8
- package/.vscode/settings.json +0 -2
- package/index.html +0 -56
- package/src/decoder/B3DMDecoder.js +0 -125
- package/src/decoder/FeatureTable.js +0 -169
- package/src/decoder/LegacyGLTFLoader.js +0 -2216
- package/src/geometry/obb.js +0 -47
- package/src/images/skybox/back.png +0 -0
- package/src/images/skybox/bottom.png +0 -0
- package/src/images/skybox/front.png +0 -0
- package/src/images/skybox/left.png +0 -0
- package/src/images/skybox/right.png +0 -0
- package/src/images/skybox/top.png +0 -0
- package/src/index.js +0 -331
- package/src/tileset/OGC3DTile.js +0 -676
- package/src/tileset/OcclusionCullingService.js +0 -79
- package/src/tileset/TileLoader.js +0 -381
- package/src/tileset/instanced/InstancedOGC3DTile.js +0 -55
- package/src/tileset/instanced/InstancedTile.js +0 -588
- package/src/tileset/instanced/InstancedTileLoader.js +0 -396
- package/src/tileset/instanced/JsonTile.js +0 -41
- package/src/tileset/instanced/MeshTile.js +0 -81
- package/threedtiles.js +0 -82894
- package/threedtiles.js.map +0 -1
- package/webpack.config.js +0 -142
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import { LinkedHashMap } from 'js-utils-z';
|
|
2
|
-
import { B3DMDecoder } from "../../decoder/B3DMDecoder";
|
|
3
|
-
import { setIntervalAsync } from 'set-interval-async/dynamic';
|
|
4
|
-
import * as THREE from 'three';
|
|
5
|
-
import { MeshTile } from './MeshTile';
|
|
6
|
-
import { JsonTile } from './JsonTile';
|
|
7
|
-
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
8
|
-
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
9
|
-
import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader";
|
|
10
|
-
|
|
11
|
-
let concurentDownloads = 0;
|
|
12
|
-
|
|
13
|
-
const zUpToYUpMatrix = new THREE.Matrix4();
|
|
14
|
-
zUpToYUpMatrix.set(1, 0, 0, 0,
|
|
15
|
-
0, 0, -1, 0,
|
|
16
|
-
0, 1, 0, 0,
|
|
17
|
-
0, 0, 0, 1);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A Tile loader that manages caching and load order for instanced tiles.
|
|
21
|
-
* The cache is an LRU cache and is defined by the number of items it can hold.
|
|
22
|
-
* The actual number of cached items might grow beyond max if all items are in use.
|
|
23
|
-
*
|
|
24
|
-
* The load order is designed for optimal perceived loading speed (nearby tiles are refined first).
|
|
25
|
-
*
|
|
26
|
-
* @param {scene} [scene] - a threejs scene.
|
|
27
|
-
* @param {Object} [options] - Optional configuration object.
|
|
28
|
-
* @param {number} [options.maxCachedItems=100] - the cache size.
|
|
29
|
-
* @param {number} [options.maxInstances=1] - the cache size.
|
|
30
|
-
* @param {function} [options.meshCallback] - A callback to call on newly decoded meshes.
|
|
31
|
-
* @param {function} [options.pointsCallback] - A callback to call on newly decoded points.
|
|
32
|
-
* @param {renderer} [options.renderer] - The renderer, this is required for KTX2 support.
|
|
33
|
-
*/
|
|
34
|
-
class InstancedTileLoader {
|
|
35
|
-
constructor(scene, options) {
|
|
36
|
-
this.maxCachedItems = 100;
|
|
37
|
-
this.maxInstances = 1;
|
|
38
|
-
if (!!options) {
|
|
39
|
-
this.meshCallback = options.meshCallback;
|
|
40
|
-
this.pointsCallback = options.pointsCallback;
|
|
41
|
-
if (options.maxCachedItems) this.maxCachedItems = options.maxCachedItems;
|
|
42
|
-
if (options.maxInstances) this.maxInstances = options.maxInstances;
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
this.gltfLoader = new GLTFLoader();
|
|
46
|
-
const dracoLoader = new DRACOLoader();
|
|
47
|
-
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.4.3/');
|
|
48
|
-
this.gltfLoader.setDRACOLoader(dracoLoader);
|
|
49
|
-
|
|
50
|
-
if(!!options && !!options.renderer){
|
|
51
|
-
const ktx2Loader = new KTX2Loader();
|
|
52
|
-
ktx2Loader.setTranscoderPath('https://storage.googleapis.com/ogc-3d-tiles/basis/').detectSupport(options.renderer);
|
|
53
|
-
this.gltfLoader.setKTX2Loader(ktx2Loader);
|
|
54
|
-
|
|
55
|
-
this.b3dmDecoder=new B3DMDecoder(options.renderer);
|
|
56
|
-
}else{
|
|
57
|
-
this.b3dmDecoder=new B3DMDecoder(null);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.cache = new LinkedHashMap();
|
|
61
|
-
this.scene = scene;
|
|
62
|
-
|
|
63
|
-
this.ready = [];
|
|
64
|
-
this.downloads = [];
|
|
65
|
-
this.nextReady = [];
|
|
66
|
-
this.nextDownloads = [];
|
|
67
|
-
this.init();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
update() {
|
|
72
|
-
const self = this;
|
|
73
|
-
|
|
74
|
-
self.cache._data.forEach(v => {
|
|
75
|
-
v.update();
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
init() {
|
|
80
|
-
|
|
81
|
-
const self = this;
|
|
82
|
-
setIntervalAsync(() => {
|
|
83
|
-
self.download();
|
|
84
|
-
}, 10);
|
|
85
|
-
setIntervalAsync(() => {
|
|
86
|
-
const start = Date.now();
|
|
87
|
-
let loaded = 0;
|
|
88
|
-
do {
|
|
89
|
-
loaded = self.loadBatch();
|
|
90
|
-
} while (loaded > 0 && (Date.now() - start) <= 0)
|
|
91
|
-
|
|
92
|
-
}, 10);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
download() {
|
|
96
|
-
const self = this;
|
|
97
|
-
if (self.nextDownloads.length == 0) {
|
|
98
|
-
self.getNextDownloads();
|
|
99
|
-
if (self.nextDownloads.length == 0) return;
|
|
100
|
-
}
|
|
101
|
-
while (self.nextDownloads.length > 0 && concurentDownloads < 500) {
|
|
102
|
-
const nextDownload = self.nextDownloads.shift();
|
|
103
|
-
if (!!nextDownload && nextDownload.shouldDoDownload()) {
|
|
104
|
-
//nextDownload.doDownload();
|
|
105
|
-
concurentDownloads++;
|
|
106
|
-
if (nextDownload.path.includes(".b3dm")) {
|
|
107
|
-
fetch(nextDownload.path, { signal: nextDownload.abortController.signal }).then(result => {
|
|
108
|
-
concurentDownloads--;
|
|
109
|
-
if (!result.ok) {
|
|
110
|
-
console.error("could not load tile with path : " + path)
|
|
111
|
-
throw new Error(`couldn't load "${path}". Request failed with status ${result.status} : ${result.statusText}`);
|
|
112
|
-
}
|
|
113
|
-
return result.arrayBuffer();
|
|
114
|
-
|
|
115
|
-
})
|
|
116
|
-
.then(resultArrayBuffer => {
|
|
117
|
-
return this.b3dmDecoder.parseB3DMInstanced(resultArrayBuffer, self.meshCallback, self.maxInstances, nextDownload.zUpToYUp);
|
|
118
|
-
})
|
|
119
|
-
.then(mesh => {
|
|
120
|
-
nextDownload.tile.setObject(mesh);
|
|
121
|
-
self.ready.unshift(nextDownload);
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
.catch(e => console.error(e));
|
|
125
|
-
} if (nextDownload.path.includes(".glb") || (nextDownload.path.includes(".gltf"))) {
|
|
126
|
-
this.gltfLoader.load(nextDownload.path, gltf => {
|
|
127
|
-
gltf.scene.traverse((o) => {
|
|
128
|
-
o.geometricError = nextDownload.geometricError;
|
|
129
|
-
if (o.isMesh) {
|
|
130
|
-
if (nextDownload.zUpToYUp) {
|
|
131
|
-
o.applyMatrix4(zUpToYUpMatrix);
|
|
132
|
-
}
|
|
133
|
-
if (!!self.meshCallback) {
|
|
134
|
-
self.meshCallback(o);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (o.isPoints) {
|
|
138
|
-
console.error("instanced point cloud is not supported");
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
let instancedMesh;
|
|
142
|
-
gltf.scene.updateWorldMatrix(false, true)
|
|
143
|
-
gltf.scene.traverse(child => {
|
|
144
|
-
//TODO several meshes in a single gltf
|
|
145
|
-
if (child.isMesh) {
|
|
146
|
-
instancedMesh = new THREE.InstancedMesh(child.geometry, child.material, self.maxInstances);
|
|
147
|
-
instancedMesh.baseMatrix = child.matrixWorld;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
self.ready.unshift(nextDownload);
|
|
152
|
-
if (!instancedMesh) {
|
|
153
|
-
gltf.scene.traverse(c => {
|
|
154
|
-
if (c.dispose) c.dispose();
|
|
155
|
-
if (c.material) c.material.dispose();
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
nextDownload.tile.setObject(instancedMesh);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
} else if (nextDownload.path.includes(".json")) {
|
|
163
|
-
concurentDownloads++;
|
|
164
|
-
fetch(nextDownload.path, { signal: nextDownload.abortController.signal }).then(result => {
|
|
165
|
-
concurentDownloads--;
|
|
166
|
-
if (!result.ok) {
|
|
167
|
-
console.error("could not load tile with path : " + path)
|
|
168
|
-
throw new Error(`couldn't load "${path}". Request failed with status ${result.status} : ${result.statusText}`);
|
|
169
|
-
}
|
|
170
|
-
return result.json();
|
|
171
|
-
|
|
172
|
-
}).then(json => {
|
|
173
|
-
nextDownload.tile.setObject(json, nextDownload.path);
|
|
174
|
-
self.ready.unshift(nextDownload);
|
|
175
|
-
})
|
|
176
|
-
.catch(e => console.error(e))
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
loadBatch() {
|
|
184
|
-
if (this.nextReady.length == 0) {
|
|
185
|
-
this.getNextReady();
|
|
186
|
-
if (this.nextReady.length == 0) return 0;
|
|
187
|
-
}
|
|
188
|
-
const download = this.nextReady.shift();
|
|
189
|
-
if (!download) return 0;
|
|
190
|
-
|
|
191
|
-
if (!!download.tile.addToScene) download.tile.addToScene();
|
|
192
|
-
return 1;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
getNextReady() {
|
|
196
|
-
let smallestDistance = Number.MAX_VALUE;
|
|
197
|
-
let closest = -1;
|
|
198
|
-
for (let i = this.ready.length - 1; i >= 0; i--) {
|
|
199
|
-
|
|
200
|
-
if (!this.ready[i].distanceFunction) {// if no distance function, must be a json, give absolute priority!
|
|
201
|
-
this.nextReady.push(this.ready.splice(i, 1)[0]);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (this.nextReady.length > 0) return;
|
|
205
|
-
for (let i = this.ready.length - 1; i >= 0; i--) {
|
|
206
|
-
const dist = this.ready[i].distanceFunction() * this.ready[i].level;
|
|
207
|
-
if (dist < smallestDistance) {
|
|
208
|
-
smallestDistance = dist;
|
|
209
|
-
closest = i
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (closest >= 0) {
|
|
213
|
-
const closestItem = this.ready.splice(closest, 1).pop();
|
|
214
|
-
this.nextReady.push(closestItem);
|
|
215
|
-
const siblings = closestItem.getSiblings();
|
|
216
|
-
for (let i = this.ready.length - 1; i >= 0; i--) {
|
|
217
|
-
if (siblings.includes(this.ready[i].uuid)) {
|
|
218
|
-
this.nextready.push(this.ready.splice(i, 1).pop());
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
get(abortController, path, uuid, instancedOGC3DTile, distanceFunction, getSiblings, level, zUpToYUp, geometricError) {
|
|
225
|
-
const self = this;
|
|
226
|
-
const key = simplifyPath(path);
|
|
227
|
-
|
|
228
|
-
if (!path.includes(".b3dm") && !path.includes(".json") && !path.includes(".glb") && !path.includes(".gltf")) {
|
|
229
|
-
console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const cachedTile = self.cache.get(key);
|
|
234
|
-
if (!!cachedTile) {
|
|
235
|
-
cachedTile.addInstance(instancedOGC3DTile);
|
|
236
|
-
return;
|
|
237
|
-
} else {
|
|
238
|
-
|
|
239
|
-
if (path.includes(".b3dm") || path.includes(".glb") || path.includes(".gltf")) {
|
|
240
|
-
const tile = new MeshTile(self.scene);
|
|
241
|
-
tile.addInstance(instancedOGC3DTile);
|
|
242
|
-
|
|
243
|
-
self.cache.put(key, tile);
|
|
244
|
-
|
|
245
|
-
const realAbortController = new AbortController();
|
|
246
|
-
abortController.signal.addEventListener("abort", () => {
|
|
247
|
-
if (tile.getCount() == 0) {
|
|
248
|
-
realAbortController.abort();
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
this.downloads.push({
|
|
252
|
-
abortController: realAbortController,
|
|
253
|
-
tile: tile,
|
|
254
|
-
key: key,
|
|
255
|
-
path: path,
|
|
256
|
-
distanceFunction: distanceFunction,
|
|
257
|
-
getSiblings: getSiblings,
|
|
258
|
-
level: level,
|
|
259
|
-
uuid: uuid,
|
|
260
|
-
zUpToYUp: zUpToYUp,
|
|
261
|
-
geometricError: geometricError,
|
|
262
|
-
shouldDoDownload: () => {
|
|
263
|
-
return true;
|
|
264
|
-
},
|
|
265
|
-
})
|
|
266
|
-
} else if (path.includes(".json")) {
|
|
267
|
-
const tile = new JsonTile();
|
|
268
|
-
tile.addInstance(instancedOGC3DTile);
|
|
269
|
-
self.cache.put(key, tile);
|
|
270
|
-
|
|
271
|
-
const realAbortController = new AbortController();
|
|
272
|
-
abortController.signal.addEventListener("abort", () => {
|
|
273
|
-
if (tile.getCount() == 0) {
|
|
274
|
-
realAbortController.abort();
|
|
275
|
-
}
|
|
276
|
-
})
|
|
277
|
-
this.downloads.push({
|
|
278
|
-
abortController: realAbortController,
|
|
279
|
-
tile: tile,
|
|
280
|
-
key: key,
|
|
281
|
-
path: path,
|
|
282
|
-
distanceFunction: distanceFunction,
|
|
283
|
-
getSiblings: getSiblings,
|
|
284
|
-
level: level,
|
|
285
|
-
shouldDoDownload: () => {
|
|
286
|
-
return true;
|
|
287
|
-
},
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
getNextDownloads() {
|
|
297
|
-
let smallestDistance = Number.MAX_VALUE;
|
|
298
|
-
let closest = -1;
|
|
299
|
-
for (let i = this.downloads.length - 1; i >= 0; i--) {
|
|
300
|
-
const download = this.downloads[i];
|
|
301
|
-
if (!download.shouldDoDownload()) {
|
|
302
|
-
this.downloads.splice(i, 1);
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (!download.distanceFunction) { // if no distance function, must be a json, give absolute priority!
|
|
306
|
-
this.nextDownloads.push(this.downloads.splice(i, 1)[0]);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
if (this.nextDownloads.length > 0) return;
|
|
310
|
-
for (let i = this.downloads.length - 1; i >= 0; i--) {
|
|
311
|
-
const download = this.downloads[i];
|
|
312
|
-
const dist = download.distanceFunction() * download.level;
|
|
313
|
-
if (dist < smallestDistance) {
|
|
314
|
-
smallestDistance = dist;
|
|
315
|
-
closest = i;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (closest >= 0) {
|
|
319
|
-
const closestItem = this.downloads.splice(closest, 1).pop();
|
|
320
|
-
this.nextDownloads.push(closestItem);
|
|
321
|
-
const siblings = closestItem.getSiblings();
|
|
322
|
-
for (let i = this.downloads.length - 1; i >= 0; i--) {
|
|
323
|
-
if (siblings.includes(this.downloads[i].uuid)) {
|
|
324
|
-
this.nextDownloads.push(this.downloads.splice(i, 1).pop());
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
checkSize() {
|
|
331
|
-
const self = this;
|
|
332
|
-
|
|
333
|
-
let i = 0;
|
|
334
|
-
|
|
335
|
-
while (self.cache.size() > self.maxCachedItems && i < self.cache.size()) {
|
|
336
|
-
i++;
|
|
337
|
-
const entry = self.cache.head();
|
|
338
|
-
if (entry.value.getCount() > 0) {
|
|
339
|
-
self.cache.remove(entry.key);
|
|
340
|
-
self.cache.put(entry.key, entry.value);
|
|
341
|
-
} else {
|
|
342
|
-
self.cache.remove(entry.key);
|
|
343
|
-
if (entry.value.instancedMesh) {
|
|
344
|
-
entry.value.instancedMesh.traverse((o) => {
|
|
345
|
-
if (o.material) {
|
|
346
|
-
// dispose materials
|
|
347
|
-
if (o.material.length) {
|
|
348
|
-
for (let i = 0; i < o.material.length; ++i) {
|
|
349
|
-
o.material[i].dispose();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
o.material.dispose()
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (o.geometry) {
|
|
357
|
-
// dispose geometry
|
|
358
|
-
o.geometry.dispose();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function simplifyPath(main_path) {
|
|
369
|
-
|
|
370
|
-
var parts = main_path.split('/'),
|
|
371
|
-
new_path = [],
|
|
372
|
-
length = 0;
|
|
373
|
-
for (var i = 0; i < parts.length; i++) {
|
|
374
|
-
var part = parts[i];
|
|
375
|
-
if (part === '.' || part === '' || part === '..') {
|
|
376
|
-
if (part === '..' && length > 0) {
|
|
377
|
-
length--;
|
|
378
|
-
}
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
new_path[length++] = part;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (length === 0) {
|
|
385
|
-
return '/';
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
var result = '';
|
|
389
|
-
for (var i = 0; i < length; i++) {
|
|
390
|
-
result += '/' + new_path[i];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
return result;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export { InstancedTileLoader };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class JsonTile{
|
|
4
|
-
constructor(){
|
|
5
|
-
const self = this;
|
|
6
|
-
self.count = 0;
|
|
7
|
-
self.json;
|
|
8
|
-
self.instancedTiles = [];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
addInstance(instanceTile){
|
|
12
|
-
this.instancedTiles.push(instanceTile);
|
|
13
|
-
if(this.json){
|
|
14
|
-
instanceTile.loadJson(this.json, this.url)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
setObject(json, url){
|
|
21
|
-
const self = this;
|
|
22
|
-
self.json = json;
|
|
23
|
-
self.url = url;
|
|
24
|
-
for(let i = 0; i<self.instancedTiles.length; i++){
|
|
25
|
-
self.instancedTiles[i].loadJson( self.json, self.url );
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getCount(){
|
|
30
|
-
return this.instancedTiles.length;
|
|
31
|
-
}
|
|
32
|
-
update(){
|
|
33
|
-
const self = this;
|
|
34
|
-
for(let i = self.instancedTiles.length-1; i>=0; i--){
|
|
35
|
-
if(self.instancedTiles[i].deleted){
|
|
36
|
-
self.instancedTiles.splice(i,1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}export { JsonTile };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { InstancedMesh } from 'three';
|
|
3
|
-
|
|
4
|
-
const t = new THREE.Matrix4();
|
|
5
|
-
class MeshTile{
|
|
6
|
-
constructor(scene){
|
|
7
|
-
const self = this;
|
|
8
|
-
self.scene = scene;
|
|
9
|
-
self.instancedTiles = [];
|
|
10
|
-
self.instancedMesh;
|
|
11
|
-
|
|
12
|
-
self.reuseableMatrix = new THREE.Matrix4();
|
|
13
|
-
}
|
|
14
|
-
addInstance(instancedTile){
|
|
15
|
-
const self = this;
|
|
16
|
-
instancedTile.added = true;
|
|
17
|
-
instancedTile.listOMesh = self.instancedTiles;
|
|
18
|
-
self.instancedTiles.push(instancedTile);
|
|
19
|
-
if(self.instancedMesh){
|
|
20
|
-
instancedTile.loadMesh(self.instancedMesh)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
addToScene(){
|
|
25
|
-
//this.instancedMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
|
|
26
|
-
const self = this;
|
|
27
|
-
self.instancedMesh.setMatrixAt(0,new THREE.Matrix4());
|
|
28
|
-
self.instancedMesh.instanceMatrix.needsUpdate = true;
|
|
29
|
-
self.instancedMesh.count = 1;
|
|
30
|
-
|
|
31
|
-
self.scene.add(self.instancedMesh);
|
|
32
|
-
self.instancedMesh.onAfterRender = () => {
|
|
33
|
-
delete self.instancedMesh.onAfterRender;
|
|
34
|
-
self.instancedMesh.displayedOnce = true;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
setObject(instancedMesh){
|
|
39
|
-
const self = this;
|
|
40
|
-
self.instancedMesh = instancedMesh;
|
|
41
|
-
|
|
42
|
-
for(let i = 0; i<self.instancedTiles.length; i++){
|
|
43
|
-
self.instancedTiles[i].loadMesh(self.instancedMesh)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
update(){
|
|
48
|
-
const self = this;
|
|
49
|
-
|
|
50
|
-
for(let i = self.instancedTiles.length-1; i>=0; i--){
|
|
51
|
-
if(self.instancedTiles[i].deleted){
|
|
52
|
-
self.instancedTiles.splice(i,1);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if(!!self.instancedMesh){
|
|
57
|
-
|
|
58
|
-
self.instancedMesh.count = 0;
|
|
59
|
-
|
|
60
|
-
for(let i = 0; i<self.instancedTiles.length; i++){
|
|
61
|
-
self.instancedTiles[i].meshContent = self.instancedMesh;
|
|
62
|
-
if(self.instancedTiles[i].materialVisibility && !!self.instancedTiles[i].meshContent){
|
|
63
|
-
self.instancedMesh.count++;
|
|
64
|
-
self.reuseableMatrix.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);
|
|
65
|
-
self.reuseableMatrix.multiply(self.instancedTiles[i].master.matrixWorld);
|
|
66
|
-
self.reuseableMatrix.multiply(self.instancedMesh.baseMatrix);
|
|
67
|
-
self.instancedMesh.setMatrixAt(self.instancedMesh.count-1, self.reuseableMatrix );
|
|
68
|
-
self.instancedMesh.getMatrixAt(0, t);
|
|
69
|
-
console.log()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
self.instancedMesh.instanceMatrix.needsUpdate = true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getCount(){
|
|
78
|
-
return this.instancedTiles.length;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}export { MeshTile };
|