@file-viewer/renderer-3d 3.1.1 → 3.2.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/GEO3D.md +505 -0
- package/GEO3D_THIRD_PARTY_NOTICES.md +63 -0
- package/IFC.md +14 -1
- package/README.en.md +3 -35
- package/README.md +3 -35
- package/bin/copy-geo3d-assets.mjs +143 -0
- package/bin/copy-ifc-assets.mjs +52 -16
- package/dist/geo3d-workers/geotiff-worker.js +9 -0
- package/dist/geo3d-workers/las-worker.js +3858 -0
- package/dist/geo3d-workers/licenses/_giro3d_giro3d-LICENSE +10 -0
- package/dist/geo3d-workers/licenses/copc-license +21 -0
- package/dist/geo3d-workers/licenses/cross-fetch-LICENSE +21 -0
- package/dist/geo3d-workers/licenses/laz-perf-COPYING.txt +202 -0
- package/dist/geo3d-workers/licenses/mgrs-license.md +19 -0
- package/dist/geo3d-workers/licenses/ol-LICENSE.md +25 -0
- package/dist/geo3d-workers/licenses/proj4-LICENSE.md +29 -0
- package/dist/geo3d-workers/licenses/three-LICENSE +21 -0
- package/dist/geo3d-workers/licenses/wkt-parser-LICENSE.md +29 -0
- package/dist/geo3d-workers/manifest.json +203 -0
- package/dist/geo3d-workers/raster-licenses/_giro3d_giro3d-LICENSE +10 -0
- package/dist/geo3d-workers/raster-licenses/_petamoriken_float16-LICENSE +21 -0
- package/dist/geo3d-workers/raster-licenses/geotiff-LICENSE +22 -0
- package/dist/geo3d-workers/raster-licenses/lerc-LICENSE +101 -0
- package/dist/geo3d-workers/raster-licenses/lerc-NOTICE +23 -0
- package/dist/geo3d-workers/raster-licenses/pako-LICENSE +21 -0
- package/dist/geo3d-workers/raster-licenses/quick-lru-license +9 -0
- package/dist/geo3d-workers/raster-licenses/web-worker-LICENSE +201 -0
- package/dist/geo3d-workers/raster-licenses/xml-utils-LICENSE +121 -0
- package/dist/geo3d-workers/raster-licenses/zstddec-LICENSE +54 -0
- package/dist/geo3d-workers/texture-worker.js +1 -0
- package/dist/geo3d.d.ts +10 -0
- package/dist/geo3d.js +38 -0
- package/dist/geo3dArchive.d.ts +25 -0
- package/dist/geo3dArchive.js +393 -0
- package/dist/geo3dCityJson.d.ts +65 -0
- package/dist/geo3dCityJson.js +354 -0
- package/dist/geo3dCrs.d.ts +8 -0
- package/dist/geo3dCrs.js +18 -0
- package/dist/geo3dHooks.d.ts +4 -0
- package/dist/geo3dHooks.js +91 -0
- package/dist/geo3dInspect.d.ts +32 -0
- package/dist/geo3dInspect.js +410 -0
- package/dist/geo3dLasWorkers.d.ts +6 -0
- package/dist/geo3dLasWorkers.js +59 -0
- package/dist/geo3dOwnedWorkerPool.d.ts +31 -0
- package/dist/geo3dOwnedWorkerPool.js +209 -0
- package/dist/geo3dPointFactories.js +3835 -0
- package/dist/geo3dPointMaterial.d.ts +2 -0
- package/dist/geo3dPointMaterial.js +54 -0
- package/dist/geo3dRange.d.ts +11 -0
- package/dist/geo3dRange.js +151 -0
- package/dist/geo3dRasterFactories.js +32 -0
- package/dist/geo3dRasterWorkers.d.ts +14 -0
- package/dist/geo3dRasterWorkers.js +48 -0
- package/dist/geo3dRuntime.d.ts +144 -0
- package/dist/geo3dRuntime.js +378 -0
- package/dist/geo3dUrl.d.ts +1 -0
- package/dist/geo3dUrl.js +5 -0
- package/dist/ifc-import.worker.js +0 -2
- package/dist/ifc.d.ts +0 -9
- package/dist/ifc.js +0 -1
- package/dist/ifcRuntime.js +4 -9
- package/dist/ifcSettings.d.ts +0 -3
- package/dist/ifcSettings.js +0 -3
- package/dist/model.js +0 -4
- package/dist/occtModel.js +0 -2
- package/licenses/laz-perf-COPYING.txt +202 -0
- package/licenses/laz-perf-PROVENANCE.md +22 -0
- package/licenses/lerc-LICENSE +101 -0
- package/licenses/lerc-NOTICE +23 -0
- package/licenses/lerc-PROVENANCE.md +37 -0
- package/licenses/thatopen-components-MIT.txt +18 -0
- package/package.json +115 -29
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { checkAbort } from './geo3dRange.js';
|
|
2
|
+
const utf8 = new TextDecoder('utf-8', { fatal: true });
|
|
3
|
+
const DEFAULTS = {
|
|
4
|
+
maxEntries: 4096,
|
|
5
|
+
maxExpandedBytes: 512 * 1024 * 1024,
|
|
6
|
+
maxEntryBytes: 128 * 1024 * 1024,
|
|
7
|
+
maxCompressionRatio: 200
|
|
8
|
+
};
|
|
9
|
+
function limitsFor(options) {
|
|
10
|
+
const limits = { ...DEFAULTS };
|
|
11
|
+
for (const key of Object.keys(DEFAULTS)) {
|
|
12
|
+
const value = options[key] ?? DEFAULTS[key];
|
|
13
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > DEFAULTS[key])
|
|
14
|
+
throw new Error(`Invalid 3TZ ${key}; limits cannot exceed the browser safety ceiling.`);
|
|
15
|
+
limits[key] = value;
|
|
16
|
+
}
|
|
17
|
+
return limits;
|
|
18
|
+
}
|
|
19
|
+
function normalizeArchivePath(raw) {
|
|
20
|
+
if (!raw || raw.length > 1024 || /[\0-\x1f]/.test(raw))
|
|
21
|
+
throw new Error('3TZ contains an invalid empty/NUL path.');
|
|
22
|
+
if (/^[\\/]|^[a-z][a-z0-9+.-]*:/i.test(raw))
|
|
23
|
+
throw new Error('3TZ contains an absolute path.');
|
|
24
|
+
const value = raw.replace(/\\/g, '/');
|
|
25
|
+
const parts = value.split('/').filter(Boolean);
|
|
26
|
+
let decoded;
|
|
27
|
+
try {
|
|
28
|
+
decoded = decodeURIComponent(value);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error('3TZ contains invalid path encoding.');
|
|
32
|
+
}
|
|
33
|
+
if (parts.some((p) => p === '.' || p === '..') ||
|
|
34
|
+
decoded.split(/[\\/]/).some((p) => p === '.' || p === '..') ||
|
|
35
|
+
/^[\\/]|^[a-z][a-z0-9+.-]*:/i.test(decoded))
|
|
36
|
+
throw new Error('3TZ contains path traversal.');
|
|
37
|
+
return parts.join('/') + (value.endsWith('/') ? '/' : '');
|
|
38
|
+
}
|
|
39
|
+
export function inspect3tzCentralDirectory(bytes, options = {}) {
|
|
40
|
+
const limits = limitsFor(options), view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
41
|
+
const u16 = (p) => view.getUint16(p, true), u32 = (p) => view.getUint32(p, true);
|
|
42
|
+
let eocd = -1;
|
|
43
|
+
for (let p = bytes.length - 22; p >= Math.max(0, bytes.length - 22 - 65535); p--) {
|
|
44
|
+
if (u32(p) === 0x06054b50 && p + 22 + u16(p + 20) === bytes.length) {
|
|
45
|
+
eocd = p;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (eocd < 0)
|
|
50
|
+
throw new Error('3TZ is missing the ZIP end-of-central-directory record.');
|
|
51
|
+
const count = u16(eocd + 10), size = u32(eocd + 12), start = u32(eocd + 16);
|
|
52
|
+
if (u16(eocd + 4) || u16(eocd + 6) || u16(eocd + 8) !== count)
|
|
53
|
+
throw new Error('3TZ multi-disk ZIP archives are not supported.');
|
|
54
|
+
if (count === 65535 || size === 0xffffffff || start === 0xffffffff)
|
|
55
|
+
throw new Error('3TZ ZIP64 archives are not supported by the bounded browser extractor.');
|
|
56
|
+
if (count > limits.maxEntries)
|
|
57
|
+
throw new Error('3TZ entry count exceeds maxEntries.');
|
|
58
|
+
if (start + size !== eocd)
|
|
59
|
+
throw new Error('3TZ central directory bounds are invalid.');
|
|
60
|
+
const entries = [], seen = new Set(), regions = [];
|
|
61
|
+
let cursor = start, total = 0;
|
|
62
|
+
for (let i = 0; i < count; i++) {
|
|
63
|
+
if (cursor + 46 > eocd || u32(cursor) !== 0x02014b50)
|
|
64
|
+
throw new Error('3TZ central directory is truncated or malformed.');
|
|
65
|
+
const flags = u16(cursor + 8), method = u16(cursor + 10), crc = u32(cursor + 16), compressedSize = u32(cursor + 20), uncompressedSize = u32(cursor + 24);
|
|
66
|
+
const nameLength = u16(cursor + 28), extraLength = u16(cursor + 30), commentLength = u16(cursor + 32), local = u32(cursor + 42);
|
|
67
|
+
const nameEnd = cursor + 46 + nameLength, next = nameEnd + extraLength + commentLength;
|
|
68
|
+
if (next > eocd)
|
|
69
|
+
throw new Error('3TZ central directory entry exceeds its bounds.');
|
|
70
|
+
if (flags & 1)
|
|
71
|
+
throw new Error('Encrypted 3TZ entries are not supported.');
|
|
72
|
+
if (flags & 8)
|
|
73
|
+
throw new Error('3TZ local headers must include sizes and CRC; data descriptors are unsupported.');
|
|
74
|
+
if (method !== 0 && method !== 8)
|
|
75
|
+
throw new Error('Unsupported 3TZ compression; only stored and DEFLATE entries are supported.');
|
|
76
|
+
if ([compressedSize, uncompressedSize, local].includes(0xffffffff))
|
|
77
|
+
throw new Error('3TZ ZIP64 entry is not supported.');
|
|
78
|
+
if (u16(cursor + 34) !== 0 || ((u32(cursor + 38) >>> 16) & 0xf000) === 0xa000)
|
|
79
|
+
throw new Error('3TZ disk/symlink entry is not supported.');
|
|
80
|
+
for (let p = nameEnd; p < nameEnd + extraLength;) {
|
|
81
|
+
if (p + 4 > nameEnd + extraLength || p + 4 + u16(p + 2) > nameEnd + extraLength)
|
|
82
|
+
throw new Error('Truncated 3TZ extra field.');
|
|
83
|
+
if ([0x0001, 0x7075].includes(u16(p)))
|
|
84
|
+
throw new Error('3TZ ZIP64 or alternate Unicode paths are unsupported.');
|
|
85
|
+
p += 4 + u16(p + 2);
|
|
86
|
+
}
|
|
87
|
+
const raw = utf8.decode(bytes.subarray(cursor + 46, nameEnd)), name = normalizeArchivePath(raw);
|
|
88
|
+
if (seen.has(name.toLowerCase()))
|
|
89
|
+
throw new Error(`3TZ contains duplicate path: ${name}`);
|
|
90
|
+
seen.add(name.toLowerCase());
|
|
91
|
+
if (local + 30 > start || u32(local) !== 0x04034b50)
|
|
92
|
+
throw new Error('Invalid 3TZ local file header.');
|
|
93
|
+
const localName = u16(local + 26), localExtra = u16(local + 28), dataStart = local + 30 + localName + localExtra, dataEnd = dataStart + compressedSize;
|
|
94
|
+
if (dataEnd > start ||
|
|
95
|
+
flags !== u16(local + 6) ||
|
|
96
|
+
method !== u16(local + 8) ||
|
|
97
|
+
crc !== u32(local + 14) ||
|
|
98
|
+
compressedSize !== u32(local + 18) ||
|
|
99
|
+
uncompressedSize !== u32(local + 22) ||
|
|
100
|
+
utf8.decode(bytes.subarray(local + 30, local + 30 + localName)) !== raw)
|
|
101
|
+
throw new Error('3TZ local and central headers disagree.');
|
|
102
|
+
regions.push([local, dataEnd]);
|
|
103
|
+
if (method === 0 && compressedSize !== uncompressedSize)
|
|
104
|
+
throw new Error('Invalid stored 3TZ entry size.');
|
|
105
|
+
if (uncompressedSize > limits.maxEntryBytes)
|
|
106
|
+
throw new Error('3TZ entry exceeds maxEntryBytes.');
|
|
107
|
+
total += uncompressedSize;
|
|
108
|
+
if (total > limits.maxExpandedBytes)
|
|
109
|
+
throw new Error('3TZ expanded size exceeds maxExpandedBytes.');
|
|
110
|
+
if (uncompressedSize / Math.max(1, compressedSize) > limits.maxCompressionRatio)
|
|
111
|
+
throw new Error('3TZ entry exceeds maxCompressionRatio.');
|
|
112
|
+
if (!name.endsWith('/'))
|
|
113
|
+
entries.push({ name, compressedSize, uncompressedSize, crc });
|
|
114
|
+
else if (uncompressedSize !== 0)
|
|
115
|
+
throw new Error('3TZ directory contains an unexpected payload.');
|
|
116
|
+
cursor = next;
|
|
117
|
+
}
|
|
118
|
+
if (cursor !== eocd)
|
|
119
|
+
throw new Error('3TZ central directory size/count mismatch.');
|
|
120
|
+
regions.sort((a, b) => a[0] - b[0]);
|
|
121
|
+
if (regions.some((r, i) => i > 0 && r[0] < regions[i - 1][1]))
|
|
122
|
+
throw new Error('3TZ local entries overlap.');
|
|
123
|
+
if (!entries.some((e) => e.name === 'tileset.json'))
|
|
124
|
+
throw new Error('3TZ must contain tileset.json at the archive root.');
|
|
125
|
+
return { entries, totalExpandedBytes: total };
|
|
126
|
+
}
|
|
127
|
+
const crcTable = Array.from({ length: 256 }, (_, n) => {
|
|
128
|
+
for (let i = 0; i < 8; i++)
|
|
129
|
+
n = n & 1 ? 0xedb88320 ^ (n >>> 1) : n >>> 1;
|
|
130
|
+
return n >>> 0;
|
|
131
|
+
});
|
|
132
|
+
function boundedExtract(file, entry, signal) {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
checkAbort(signal);
|
|
135
|
+
const stream = file.internalStream('uint8array'), result = new Uint8Array(entry.uncompressedSize);
|
|
136
|
+
let offset = 0, crc = 0xffffffff, settled = false;
|
|
137
|
+
const fail = (error) => {
|
|
138
|
+
if (settled)
|
|
139
|
+
return;
|
|
140
|
+
settled = true;
|
|
141
|
+
stream.pause();
|
|
142
|
+
signal?.removeEventListener('abort', abort);
|
|
143
|
+
reject(error);
|
|
144
|
+
};
|
|
145
|
+
const abort = () => fail(signal?.reason || new DOMException('3TZ extraction aborted.', 'AbortError'));
|
|
146
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
147
|
+
stream
|
|
148
|
+
.on('data', (chunk) => {
|
|
149
|
+
if (settled)
|
|
150
|
+
return;
|
|
151
|
+
if (offset + chunk.length > result.length) {
|
|
152
|
+
fail(new Error('3TZ actual expanded size exceeds declared size.'));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
result.set(chunk, offset);
|
|
156
|
+
offset += chunk.length;
|
|
157
|
+
for (const byte of chunk)
|
|
158
|
+
crc = crcTable[(crc ^ byte) & 255] ^ (crc >>> 8);
|
|
159
|
+
})
|
|
160
|
+
.on('error', fail)
|
|
161
|
+
.on('end', () => {
|
|
162
|
+
if (settled)
|
|
163
|
+
return;
|
|
164
|
+
if (offset !== result.length || (crc ^ 0xffffffff) >>> 0 !== entry.crc) {
|
|
165
|
+
fail(new Error('3TZ expanded size or CRC32 mismatch.'));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
settled = true;
|
|
169
|
+
signal?.removeEventListener('abort', abort);
|
|
170
|
+
resolve(result);
|
|
171
|
+
})
|
|
172
|
+
.resume();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const mimeFor = (name) => /\.gltf$/i.test(name)
|
|
176
|
+
? 'model/gltf+json'
|
|
177
|
+
: /\.glb$/i.test(name)
|
|
178
|
+
? 'model/gltf-binary'
|
|
179
|
+
: /\.json$/i.test(name)
|
|
180
|
+
? 'application/json'
|
|
181
|
+
: /\.png$/i.test(name)
|
|
182
|
+
? 'image/png'
|
|
183
|
+
: /\.jpe?g$/i.test(name)
|
|
184
|
+
? 'image/jpeg'
|
|
185
|
+
: /\.webp$/i.test(name)
|
|
186
|
+
? 'image/webp'
|
|
187
|
+
: /\.ktx2$/i.test(name)
|
|
188
|
+
? 'image/ktx2'
|
|
189
|
+
: 'application/octet-stream';
|
|
190
|
+
function resolveEntryName(base, reference) {
|
|
191
|
+
if (/^[a-z][a-z0-9+.-]*:|^[\\/]|[\0-\x1f]/i.test(reference))
|
|
192
|
+
throw new Error('3TZ external/absolute resource is not allowed.');
|
|
193
|
+
const path = decodeURIComponent(reference.split(/[?#]/)[0]).replace(/\\/g, '/');
|
|
194
|
+
const parts = base.split('/').slice(0, -1);
|
|
195
|
+
for (const part of path.split('/')) {
|
|
196
|
+
if (!part || part === '.')
|
|
197
|
+
continue;
|
|
198
|
+
if (part === '..') {
|
|
199
|
+
if (!parts.length)
|
|
200
|
+
throw new Error('3TZ relative path traversal escapes the archive.');
|
|
201
|
+
parts.pop();
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
parts.push(part);
|
|
205
|
+
}
|
|
206
|
+
return normalizeArchivePath(parts.join('/'));
|
|
207
|
+
}
|
|
208
|
+
async function rewriteUris(value, name, getUrl, depth) {
|
|
209
|
+
const inlineResources = new Set();
|
|
210
|
+
if (value && typeof value === 'object') {
|
|
211
|
+
const root = value;
|
|
212
|
+
const asset = root.asset;
|
|
213
|
+
if (asset?.version === '2.0') {
|
|
214
|
+
for (const key of ['buffers', 'images']) {
|
|
215
|
+
if (Array.isArray(root[key])) {
|
|
216
|
+
for (const resource of root[key]) {
|
|
217
|
+
if (resource && typeof resource === 'object')
|
|
218
|
+
inlineResources.add(resource);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const stack = [[value, 0]];
|
|
225
|
+
let nodes = 0;
|
|
226
|
+
while (stack.length) {
|
|
227
|
+
const [v, nesting] = stack.pop();
|
|
228
|
+
if (!v || typeof v !== 'object')
|
|
229
|
+
continue;
|
|
230
|
+
if (nesting > 128 || ++nodes > 1000000)
|
|
231
|
+
throw new Error('3TZ JSON exceeds its structural limit.');
|
|
232
|
+
if (Array.isArray(v)) {
|
|
233
|
+
for (const child of v)
|
|
234
|
+
stack.push([child, nesting + 1]);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const record = v;
|
|
238
|
+
for (const [key, child] of Object.entries(record)) {
|
|
239
|
+
if ((key === 'uri' || key === 'url' || key === 'schemaUri') && typeof child === 'string') {
|
|
240
|
+
if (/^data:/i.test(child)) {
|
|
241
|
+
if (!inlineResources.has(record))
|
|
242
|
+
throw new Error('3TZ inline tile/model resources are unsupported.');
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const target = resolveEntryName(name, child);
|
|
246
|
+
if (target)
|
|
247
|
+
record[key] = await getUrl(target, depth + 1, key === 'schemaUri');
|
|
248
|
+
}
|
|
249
|
+
else
|
|
250
|
+
stack.push([child, nesting + 1]);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function rewriteGlbUris(data, name, getUrl, depth) {
|
|
255
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
256
|
+
if (data.length < 20 ||
|
|
257
|
+
view.getUint32(0, true) !== 0x46546c67 ||
|
|
258
|
+
view.getUint32(4, true) !== 2 ||
|
|
259
|
+
view.getUint32(8, true) !== data.length)
|
|
260
|
+
throw new Error('Invalid 3TZ GLB.');
|
|
261
|
+
const chunks = [];
|
|
262
|
+
let offset = 12;
|
|
263
|
+
while (offset < data.length) {
|
|
264
|
+
if (offset + 8 > data.length)
|
|
265
|
+
throw new Error('Truncated GLB chunk.');
|
|
266
|
+
const length = view.getUint32(offset, true), type = view.getUint32(offset + 4, true);
|
|
267
|
+
if (length % 4 || offset + 8 + length > data.length)
|
|
268
|
+
throw new Error('Invalid GLB chunk bounds.');
|
|
269
|
+
let bytes = data.slice(offset + 8, offset + 8 + length);
|
|
270
|
+
if (chunks.length === 0) {
|
|
271
|
+
if (type !== 0x4e4f534a)
|
|
272
|
+
throw new Error('GLB JSON must be the first chunk.');
|
|
273
|
+
let end = bytes.length;
|
|
274
|
+
while (end > 0 && (bytes[end - 1] === 0 || bytes[end - 1] === 32))
|
|
275
|
+
end--;
|
|
276
|
+
const json = JSON.parse(utf8.decode(bytes.subarray(0, end)));
|
|
277
|
+
await rewriteUris(json, name, getUrl, depth);
|
|
278
|
+
const encoded = new TextEncoder().encode(JSON.stringify(json)), padded = new Uint8Array(Math.ceil(encoded.length / 4) * 4).fill(32);
|
|
279
|
+
padded.set(encoded);
|
|
280
|
+
bytes = padded;
|
|
281
|
+
}
|
|
282
|
+
chunks.push({ type, bytes });
|
|
283
|
+
offset += 8 + length;
|
|
284
|
+
}
|
|
285
|
+
const length = 12 + chunks.reduce((n, c) => n + 8 + c.bytes.length, 0), out = new Uint8Array(length), v = new DataView(out.buffer);
|
|
286
|
+
v.setUint32(0, 0x46546c67, true);
|
|
287
|
+
v.setUint32(4, 2, true);
|
|
288
|
+
v.setUint32(8, length, true);
|
|
289
|
+
offset = 12;
|
|
290
|
+
for (const c of chunks) {
|
|
291
|
+
v.setUint32(offset, c.bytes.length, true);
|
|
292
|
+
v.setUint32(offset + 4, c.type, true);
|
|
293
|
+
out.set(c.bytes, offset + 8);
|
|
294
|
+
offset += 8 + c.bytes.length;
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
export async function prepare3tzDataset(bytes, options = {}, signal) {
|
|
299
|
+
checkAbort(signal);
|
|
300
|
+
const { entries } = inspect3tzCentralDirectory(bytes, options);
|
|
301
|
+
const imported = await import('jszip'), JSZip = imported.default || imported;
|
|
302
|
+
const zip = await JSZip.loadAsync(bytes, { createFolders: false, checkCRC32: false });
|
|
303
|
+
const extracted = new Map(), urls = new Map(), creating = new Set();
|
|
304
|
+
const responses = new Map();
|
|
305
|
+
const archiveBase = `file-viewer-archive://${crypto.randomUUID()}/`;
|
|
306
|
+
let disposed = false;
|
|
307
|
+
const dispose = () => {
|
|
308
|
+
disposed = true;
|
|
309
|
+
for (const url of urls.values())
|
|
310
|
+
if (url.startsWith('blob:'))
|
|
311
|
+
URL.revokeObjectURL(url);
|
|
312
|
+
urls.clear();
|
|
313
|
+
extracted.clear();
|
|
314
|
+
responses.clear();
|
|
315
|
+
};
|
|
316
|
+
const fetchData = (url, options) => {
|
|
317
|
+
if (!url.startsWith(archiveBase))
|
|
318
|
+
return null;
|
|
319
|
+
return Promise.resolve().then(() => {
|
|
320
|
+
checkAbort(signal);
|
|
321
|
+
checkAbort(options?.signal);
|
|
322
|
+
if (disposed)
|
|
323
|
+
throw new Error('3TZ dataset has been disposed.');
|
|
324
|
+
const item = responses.get(url);
|
|
325
|
+
if (!item)
|
|
326
|
+
throw new Error('Unknown 3TZ virtual resource.');
|
|
327
|
+
return new Response(item.bytes.slice().buffer, {
|
|
328
|
+
headers: { 'Content-Type': item.mime }
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
try {
|
|
333
|
+
for (const entry of entries) {
|
|
334
|
+
checkAbort(signal);
|
|
335
|
+
const file = zip.file(entry.name);
|
|
336
|
+
if (!file)
|
|
337
|
+
throw new Error(`3TZ entry missing after ZIP parse: ${entry.name}`);
|
|
338
|
+
const data = await boundedExtract(file, entry, signal);
|
|
339
|
+
const magic = String.fromCharCode(...data.subarray(0, 4)).toLowerCase();
|
|
340
|
+
const container = /\.(b3dm|i3dm|cmpt)$/i.exec(entry.name)?.[1].toLowerCase() ||
|
|
341
|
+
(['b3dm', 'i3dm', 'cmpt'].includes(magic) ? magic : null);
|
|
342
|
+
if (container)
|
|
343
|
+
throw new Error(`3TZ unsupported ${container.toUpperCase()} container; use archive-local glTF/GLB tiles.`);
|
|
344
|
+
if (magic === 'gltf' && !/\.glb$/i.test(entry.name))
|
|
345
|
+
throw new Error('3TZ GLB content must use the .glb extension.');
|
|
346
|
+
extracted.set(entry.name, data);
|
|
347
|
+
}
|
|
348
|
+
const root = JSON.parse(utf8.decode(extracted.get('tileset.json')));
|
|
349
|
+
if (typeof root?.asset?.version !== 'string' || !root.root || typeof root.root !== 'object')
|
|
350
|
+
throw new Error('3TZ root tileset.json is not a 3D Tiles dataset.');
|
|
351
|
+
const getUrl = async (name, depth = 0, asBlob = false) => {
|
|
352
|
+
checkAbort(signal);
|
|
353
|
+
const cacheKey = asBlob ? `schema:${name}` : name;
|
|
354
|
+
if (depth > 64 || creating.has(cacheKey))
|
|
355
|
+
throw new Error('3TZ cyclic/deep resource reference.');
|
|
356
|
+
const existing = urls.get(cacheKey);
|
|
357
|
+
if (existing)
|
|
358
|
+
return existing;
|
|
359
|
+
const data = extracted.get(name);
|
|
360
|
+
if (!data)
|
|
361
|
+
throw new Error(`Missing 3TZ relative resource: ${name}`);
|
|
362
|
+
creating.add(cacheKey);
|
|
363
|
+
try {
|
|
364
|
+
let payload = data;
|
|
365
|
+
if (/\.(json|gltf)$/i.test(name)) {
|
|
366
|
+
const value = JSON.parse(utf8.decode(data));
|
|
367
|
+
await rewriteUris(value, name, getUrl, depth);
|
|
368
|
+
payload = new TextEncoder().encode(JSON.stringify(value));
|
|
369
|
+
}
|
|
370
|
+
else if (/\.glb$/i.test(name))
|
|
371
|
+
payload = await rewriteGlbUris(data, name, getUrl, depth);
|
|
372
|
+
checkAbort(signal);
|
|
373
|
+
const nativeTile = !asBlob && /\.(json|gltf|glb|b3dm|i3dm|pnts|cmpt)$/i.test(name);
|
|
374
|
+
const url = nativeTile
|
|
375
|
+
? archiveBase + name.split('/').map(encodeURIComponent).join('/')
|
|
376
|
+
: URL.createObjectURL(new Blob([payload.slice().buffer], { type: mimeFor(name) }));
|
|
377
|
+
if (nativeTile)
|
|
378
|
+
responses.set(url, { bytes: payload, mime: mimeFor(name) });
|
|
379
|
+
urls.set(cacheKey, url);
|
|
380
|
+
return url;
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
creating.delete(cacheKey);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const rootUrl = await getUrl('tileset.json');
|
|
387
|
+
return { rootUrl, fetchData, dispose };
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
dispose();
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Group, MeshBasicMaterial } from 'three';
|
|
2
|
+
export interface CityJsonDocument {
|
|
3
|
+
type: 'CityJSON';
|
|
4
|
+
version?: string;
|
|
5
|
+
transform?: {
|
|
6
|
+
scale?: [number, number, number];
|
|
7
|
+
translate?: [number, number, number];
|
|
8
|
+
};
|
|
9
|
+
metadata?: {
|
|
10
|
+
referenceSystem?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
appearance?: {
|
|
14
|
+
textures?: Array<{
|
|
15
|
+
image?: string;
|
|
16
|
+
type?: string;
|
|
17
|
+
wrapMode?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}>;
|
|
20
|
+
'vertices-texture'?: number[][];
|
|
21
|
+
'default-theme-texture'?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
CityObjects: Record<string, {
|
|
25
|
+
geometry?: Array<{
|
|
26
|
+
type?: string;
|
|
27
|
+
boundaries?: unknown;
|
|
28
|
+
texture?: Record<string, {
|
|
29
|
+
values?: unknown;
|
|
30
|
+
}>;
|
|
31
|
+
}>;
|
|
32
|
+
}>;
|
|
33
|
+
vertices: number[][];
|
|
34
|
+
}
|
|
35
|
+
export interface CityJsonExternalResource {
|
|
36
|
+
source: string;
|
|
37
|
+
url: string;
|
|
38
|
+
}
|
|
39
|
+
interface TextureBinding {
|
|
40
|
+
material: MeshBasicMaterial;
|
|
41
|
+
resource: CityJsonExternalResource;
|
|
42
|
+
wrapMode: string;
|
|
43
|
+
}
|
|
44
|
+
export interface CityJsonRenderResult {
|
|
45
|
+
group: Group;
|
|
46
|
+
crs?: string;
|
|
47
|
+
triangleCount: number;
|
|
48
|
+
objectCount: number;
|
|
49
|
+
externalResources: CityJsonExternalResource[];
|
|
50
|
+
textureBindings: TextureBinding[];
|
|
51
|
+
}
|
|
52
|
+
export interface CityJsonRenderOptions {
|
|
53
|
+
materialColor?: number | string;
|
|
54
|
+
textureTheme?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare function parseCityJson(text: string): CityJsonDocument;
|
|
57
|
+
export declare function renderCityJsonDocument(document: CityJsonDocument, resolveRelativeUrl?: (reference: string) => string, options?: CityJsonRenderOptions): CityJsonRenderResult;
|
|
58
|
+
export declare function cityJsonTextureSize(data: Uint8Array): {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
mime: string;
|
|
62
|
+
};
|
|
63
|
+
export declare function renderCityJsonWithTextures(document: CityJsonDocument, resolveRelativeUrl: (reference: string) => string, options: CityJsonRenderOptions | undefined, datasetUrl: string | undefined, signal?: AbortSignal): Promise<CityJsonRenderResult>;
|
|
64
|
+
export declare function disposeCityJsonGroup(group: Group): void;
|
|
65
|
+
export {};
|