zincjs 3.0.0 → 3.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 +27 -22
- package/build/zinc.js +2 -2
- package/build/zinc.js.map +1 -1
- package/package.json +4 -1
- package/src/controls.js +1332 -1241
- package/src/geometryCSG.js +111 -115
- package/src/glyphsetCSG.js +51 -55
- package/src/loaders/GLTFToZincJSLoader.js +31 -33
- package/src/loaders/JSONLoader.js +339 -449
- package/src/loaders/OBJLoader.js +654 -851
- package/src/loaders/STLLoader.js +271 -329
- package/src/loaders/niftiReader.js +90 -59
- package/src/loaders/primitivesLoader.js +55 -52
- package/src/minimap.js +63 -43
- package/src/primitives/geometry.js +40 -44
- package/src/primitives/glyph.js +16 -19
- package/src/primitives/glyphset.js +229 -185
- package/src/primitives/label.js +29 -31
- package/src/primitives/lines.js +20 -20
- package/src/primitives/lines2.js +33 -39
- package/src/primitives/lod.js +43 -43
- package/src/primitives/marker.js +31 -32
- package/src/primitives/markerCluster.js +32 -35
- package/src/primitives/pointset.js +86 -83
- package/src/primitives/texturePrimitive.js +9 -10
- package/src/primitives/textureSlides.js +84 -97
- package/src/primitives/textureVolume.js +46 -49
- package/src/primitives/tubeLines.js +108 -108
- package/src/primitives/zincObject.js +176 -184
- package/src/region.js +145 -155
- package/src/renderRequests.js +3 -3
- package/src/renderer.js +635 -620
- package/src/scene.js +479 -419
- package/src/sceneExporter.js +22 -17
- package/src/sceneLoader.js +542 -296
- package/src/shaders/rgbVolumeRender.js +11 -18
- package/src/shaders/textureArray.js +5 -12
- package/src/shaders/textureSlide.js +10 -17
- package/src/shaders/volumeRender.js +11 -18
- package/src/shaders/volumeRender_old.js +11 -18
- package/src/shaders/volumeTexture.js +7 -14
- package/src/textSprite.js +23 -19
- package/src/texture/texture.js +14 -15
- package/src/texture/textureArray.js +14 -16
- package/src/three/InstancedPoints.js +2 -9
- package/src/three/Loader.js +334 -315
- package/src/three/line/Line.js +165 -215
- package/src/three/line/LineSegments.js +40 -55
- package/src/three/line/LineSegments2.js +322 -366
- package/src/three/line/LineSegmentsGeometry.js +239 -280
- package/src/three-js-csg.js +260 -252
- package/src/tsl/glyphRenderMaterial.js +12 -3
- package/src/tsl/glyphTransform.js +51 -29
- package/src/tsl/textureSlides.js +23 -24
- package/src/utilities.js +309 -371
- package/src/videoHandler.js +76 -83
- package/src/workers/geometryCSG.worker.js +33 -36
- package/src/workers/geometryCSGInternal.js +39 -44
- package/src/zinc.js +4 -7
- package/vite.config.js +7 -7
|
@@ -4,36 +4,36 @@ import { TextureArray } from '../texture/textureArray';
|
|
|
4
4
|
import { TextureSlides } from '../primitives/textureSlides';
|
|
5
5
|
|
|
6
6
|
const defaultTextureSettings = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
id: 'mesh-location-orientation',
|
|
8
|
+
locations: [
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
10
|
+
identifier: 1,
|
|
11
|
+
label: 'original',
|
|
12
|
+
orientation: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0],
|
|
13
|
+
position: [0, 0, 0],
|
|
14
|
+
scale: [1, 1, 1],
|
|
15
|
+
flipY: false,
|
|
16
|
+
flipZ: false,
|
|
17
|
+
reference_point: 'corner',
|
|
18
|
+
},
|
|
19
19
|
],
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
settings: {
|
|
21
|
+
slides: [
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
direction: 'x',
|
|
24
|
+
value: 0.5,
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
direction: 'y',
|
|
28
|
+
value: 0.5,
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
]
|
|
31
|
+
direction: 'z',
|
|
32
|
+
value: 0.5,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
type: 'slides',
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const defaultOptions = {
|
|
@@ -43,7 +43,6 @@ const defaultOptions = {
|
|
|
43
43
|
timeEnabled: false,
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
|
|
47
46
|
/*
|
|
48
47
|
const exampleSettings = {
|
|
49
48
|
v1: {
|
|
@@ -117,26 +116,42 @@ function readNIFTI(data) {
|
|
|
117
116
|
if (nifti.isNIFTI(fullData)) {
|
|
118
117
|
let niftiHeader = nifti.readHeader(fullData);
|
|
119
118
|
let niftiImage = nifti.readImage(niftiHeader, fullData);
|
|
120
|
-
return {niftiHeader, niftiImage};
|
|
119
|
+
return { niftiHeader, niftiImage };
|
|
121
120
|
}
|
|
122
121
|
fullData = undefined;
|
|
123
|
-
return {niftiHeader: undefined, niftiImage: undefined};
|
|
122
|
+
return { niftiHeader: undefined, niftiImage: undefined };
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
|
|
127
125
|
function convertNiftiToUint8Array(niftiHeader, niftiImage) {
|
|
128
126
|
// 1. Parse the raw array using the correct native typed array view
|
|
129
127
|
let rawData;
|
|
130
128
|
switch (niftiHeader.datatypeCode) {
|
|
131
|
-
case nifti.NIFTI1.TYPE_UINT8:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
case nifti.NIFTI1.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case nifti.NIFTI1.
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
case nifti.NIFTI1.TYPE_UINT8:
|
|
130
|
+
rawData = new Uint8Array(niftiImage);
|
|
131
|
+
break;
|
|
132
|
+
case nifti.NIFTI1.TYPE_INT8:
|
|
133
|
+
rawData = new Int8Array(niftiImage);
|
|
134
|
+
break;
|
|
135
|
+
case nifti.NIFTI1.TYPE_UINT16:
|
|
136
|
+
rawData = new Uint16Array(niftiImage);
|
|
137
|
+
break;
|
|
138
|
+
case nifti.NIFTI1.TYPE_INT16:
|
|
139
|
+
rawData = new Int16Array(niftiImage);
|
|
140
|
+
break;
|
|
141
|
+
case nifti.NIFTI1.TYPE_UINT32:
|
|
142
|
+
rawData = new Uint32Array(niftiImage);
|
|
143
|
+
break;
|
|
144
|
+
case nifti.NIFTI1.TYPE_INT32:
|
|
145
|
+
rawData = new Int32Array(niftiImage);
|
|
146
|
+
break;
|
|
147
|
+
case nifti.NIFTI1.TYPE_FLOAT32:
|
|
148
|
+
rawData = new Float32Array(niftiImage);
|
|
149
|
+
break;
|
|
150
|
+
case nifti.NIFTI1.TYPE_FLOAT64:
|
|
151
|
+
rawData = new Float64Array(niftiImage);
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
throw new Error('Unsupported NIfTI data type');
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
let min = Infinity;
|
|
@@ -168,8 +183,12 @@ function createSources(niftiHeader, niftiImage, maskHeader, maskImage) {
|
|
|
168
183
|
const height = niftiHeader.dims[2];
|
|
169
184
|
const depth = niftiHeader.dims[3];
|
|
170
185
|
let isRGB = false;
|
|
171
|
-
if (
|
|
172
|
-
niftiHeader.
|
|
186
|
+
if (
|
|
187
|
+
niftiHeader.intent_code === 1007 ||
|
|
188
|
+
niftiHeader.intent_code === 1008 ||
|
|
189
|
+
niftiHeader.datatypeCode === 128 ||
|
|
190
|
+
niftiHeader.datatypeCode === 2304
|
|
191
|
+
) {
|
|
173
192
|
isRGB = true;
|
|
174
193
|
}
|
|
175
194
|
const typedData = convertNiftiToUint8Array(niftiHeader, niftiImage);
|
|
@@ -212,24 +231,23 @@ function getSFormTransformation(header, options) {
|
|
|
212
231
|
scale[1] = Math.abs(scale[1]);
|
|
213
232
|
scale[2] = Math.abs(scale[2]);
|
|
214
233
|
}
|
|
215
|
-
return {position, scale}
|
|
234
|
+
return { position, scale };
|
|
216
235
|
}
|
|
217
|
-
return {position: undefined, scale: undefined}
|
|
236
|
+
return { position: undefined, scale: undefined };
|
|
218
237
|
}
|
|
219
238
|
|
|
220
239
|
function getTransformationFromHeader(header, options) {
|
|
221
240
|
if (header) {
|
|
222
241
|
if (header.sform_code) {
|
|
223
|
-
return getSFormTransformation(header, options)
|
|
242
|
+
return getSFormTransformation(header, options);
|
|
224
243
|
}
|
|
225
244
|
}
|
|
226
245
|
|
|
227
|
-
return {position: undefined, scale: undefined}
|
|
246
|
+
return { position: undefined, scale: undefined };
|
|
228
247
|
}
|
|
229
248
|
|
|
230
249
|
function createDataTexture(data, width, height, depth, isRGB) {
|
|
231
|
-
const dataTexture = new THREE.Data3DTexture(
|
|
232
|
-
data, width, height, depth);
|
|
250
|
+
const dataTexture = new THREE.Data3DTexture(data, width, height, depth);
|
|
233
251
|
dataTexture.anisotropy = 4;
|
|
234
252
|
if (!isRGB) {
|
|
235
253
|
dataTexture.format = THREE.RedFormat;
|
|
@@ -245,7 +263,11 @@ function createTextureArray(sources) {
|
|
|
245
263
|
if (sources?.data) {
|
|
246
264
|
const tArray = new TextureArray();
|
|
247
265
|
const dataTexutre = createDataTexture(
|
|
248
|
-
|
|
266
|
+
sources.data,
|
|
267
|
+
sources.width,
|
|
268
|
+
sources.height,
|
|
269
|
+
sources.depth,
|
|
270
|
+
);
|
|
249
271
|
tArray.setDataTexture(dataTexutre);
|
|
250
272
|
tArray.size = {
|
|
251
273
|
width: sources.width,
|
|
@@ -260,14 +282,14 @@ function createTextureArray(sources) {
|
|
|
260
282
|
|
|
261
283
|
function createTexturePrimitives(niftiHeader, sources, useHeaderInfo, textureSettings, optionsIn) {
|
|
262
284
|
if (sources?.data) {
|
|
263
|
-
const options = {...defaultOptions};
|
|
285
|
+
const options = { ...defaultOptions };
|
|
264
286
|
if (optionsIn) {
|
|
265
287
|
Object.assign(options, optionsIn);
|
|
266
288
|
}
|
|
267
289
|
const newTexture = new TextureSlides();
|
|
268
290
|
const tArray = createTextureArray(sources);
|
|
269
291
|
if (tArray) {
|
|
270
|
-
newTexture.groupName =
|
|
292
|
+
newTexture.groupName = 'Images';
|
|
271
293
|
newTexture.morph.renderOrder = 1;
|
|
272
294
|
newTexture.texture = tArray;
|
|
273
295
|
const settings = structuredClone(defaultTextureSettings);
|
|
@@ -275,7 +297,7 @@ function createTexturePrimitives(niftiHeader, sources, useHeaderInfo, textureSet
|
|
|
275
297
|
//The following will allow the dimension and upset to be
|
|
276
298
|
//set using the information from the header
|
|
277
299
|
if (useHeaderInfo && niftiHeader) {
|
|
278
|
-
const {position, scale} = getTransformationFromHeader(niftiHeader, options);
|
|
300
|
+
const { position, scale } = getTransformationFromHeader(niftiHeader, options);
|
|
279
301
|
if (position && scale) {
|
|
280
302
|
settings.locations[0].scale = scale;
|
|
281
303
|
settings.locations[0].position = position;
|
|
@@ -284,8 +306,13 @@ function createTexturePrimitives(niftiHeader, sources, useHeaderInfo, textureSet
|
|
|
284
306
|
newTexture.initialise(settings, undefined);
|
|
285
307
|
newTexture.showEdges(0x999999);
|
|
286
308
|
if (sources.maskData && !options.timeEnabled) {
|
|
287
|
-
const maskTexture = createDataTexture(
|
|
288
|
-
sources.
|
|
309
|
+
const maskTexture = createDataTexture(
|
|
310
|
+
sources.maskData,
|
|
311
|
+
sources.width,
|
|
312
|
+
sources.height,
|
|
313
|
+
sources.depth,
|
|
314
|
+
false,
|
|
315
|
+
);
|
|
289
316
|
newTexture.setMask(maskTexture);
|
|
290
317
|
}
|
|
291
318
|
newTexture.setNumberOfChannels(sources.isRGB ? 3 : 1);
|
|
@@ -297,9 +324,9 @@ function createTexturePrimitives(niftiHeader, sources, useHeaderInfo, textureSet
|
|
|
297
324
|
}
|
|
298
325
|
|
|
299
326
|
async function getImagesFromURL(url, maskURL) {
|
|
300
|
-
|
|
301
327
|
// try {
|
|
302
|
-
let maskHeader = undefined,
|
|
328
|
+
let maskHeader = undefined,
|
|
329
|
+
maskImage = undefined;
|
|
303
330
|
if (maskURL) {
|
|
304
331
|
const mask = await fetch(maskURL);
|
|
305
332
|
const maskBuffer = await mask.arrayBuffer();
|
|
@@ -309,14 +336,12 @@ async function getImagesFromURL(url, maskURL) {
|
|
|
309
336
|
}
|
|
310
337
|
const response = await fetch(url);
|
|
311
338
|
const buffer = await response.arrayBuffer();
|
|
312
|
-
const {niftiHeader, niftiImage} = readNIFTI(buffer);
|
|
339
|
+
const { niftiHeader, niftiImage } = readNIFTI(buffer);
|
|
313
340
|
const sources = createSources(niftiHeader, niftiImage, maskHeader, maskImage);
|
|
314
|
-
return {sources, niftiHeader};
|
|
341
|
+
return { sources, niftiHeader };
|
|
315
342
|
}
|
|
316
343
|
|
|
317
|
-
|
|
318
|
-
async function createPrimitivesFromNIFTI(
|
|
319
|
-
url, useHeaderInfo, maskURL, textureSettings, optionsIn) {
|
|
344
|
+
async function createPrimitivesFromNIFTI(url, useHeaderInfo, maskURL, textureSettings, optionsIn) {
|
|
320
345
|
let timeEnabled = false;
|
|
321
346
|
let textureP = undefined;
|
|
322
347
|
let firstURL = url;
|
|
@@ -327,8 +352,14 @@ async function createPrimitivesFromNIFTI(
|
|
|
327
352
|
}
|
|
328
353
|
}
|
|
329
354
|
if (typeof firstURL === 'string') {
|
|
330
|
-
const {sources, niftiHeader} = await getImagesFromURL(firstURL, maskURL, optionsIn);
|
|
331
|
-
textureP = createTexturePrimitives(
|
|
355
|
+
const { sources, niftiHeader } = await getImagesFromURL(firstURL, maskURL, optionsIn);
|
|
356
|
+
textureP = createTexturePrimitives(
|
|
357
|
+
niftiHeader,
|
|
358
|
+
sources,
|
|
359
|
+
useHeaderInfo,
|
|
360
|
+
textureSettings,
|
|
361
|
+
optionsIn,
|
|
362
|
+
);
|
|
332
363
|
}
|
|
333
364
|
if (timeEnabled && textureP) {
|
|
334
365
|
for (let i = 1; i < url.length; i++) {
|
|
@@ -342,7 +373,7 @@ async function createPrimitivesFromNIFTI(
|
|
|
342
373
|
}
|
|
343
374
|
|
|
344
375
|
async function createTextureFromNIFTI(url, maskURL, optionsIn) {
|
|
345
|
-
const {sources} = await getImagesFromURL(url, maskURL, optionsIn);
|
|
376
|
+
const { sources } = await getImagesFromURL(url, maskURL, optionsIn);
|
|
346
377
|
return createTextureArray(sources);
|
|
347
378
|
}
|
|
348
379
|
|
|
@@ -13,7 +13,7 @@ const mergeGlyphData = (glyphData) => {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const fields = ['axis1', 'axis2', 'axis3', 'colors', 'positions', 'scale'];
|
|
16
|
-
fields.forEach(field => {
|
|
16
|
+
fields.forEach((field) => {
|
|
17
17
|
if (field in glyphData1) {
|
|
18
18
|
Object.keys(glyphData1[field]).forEach((step) => {
|
|
19
19
|
const len = glyphData2[field][step].length;
|
|
@@ -23,15 +23,15 @@ const mergeGlyphData = (glyphData) => {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
if (glyphData && glyphData.length > 0) {
|
|
29
29
|
while (glyphData.length > 1) {
|
|
30
|
-
const glyphData2 = glyphData.splice(1,1);
|
|
30
|
+
const glyphData2 = glyphData.splice(1, 1);
|
|
31
31
|
merge(glyphData[0], glyphData2[0]);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
const mergeGeometries = (geometries) => {
|
|
37
37
|
if (geometries && geometries.length > 0) {
|
|
@@ -43,9 +43,9 @@ const mergeGeometries = (geometries) => {
|
|
|
43
43
|
return merged;
|
|
44
44
|
}
|
|
45
45
|
return undefined;
|
|
46
|
-
}
|
|
46
|
+
};
|
|
47
47
|
|
|
48
|
-
const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback, onErrorCallback) {
|
|
48
|
+
const IndexedSourcesHandler = function (urlIn, crossOrigin, onDownloadedCallback, onErrorCallback) {
|
|
49
49
|
const fileLoader = new FileLoader();
|
|
50
50
|
const jsonLoader = new JSONLoader();
|
|
51
51
|
fileLoader.crossOrigin = crossOrigin;
|
|
@@ -61,25 +61,25 @@ const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback,
|
|
|
61
61
|
const processItemDownloaded = (item) => {
|
|
62
62
|
const modelData = data[item.index];
|
|
63
63
|
if (modelData) {
|
|
64
|
-
if (
|
|
64
|
+
if ('GlyphGeometriesURL' in modelData) {
|
|
65
65
|
item.onLoad(modelData);
|
|
66
66
|
} else {
|
|
67
|
-
let obj = jsonLoader.parse(
|
|
67
|
+
let obj = jsonLoader.parse(modelData);
|
|
68
68
|
item.onLoad(obj.geometry, obj.materials);
|
|
69
69
|
}
|
|
70
70
|
} else {
|
|
71
|
-
processItemError(item, {responseURL: url});
|
|
71
|
+
processItemError(item, { responseURL: url });
|
|
72
72
|
}
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
74
|
|
|
75
75
|
const processItemError = (item) => {
|
|
76
76
|
if (item.onError) {
|
|
77
77
|
if (!error) {
|
|
78
|
-
error = {responseURL: url};
|
|
78
|
+
error = { responseURL: url };
|
|
79
79
|
}
|
|
80
80
|
item.onError(error);
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
};
|
|
83
83
|
|
|
84
84
|
this.downloadCompleted = (args) => {
|
|
85
85
|
try {
|
|
@@ -87,17 +87,17 @@ const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback,
|
|
|
87
87
|
downloading = false;
|
|
88
88
|
finished = true;
|
|
89
89
|
if (Array.isArray(data)) {
|
|
90
|
-
items.forEach(item => processItemDownloaded(item));
|
|
90
|
+
items.forEach((item) => processItemDownloaded(item));
|
|
91
91
|
} else {
|
|
92
|
-
items.forEach(item => processItemError(item));
|
|
92
|
+
items.forEach((item) => processItemError(item));
|
|
93
93
|
}
|
|
94
94
|
} catch {
|
|
95
|
-
items.forEach(item => processItemError(item));
|
|
95
|
+
items.forEach((item) => processItemError(item));
|
|
96
96
|
}
|
|
97
|
-
}
|
|
97
|
+
};
|
|
98
98
|
|
|
99
99
|
const errorHandling = () => {
|
|
100
|
-
return xhr => {
|
|
100
|
+
return (xhr) => {
|
|
101
101
|
error = xhr;
|
|
102
102
|
finished = true;
|
|
103
103
|
downloading = false;
|
|
@@ -107,18 +107,18 @@ const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback,
|
|
|
107
107
|
if (onDownloadError) {
|
|
108
108
|
onDownloadError(xhr);
|
|
109
109
|
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
112
|
|
|
113
113
|
const progressHandling = () => {
|
|
114
|
-
return xhr => {
|
|
114
|
+
return (xhr) => {
|
|
115
115
|
items.forEach((item) => {
|
|
116
116
|
if (item.onProgress) {
|
|
117
117
|
item.onProgress(xhr);
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
122
|
|
|
123
123
|
this.load = (index, onLoad, onProgress, onError) => {
|
|
124
124
|
const item = {
|
|
@@ -141,10 +141,10 @@ const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback,
|
|
|
141
141
|
downloading = true;
|
|
142
142
|
fileLoader.load(url, onDownloaded, progressHandling(), errorHandling());
|
|
143
143
|
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
146
|
|
|
147
|
-
const MultiSourcesHandler = function(numberIn, onLoadCallback, onErrorCallback, options) {
|
|
147
|
+
const MultiSourcesHandler = function (numberIn, onLoadCallback, onErrorCallback, options) {
|
|
148
148
|
const allData = [];
|
|
149
149
|
const number = numberIn;
|
|
150
150
|
const onLoad = onLoadCallback;
|
|
@@ -166,7 +166,7 @@ const MultiSourcesHandler = function(numberIn, onLoadCallback, onErrorCallback,
|
|
|
166
166
|
if (onError) {
|
|
167
167
|
onError(...failure);
|
|
168
168
|
}
|
|
169
|
-
}
|
|
169
|
+
};
|
|
170
170
|
|
|
171
171
|
this.itemFailed = (order, args) => {
|
|
172
172
|
if (!failure) {
|
|
@@ -176,10 +176,10 @@ const MultiSourcesHandler = function(numberIn, onLoadCallback, onErrorCallback,
|
|
|
176
176
|
if (totalDownloaded == number) {
|
|
177
177
|
reportFailure();
|
|
178
178
|
}
|
|
179
|
-
}
|
|
179
|
+
};
|
|
180
180
|
|
|
181
181
|
this.itemDownloaded = (order, args) => {
|
|
182
|
-
allData[order]= args;
|
|
182
|
+
allData[order] = args;
|
|
183
183
|
totalDownloaded++;
|
|
184
184
|
if (totalDownloaded == number) {
|
|
185
185
|
if (failure) {
|
|
@@ -199,23 +199,23 @@ const MultiSourcesHandler = function(numberIn, onLoadCallback, onErrorCallback,
|
|
|
199
199
|
onLoad(geometry, materials);
|
|
200
200
|
} else {
|
|
201
201
|
const glyphData = allData.map((item) => {
|
|
202
|
-
return JSON.parse(item[0])
|
|
202
|
+
return JSON.parse(item[0]);
|
|
203
203
|
});
|
|
204
204
|
mergeGlyphData(glyphData);
|
|
205
205
|
onLoad(glyphData[0]);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
211
|
|
|
212
212
|
const PrimitivesLoader = function () {
|
|
213
213
|
let concurrentDownloads = 0;
|
|
214
214
|
const MAX_DOWNLOAD = 20;
|
|
215
|
-
this.crossOrigin =
|
|
215
|
+
this.crossOrigin = 'Anonymous';
|
|
216
216
|
const jsonloader = new JSONLoader();
|
|
217
217
|
const fileloader = new FileLoader();
|
|
218
|
-
fileloader.crossOrigin =
|
|
218
|
+
fileloader.crossOrigin = 'Anonymous';
|
|
219
219
|
const waitingList = [];
|
|
220
220
|
//URL to loader pair
|
|
221
221
|
const indexedLoaders = {};
|
|
@@ -227,24 +227,28 @@ const PrimitivesLoader = function () {
|
|
|
227
227
|
//The order here will give us hint on the sequence on merging the primitives
|
|
228
228
|
let order = 0;
|
|
229
229
|
urls.forEach((url) => {
|
|
230
|
-
const newOptions = options ? {...options} : {};
|
|
230
|
+
const newOptions = options ? { ...options } : {};
|
|
231
231
|
newOptions.msHandler = msHandler;
|
|
232
232
|
newOptions.order = order;
|
|
233
233
|
order++;
|
|
234
234
|
loadFromSingleSource(url, onLoad, onProgress, onError, newOptions);
|
|
235
235
|
});
|
|
236
|
-
}
|
|
236
|
+
};
|
|
237
237
|
|
|
238
238
|
const handleIndexedSource = (url, onLoad, onProgress, onError, options) => {
|
|
239
|
-
const newOptions = options ? {...options} : {};
|
|
239
|
+
const newOptions = options ? { ...options } : {};
|
|
240
240
|
let indexedLoader = indexedLoaders[url];
|
|
241
241
|
if (!indexedLoader) {
|
|
242
242
|
if (MAX_DOWNLOAD > concurrentDownloads) {
|
|
243
243
|
const onLoadCallback = new onFinally(undefined, this, newOptions);
|
|
244
244
|
const onErrorCallback = new onFinally(undefined, this, {});
|
|
245
245
|
++concurrentDownloads;
|
|
246
|
-
indexedLoader = new IndexedSourcesHandler(
|
|
247
|
-
|
|
246
|
+
indexedLoader = new IndexedSourcesHandler(
|
|
247
|
+
url,
|
|
248
|
+
this.crossOrigin,
|
|
249
|
+
onLoadCallback,
|
|
250
|
+
onErrorCallback,
|
|
251
|
+
);
|
|
248
252
|
indexedLoaders[url] = indexedLoader;
|
|
249
253
|
} else {
|
|
250
254
|
waitingList.push({
|
|
@@ -260,10 +264,10 @@ const PrimitivesLoader = function () {
|
|
|
260
264
|
newOptions.isHandler = indexedLoader;
|
|
261
265
|
indexedLoader.load(options.index, onLoad, onProgress, onError);
|
|
262
266
|
}
|
|
263
|
-
}
|
|
267
|
+
};
|
|
264
268
|
|
|
265
269
|
const loadFromSingleSource = (url, onLoad, onProgress, onError, options) => {
|
|
266
|
-
if (options &&
|
|
270
|
+
if (options && options.index !== undefined) {
|
|
267
271
|
handleIndexedSource(url, onLoad, onProgress, onError, options);
|
|
268
272
|
} else {
|
|
269
273
|
//Standard loading
|
|
@@ -287,7 +291,7 @@ const PrimitivesLoader = function () {
|
|
|
287
291
|
});
|
|
288
292
|
}
|
|
289
293
|
}
|
|
290
|
-
}
|
|
294
|
+
};
|
|
291
295
|
|
|
292
296
|
this.load = (url, onLoad, onProgress, onError, options) => {
|
|
293
297
|
if (Array.isArray(url)) {
|
|
@@ -295,7 +299,7 @@ const PrimitivesLoader = function () {
|
|
|
295
299
|
} else {
|
|
296
300
|
loadFromSingleSource(url, onLoad, onProgress, onError, options);
|
|
297
301
|
}
|
|
298
|
-
}
|
|
302
|
+
};
|
|
299
303
|
|
|
300
304
|
this.loadFromWaitingList = () => {
|
|
301
305
|
while (MAX_DOWNLOAD > concurrentDownloads) {
|
|
@@ -306,7 +310,7 @@ const PrimitivesLoader = function () {
|
|
|
306
310
|
return;
|
|
307
311
|
}
|
|
308
312
|
}
|
|
309
|
-
}
|
|
313
|
+
};
|
|
310
314
|
|
|
311
315
|
this.itemRemainingCheck = () => {
|
|
312
316
|
if (waitingList.length === 0 && concurrentDownloads === 0) {
|
|
@@ -316,9 +320,9 @@ const PrimitivesLoader = function () {
|
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
322
|
}
|
|
319
|
-
}
|
|
323
|
+
};
|
|
320
324
|
|
|
321
|
-
const onFinally = function(callback, loader, options, isError = false) {
|
|
325
|
+
const onFinally = function (callback, loader, options, isError = false) {
|
|
322
326
|
return (...args) => {
|
|
323
327
|
--concurrentDownloads;
|
|
324
328
|
if (options?.msHandler) {
|
|
@@ -336,13 +340,12 @@ const PrimitivesLoader = function () {
|
|
|
336
340
|
}
|
|
337
341
|
loader.loadFromWaitingList();
|
|
338
342
|
loader.itemRemainingCheck();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
343
|
+
};
|
|
344
|
+
};
|
|
341
345
|
|
|
342
|
-
this.parse = data => {
|
|
346
|
+
this.parse = (data) => {
|
|
343
347
|
return jsonloader.parse(data);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
}
|
|
348
|
+
};
|
|
349
|
+
};
|
|
347
350
|
|
|
348
|
-
export { PrimitivesLoader };
|
|
351
|
+
export { PrimitivesLoader };
|