@kitware/vtk.js 25.4.0 → 25.5.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/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +4 -8
- package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +6 -14
- package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +60 -57
- package/IO/Core/ZipMultiDataSetReader.js +19 -29
- package/IO/Core/ZipMultiDataSetWriter.js +7 -23
- package/IO/Misc/SkyboxReader.js +67 -75
- package/IO/XML/XMLReader.js +2 -2
- package/IO/XML/XMLWriter.js +2 -2
- package/Interaction/Style/InteractorStyleTrackballCamera.js +16 -0
- package/Rendering/OpenGL/RenderWindow/ContextProxy.js +65 -0
- package/Rendering/OpenGL/RenderWindow.js +3 -1
- package/index.js +0 -2
- package/package.json +3 -4
- package/ThirdParty/index.js +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { strFromU8, decompressSync } from 'fflate';
|
|
2
2
|
import macro from '../../../macros.js';
|
|
3
3
|
import Base64 from '../../../Common/Core/Base64.js';
|
|
4
4
|
import Endian from '../../../Common/Core/Endian.js';
|
|
@@ -59,9 +59,7 @@ function fetchArray(instance, baseURL, array) {
|
|
|
59
59
|
var bText = atob(txt);
|
|
60
60
|
|
|
61
61
|
if (options.compression) {
|
|
62
|
-
bText =
|
|
63
|
-
to: 'string'
|
|
64
|
-
});
|
|
62
|
+
bText = strFromU8(decompressSync(bText));
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
array.values = JSON.parse(bText);
|
|
@@ -74,11 +72,9 @@ function fetchArray(instance, baseURL, array) {
|
|
|
74
72
|
|
|
75
73
|
if (options.compression) {
|
|
76
74
|
if (array.dataType === 'string' || array.dataType === 'JSON') {
|
|
77
|
-
array.buffer =
|
|
78
|
-
to: 'string'
|
|
79
|
-
});
|
|
75
|
+
array.buffer = strFromU8(decompressSync(new Uint8Array(array.buffer)));
|
|
80
76
|
} else {
|
|
81
|
-
array.buffer =
|
|
77
|
+
array.buffer = decompressSync(new Uint8Array(array.buffer)).buffer;
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import
|
|
2
|
+
import { decompressSync, strFromU8 } from 'fflate';
|
|
3
3
|
import macro from '../../../macros.js';
|
|
4
4
|
import Endian from '../../../Common/Core/Endian.js';
|
|
5
5
|
import { DataTypeByteSize } from '../../../Common/Core/DataArray/Constants.js';
|
|
@@ -48,9 +48,7 @@ function fetchBinary(url) {
|
|
|
48
48
|
if (xhr.readyState === 4) {
|
|
49
49
|
if (xhr.status === 200 || xhr.status === 0) {
|
|
50
50
|
if (options.compression) {
|
|
51
|
-
resolve(
|
|
52
|
-
to: 'arraybuffer'
|
|
53
|
-
}).buffer);
|
|
51
|
+
resolve(decompressSync(new Uint8Array(xhr.response)).buffer);
|
|
54
52
|
} else {
|
|
55
53
|
resolve(xhr.response);
|
|
56
54
|
}
|
|
@@ -101,11 +99,9 @@ function fetchArray(instance, baseURL, array) {
|
|
|
101
99
|
|
|
102
100
|
if (options.compression) {
|
|
103
101
|
if (array.dataType === 'string' || array.dataType === 'JSON') {
|
|
104
|
-
array.buffer =
|
|
105
|
-
to: 'string'
|
|
106
|
-
});
|
|
102
|
+
array.buffer = strFromU8(decompressSync(new Uint8Array(array.buffer)));
|
|
107
103
|
} else {
|
|
108
|
-
array.buffer =
|
|
104
|
+
array.buffer = decompressSync(new Uint8Array(array.buffer)).buffer;
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
107
|
|
|
@@ -175,9 +171,7 @@ function fetchJSON(instance, url) {
|
|
|
175
171
|
|
|
176
172
|
if (xhr.status === 200 || xhr.status === 0) {
|
|
177
173
|
if (options.compression) {
|
|
178
|
-
resolve(JSON.parse(
|
|
179
|
-
to: 'string'
|
|
180
|
-
})));
|
|
174
|
+
resolve(JSON.parse(strFromU8(decompressSync(new Uint8Array(xhr.response)))));
|
|
181
175
|
} else {
|
|
182
176
|
resolve(JSON.parse(xhr.responseText));
|
|
183
177
|
}
|
|
@@ -222,9 +216,7 @@ function fetchText(instance, url) {
|
|
|
222
216
|
|
|
223
217
|
if (xhr.status === 200 || xhr.status === 0) {
|
|
224
218
|
if (options.compression) {
|
|
225
|
-
resolve(
|
|
226
|
-
to: 'string'
|
|
227
|
-
}));
|
|
219
|
+
resolve(strFromU8(decompressSync(new Uint8Array(xhr.response))));
|
|
228
220
|
} else {
|
|
229
221
|
resolve(xhr.responseText);
|
|
230
222
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import pako from 'pako';
|
|
1
|
+
import { strToU8, unzipSync, strFromU8, decompressSync } from 'fflate';
|
|
3
2
|
import macro from '../../../macros.js';
|
|
4
3
|
import Endian from '../../../Common/Core/Endian.js';
|
|
5
4
|
import { DataTypeByteSize } from '../../../Common/Core/DataArray/Constants.js';
|
|
6
5
|
import { registerType } from '../DataAccessHelper.js';
|
|
6
|
+
import { fromArrayBuffer } from '../../../Common/Core/Base64.js';
|
|
7
7
|
|
|
8
8
|
var vtkErrorMacro = macro.vtkErrorMacro,
|
|
9
9
|
vtkDebugMacro = macro.vtkDebugMacro;
|
|
@@ -27,11 +27,9 @@ function handleUint8Array(array, compression, done) {
|
|
|
27
27
|
|
|
28
28
|
if (compression) {
|
|
29
29
|
if (array.dataType === 'string' || array.dataType === 'JSON') {
|
|
30
|
-
array.buffer =
|
|
31
|
-
to: 'string'
|
|
32
|
-
});
|
|
30
|
+
array.buffer = strFromU8(decompressSync(new Uint8Array(array.buffer)));
|
|
33
31
|
} else {
|
|
34
|
-
array.buffer =
|
|
32
|
+
array.buffer = decompressSync(new Uint8Array(array.buffer)).buffer;
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
|
|
@@ -58,9 +56,7 @@ function handleUint8Array(array, compression, done) {
|
|
|
58
56
|
function handleString(array, compression, done) {
|
|
59
57
|
return function (string) {
|
|
60
58
|
if (compression) {
|
|
61
|
-
array.values = JSON.parse(
|
|
62
|
-
to: 'string'
|
|
63
|
-
}));
|
|
59
|
+
array.values = JSON.parse(strFromU8(decompressSync(string)));
|
|
64
60
|
} else {
|
|
65
61
|
array.values = JSON.parse(string);
|
|
66
62
|
}
|
|
@@ -69,11 +65,6 @@ function handleString(array, compression, done) {
|
|
|
69
65
|
};
|
|
70
66
|
}
|
|
71
67
|
|
|
72
|
-
var handlers = {
|
|
73
|
-
uint8array: handleUint8Array,
|
|
74
|
-
string: handleString
|
|
75
|
-
};
|
|
76
|
-
|
|
77
68
|
function removeLeadingSlash(str) {
|
|
78
69
|
return str[0] === '/' ? str.substr(1) : str;
|
|
79
70
|
}
|
|
@@ -86,32 +77,47 @@ function cleanUpPath(str) {
|
|
|
86
77
|
return removeLeadingSlash(normalizePath(str));
|
|
87
78
|
}
|
|
88
79
|
|
|
80
|
+
function unpack(zipContent) {
|
|
81
|
+
return new Promise(function (resolve, reject) {
|
|
82
|
+
if (typeof zipContent === 'string') {
|
|
83
|
+
resolve(strToU8(zipContent));
|
|
84
|
+
} else if (zipContent instanceof Blob) {
|
|
85
|
+
resolve(zipContent.arrayBuffer().then(function (ab) {
|
|
86
|
+
return new Uint8Array(ab);
|
|
87
|
+
}));
|
|
88
|
+
} else if (zipContent instanceof ArrayBuffer) {
|
|
89
|
+
resolve(new Uint8Array(zipContent));
|
|
90
|
+
} else if ((zipContent === null || zipContent === void 0 ? void 0 : zipContent.buffer) instanceof ArrayBuffer) {
|
|
91
|
+
resolve(new Uint8Array(zipContent.buffer));
|
|
92
|
+
} else {
|
|
93
|
+
reject(new Error('Invalid datatype to unpack.'));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
89
98
|
function create(createOptions) {
|
|
90
99
|
var ready = false;
|
|
91
100
|
var requestCount = 0;
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
|
|
101
|
+
var decompressedFiles = null;
|
|
102
|
+
var fullRootPath = '';
|
|
103
|
+
unpack(createOptions.zipContent).then(function (zipFileData) {
|
|
104
|
+
decompressedFiles = unzipSync(zipFileData);
|
|
95
105
|
ready = true; // Find root index.json
|
|
96
106
|
|
|
97
107
|
var metaFiles = [];
|
|
98
|
-
|
|
99
|
-
if (relativePath.
|
|
108
|
+
Object.keys(decompressedFiles).forEach(function (relativePath) {
|
|
109
|
+
if (relativePath.endsWith('index.json')) {
|
|
100
110
|
metaFiles.push(relativePath);
|
|
101
111
|
}
|
|
102
112
|
});
|
|
103
113
|
metaFiles.sort(function (a, b) {
|
|
104
114
|
return a.length - b.length;
|
|
105
|
-
});
|
|
106
|
-
var fullRootPath = metaFiles[0].split('/');
|
|
115
|
+
}); // if not empty, then fullRootPath will have a forward slash suffix
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
var dirName = fullRootPath.shift();
|
|
110
|
-
zipRoot = zipRoot.folder(dirName);
|
|
111
|
-
}
|
|
117
|
+
fullRootPath = metaFiles[0].replace(/index\.json$/, '');
|
|
112
118
|
|
|
113
119
|
if (createOptions.callback) {
|
|
114
|
-
createOptions.callback(
|
|
120
|
+
createOptions.callback(decompressedFiles);
|
|
115
121
|
}
|
|
116
122
|
});
|
|
117
123
|
return {
|
|
@@ -143,9 +149,18 @@ function create(createOptions) {
|
|
|
143
149
|
resolve(array);
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
var fileData = decompressedFiles["".concat(fullRootPath).concat(url)];
|
|
153
|
+
|
|
154
|
+
if (array.dataType === 'string' && !options.compression) {
|
|
155
|
+
// string
|
|
156
|
+
var handler = handleString(array, options.compression, doneCleanUp);
|
|
157
|
+
handler(strFromU8(fileData));
|
|
158
|
+
} else {
|
|
159
|
+
// uint8array
|
|
160
|
+
var _handler = handleUint8Array(array, options.compression, doneCleanUp);
|
|
161
|
+
|
|
162
|
+
_handler(fileData);
|
|
163
|
+
}
|
|
149
164
|
});
|
|
150
165
|
},
|
|
151
166
|
fetchJSON: function fetchJSON(instance, url) {
|
|
@@ -156,22 +171,18 @@ function create(createOptions) {
|
|
|
156
171
|
vtkErrorMacro('ERROR!!! zip not ready...');
|
|
157
172
|
}
|
|
158
173
|
|
|
174
|
+
var fileData = decompressedFiles["".concat(fullRootPath).concat(path)];
|
|
175
|
+
|
|
159
176
|
if (options.compression) {
|
|
160
177
|
if (options.compression === 'gz') {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
to: 'string'
|
|
164
|
-
});
|
|
165
|
-
return Promise.resolve(JSON.parse(str));
|
|
166
|
-
});
|
|
178
|
+
var str = strFromU8(decompressSync(fileData));
|
|
179
|
+
return Promise.resolve(JSON.parse(str));
|
|
167
180
|
}
|
|
168
181
|
|
|
169
182
|
return Promise.reject(new Error('Invalid compression'));
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
return
|
|
173
|
-
return Promise.resolve(JSON.parse(str));
|
|
174
|
-
});
|
|
185
|
+
return Promise.resolve(JSON.parse(strFromU8(fileData)));
|
|
175
186
|
},
|
|
176
187
|
fetchText: function fetchText(instance, url) {
|
|
177
188
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -181,22 +192,17 @@ function create(createOptions) {
|
|
|
181
192
|
vtkErrorMacro('ERROR!!! zip not ready...');
|
|
182
193
|
}
|
|
183
194
|
|
|
195
|
+
var fileData = decompressedFiles["".concat(fullRootPath).concat(path)];
|
|
196
|
+
|
|
184
197
|
if (options.compression) {
|
|
185
198
|
if (options.compression === 'gz') {
|
|
186
|
-
return
|
|
187
|
-
var str = pako.inflate(uint8array, {
|
|
188
|
-
to: 'string'
|
|
189
|
-
});
|
|
190
|
-
return Promise.resolve(str);
|
|
191
|
-
});
|
|
199
|
+
return Promise.resolve(strFromU8(unzipSync(fileData)));
|
|
192
200
|
}
|
|
193
201
|
|
|
194
202
|
return Promise.reject(new Error('Invalid compression'));
|
|
195
203
|
}
|
|
196
204
|
|
|
197
|
-
return
|
|
198
|
-
return Promise.resolve(str);
|
|
199
|
-
});
|
|
205
|
+
return Promise.resolve(strFromU8(fileData));
|
|
200
206
|
},
|
|
201
207
|
fetchImage: function fetchImage(instance, url) {
|
|
202
208
|
var path = cleanUpPath(url);
|
|
@@ -205,6 +211,7 @@ function create(createOptions) {
|
|
|
205
211
|
vtkErrorMacro('ERROR!!! zip not ready...');
|
|
206
212
|
}
|
|
207
213
|
|
|
214
|
+
var fileData = decompressedFiles["".concat(fullRootPath).concat(path)];
|
|
208
215
|
return new Promise(function (resolve, reject) {
|
|
209
216
|
var img = new Image();
|
|
210
217
|
|
|
@@ -213,9 +220,8 @@ function create(createOptions) {
|
|
|
213
220
|
};
|
|
214
221
|
|
|
215
222
|
img.onerror = reject;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
223
|
+
var str = fromArrayBuffer(fileData.buffer);
|
|
224
|
+
img.src = "data:image/".concat(toMimeType(path), ";base64,").concat(str);
|
|
219
225
|
});
|
|
220
226
|
},
|
|
221
227
|
fetchBinary: function fetchBinary(instance, url) {
|
|
@@ -226,20 +232,17 @@ function create(createOptions) {
|
|
|
226
232
|
vtkErrorMacro('ERROR!!! zip not ready...');
|
|
227
233
|
}
|
|
228
234
|
|
|
235
|
+
var fileData = decompressedFiles["".concat(fullRootPath).concat(path)];
|
|
236
|
+
|
|
229
237
|
if (options.compression) {
|
|
230
238
|
if (options.compression === 'gz') {
|
|
231
|
-
return
|
|
232
|
-
var array = pako.inflate(data).buffer;
|
|
233
|
-
return Promise.resolve(array);
|
|
234
|
-
});
|
|
239
|
+
return Promise.resolve(decompressSync(fileData).buffer);
|
|
235
240
|
}
|
|
236
241
|
|
|
237
242
|
return Promise.reject(new Error('Invalid compression'));
|
|
238
243
|
}
|
|
239
244
|
|
|
240
|
-
return
|
|
241
|
-
return Promise.resolve(data);
|
|
242
|
-
});
|
|
245
|
+
return Promise.resolve(fileData.buffer);
|
|
243
246
|
}
|
|
244
247
|
};
|
|
245
248
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import
|
|
2
|
+
import { unzipSync, strFromU8 } from 'fflate';
|
|
3
3
|
import DataAccessHelper from './DataAccessHelper.js';
|
|
4
4
|
import macro from '../../macros.js';
|
|
5
5
|
import './DataAccessHelper/HttpDataAccessHelper.js';
|
|
@@ -49,41 +49,31 @@ function vtkZipMultiDataSetReader(publicAPI, model) {
|
|
|
49
49
|
|
|
50
50
|
return new Promise(function (resolve, reject) {
|
|
51
51
|
model.arrays = [];
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
var decompressedFiles = unzipSync(new Uint8Array(arrayBuffer));
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
Object.entries(decompressedFiles).forEach(function (_ref) {
|
|
56
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
57
|
+
relativePath = _ref2[0],
|
|
58
|
+
fileData = _ref2[1];
|
|
59
|
+
|
|
56
60
|
if (relativePath.match(/datasets\.json$/i)) {
|
|
57
|
-
|
|
58
|
-
zipEntry.async('string').then(function (txt) {
|
|
59
|
-
model.datasets = JSON.parse(txt);
|
|
60
|
-
processing--;
|
|
61
|
-
|
|
62
|
-
if (!processing) {
|
|
63
|
-
resolve();
|
|
64
|
-
}
|
|
65
|
-
}).catch(reject);
|
|
61
|
+
model.datasets = JSON.parse(strFromU8(fileData));
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
if (relativePath.match(/array_[a-zA-Z]+_[0-9]+/)) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var _relativePath$split$s = relativePath.split('_').slice(-2),
|
|
74
|
-
_relativePath$split$s2 = _slicedToArray(_relativePath$split$s, 2),
|
|
75
|
-
type = _relativePath$split$s2[0],
|
|
76
|
-
id = _relativePath$split$s2[1];
|
|
77
|
-
|
|
78
|
-
model.arrays[id] = macro.newTypedArray(type, arraybuffer);
|
|
65
|
+
var _relativePath$split$s = relativePath.split('_').slice(-2),
|
|
66
|
+
_relativePath$split$s2 = _slicedToArray(_relativePath$split$s, 2),
|
|
67
|
+
type = _relativePath$split$s2[0],
|
|
68
|
+
id = _relativePath$split$s2[1];
|
|
79
69
|
|
|
80
|
-
|
|
81
|
-
resolve();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
70
|
+
model.arrays[id] = macro.newTypedArray(type, fileData.buffer);
|
|
84
71
|
}
|
|
85
72
|
});
|
|
86
|
-
|
|
73
|
+
resolve();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
87
77
|
});
|
|
88
78
|
};
|
|
89
79
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { zipSync } from 'fflate';
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
3
|
import vtkSerializer from './Serializer.js';
|
|
4
4
|
import vtkDataArray from '../../Common/Core/DataArray.js';
|
|
@@ -39,31 +39,16 @@ function vtkZipMultiDataSetWriter(publicAPI, model) {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
publicAPI.write = function () {
|
|
42
|
-
publicAPI.update();
|
|
42
|
+
publicAPI.update();
|
|
43
|
+
var zipInfo = Object.create(null); // Write metadata
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
model.zipFile = new JSZip();
|
|
46
|
-
} // Write metadata
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
model.zipFile.file('datasets.json', JSON.stringify(model.datasets)); // Write Arrays
|
|
45
|
+
zipInfo['datasets.json'] = JSON.stringify(model.datasets); // Write Arrays
|
|
50
46
|
|
|
51
47
|
for (var i = 0; i < model.arrays.length; i++) {
|
|
52
|
-
|
|
53
|
-
binary: true
|
|
54
|
-
});
|
|
48
|
+
zipInfo["array_".concat(vtkDataArray.getDataType(model.arrays[i]), "_").concat(i)] = model.arrays[i];
|
|
55
49
|
}
|
|
56
50
|
|
|
57
|
-
model.
|
|
58
|
-
type: 'blob',
|
|
59
|
-
compression: 'DEFLATE',
|
|
60
|
-
compressionOptions: {
|
|
61
|
-
level: model.compressionLevel
|
|
62
|
-
}
|
|
63
|
-
}).then(function (blob) {
|
|
64
|
-
model.blob = blob;
|
|
65
|
-
return blob;
|
|
66
|
-
});
|
|
51
|
+
model.blob = new Blob([zipSync(zipInfo)]);
|
|
67
52
|
};
|
|
68
53
|
} // ----------------------------------------------------------------------------
|
|
69
54
|
// Object factory
|
|
@@ -71,7 +56,6 @@ function vtkZipMultiDataSetWriter(publicAPI, model) {
|
|
|
71
56
|
|
|
72
57
|
|
|
73
58
|
var DEFAULT_VALUES = {
|
|
74
|
-
zipFile: null,
|
|
75
59
|
compressionLevel: 6,
|
|
76
60
|
blob: null
|
|
77
61
|
}; // ----------------------------------------------------------------------------
|
|
@@ -83,7 +67,7 @@ function extend(publicAPI, model) {
|
|
|
83
67
|
macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
|
|
84
68
|
|
|
85
69
|
macro.algo(publicAPI, model, 1, 0);
|
|
86
|
-
macro.setGet(publicAPI, model, ['
|
|
70
|
+
macro.setGet(publicAPI, model, ['compressionLevel']);
|
|
87
71
|
macro.get(publicAPI, model, ['blob']); // Object specific methods
|
|
88
72
|
|
|
89
73
|
vtkZipMultiDataSetWriter(publicAPI, model);
|
package/IO/Misc/SkyboxReader.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
1
2
|
import macro from '../../macros.js';
|
|
2
3
|
import ImageHelper from '../../Common/Core/ImageHelper.js';
|
|
3
4
|
import vtkTexture from '../../Rendering/Core/Texture.js';
|
|
4
|
-
import
|
|
5
|
+
import { unzipSync, strFromU8 } from 'fflate';
|
|
5
6
|
|
|
6
7
|
// vtkSkyboxReader methods
|
|
7
8
|
// ----------------------------------------------------------------------------
|
|
@@ -41,101 +42,92 @@ function vtkSkyboxReader(publicAPI, model) {
|
|
|
41
42
|
model.busy = true;
|
|
42
43
|
publicAPI.invokeBusy(model.busy);
|
|
43
44
|
model.dataMapping = {};
|
|
44
|
-
var
|
|
45
|
-
var canStartProcessing = false;
|
|
46
|
-
var imageReady = [];
|
|
45
|
+
var imageReady = []; // Finish data processing
|
|
47
46
|
|
|
48
47
|
function workDone() {
|
|
49
|
-
|
|
48
|
+
for (var i = 0; i < model.positions.length; i++) {
|
|
49
|
+
var key = model.positions[i];
|
|
50
|
+
var images = model.dataMapping[key];
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!model.textures[key]) {
|
|
57
|
-
model.textures[key] = vtkTexture.newInstance({
|
|
58
|
-
interpolate: true
|
|
59
|
-
});
|
|
60
|
-
}
|
|
52
|
+
if (!model.textures[key]) {
|
|
53
|
+
model.textures[key] = vtkTexture.newInstance({
|
|
54
|
+
interpolate: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
if (images) {
|
|
59
|
+
var texture = model.textures[key];
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
for (var idx = 0; idx < 6; idx++) {
|
|
62
|
+
var _model$faceMapping$id = model.faceMapping[idx],
|
|
63
|
+
fileName = _model$faceMapping$id.fileName,
|
|
64
|
+
transform = _model$faceMapping$id.transform;
|
|
65
|
+
var readyIndex = imageReady.indexOf("".concat(key, "/").concat(fileName));
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
if (readyIndex !== -1) {
|
|
68
|
+
texture.setInputData(ImageHelper.imageToImageData(images[fileName], transform), idx); // Free image
|
|
73
69
|
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
URL.revokeObjectURL(images[fileName].src);
|
|
71
|
+
delete images[fileName]; // Don't process again
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
}
|
|
73
|
+
imageReady.splice(readyIndex, 1);
|
|
79
74
|
}
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
|
-
|
|
83
|
-
if (workCount === 0) {
|
|
84
|
-
model.busy = false;
|
|
85
|
-
publicAPI.modified();
|
|
86
|
-
publicAPI.invokeBusy(model.busy);
|
|
87
|
-
}
|
|
88
77
|
}
|
|
89
|
-
}
|
|
90
78
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (relativePath.match(/index.json$/)) {
|
|
96
|
-
workCount++;
|
|
97
|
-
zipEntry.async('text').then(function (txt) {
|
|
98
|
-
var config = JSON.parse(txt);
|
|
99
|
-
|
|
100
|
-
if (config.skybox && config.skybox.faceMapping) {
|
|
101
|
-
model.faceMapping = config.skybox.faceMapping;
|
|
102
|
-
}
|
|
79
|
+
model.busy = false;
|
|
80
|
+
publicAPI.modified();
|
|
81
|
+
publicAPI.invokeBusy(model.busy);
|
|
82
|
+
}
|
|
103
83
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
84
|
+
var decompressedFiles = unzipSync(new Uint8Array(content));
|
|
85
|
+
var pending = []; // Find root index.json
|
|
107
86
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
Object.entries(decompressedFiles).forEach(function (_ref) {
|
|
88
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
89
|
+
relativePath = _ref2[0],
|
|
90
|
+
fileData = _ref2[1];
|
|
112
91
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var fileName = pathTokens.pop();
|
|
117
|
-
var key = pathTokens.pop();
|
|
92
|
+
if (relativePath.match(/index.json$/)) {
|
|
93
|
+
var txt = strFromU8(fileData);
|
|
94
|
+
var config = JSON.parse(txt);
|
|
118
95
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
96
|
+
if (config.skybox && config.skybox.faceMapping) {
|
|
97
|
+
model.faceMapping = config.skybox.faceMapping;
|
|
98
|
+
}
|
|
122
99
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
100
|
+
if (config.metadata && config.metadata.skybox && config.metadata.skybox.faceMapping) {
|
|
101
|
+
model.faceMapping = config.metadata.skybox.faceMapping;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
127
104
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
105
|
+
if (relativePath.match(/\.jpg$/)) {
|
|
106
|
+
var pathTokens = relativePath.split('/');
|
|
107
|
+
var fileName = pathTokens.pop();
|
|
108
|
+
var key = pathTokens.pop();
|
|
132
109
|
|
|
133
|
-
|
|
134
|
-
}
|
|
110
|
+
if (!model.dataMapping[key]) {
|
|
111
|
+
model.dataMapping[key] = {};
|
|
135
112
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
113
|
+
|
|
114
|
+
var blob = new Blob([fileData.buffer]);
|
|
115
|
+
var img = new Image();
|
|
116
|
+
var readyKey = "".concat(key, "/").concat(fileName);
|
|
117
|
+
model.dataMapping[key][fileName] = img;
|
|
118
|
+
pending.push(new Promise(function (resolve) {
|
|
119
|
+
img.onload = function () {
|
|
120
|
+
imageReady.push(readyKey);
|
|
121
|
+
resolve();
|
|
122
|
+
};
|
|
123
|
+
}));
|
|
124
|
+
img.src = URL.createObjectURL(blob);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
model.positions = Object.keys(model.dataMapping);
|
|
128
|
+
model.position = model.positions[0];
|
|
129
|
+
Promise.all(pending).then(function () {
|
|
130
|
+
workDone();
|
|
139
131
|
});
|
|
140
132
|
return publicAPI.getReadyPromise();
|
|
141
133
|
};
|
package/IO/XML/XMLReader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
2
|
import { create } from 'xmlbuilder2';
|
|
3
|
-
import
|
|
3
|
+
import { decompressSync } from 'fflate';
|
|
4
4
|
import DataAccessHelper from '../Core/DataAccessHelper.js';
|
|
5
5
|
import Base64 from '../../Common/Core/Base64.js';
|
|
6
6
|
import macro from '../../macros.js';
|
|
@@ -112,7 +112,7 @@ function readerHeader(uint8, headerType) {
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
function uncompressBlock(compressedUint8, output) {
|
|
115
|
-
var uncompressedBlock =
|
|
115
|
+
var uncompressedBlock = decompressSync(compressedUint8);
|
|
116
116
|
output.uint8.set(uncompressedBlock, output.offset);
|
|
117
117
|
output.offset += uncompressedBlock.length;
|
|
118
118
|
} // ----------------------------------------------------------------------------
|
package/IO/XML/XMLWriter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { create } from 'xmlbuilder2';
|
|
2
|
-
import
|
|
2
|
+
import { zlibSync } from 'fflate';
|
|
3
3
|
import macro from '../../macros.js';
|
|
4
4
|
import { fromArrayBuffer } from '../../Common/Core/Base64.js';
|
|
5
5
|
import { FormatTypes, TYPED_ARRAY } from './XMLWriter/Constants.js';
|
|
@@ -8,7 +8,7 @@ import { FormatTypes, TYPED_ARRAY } from './XMLWriter/Constants.js';
|
|
|
8
8
|
// ----------------------------------------------------------------------------
|
|
9
9
|
|
|
10
10
|
function compressBlock(uncompressed) {
|
|
11
|
-
return
|
|
11
|
+
return zlibSync(uncompressed);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function processDataArray(dataArray, format, blockSize) {
|
|
@@ -218,6 +218,10 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
|
|
|
218
218
|
|
|
219
219
|
|
|
220
220
|
publicAPI.handleMouseRotate = function (renderer, position) {
|
|
221
|
+
if (!model.previousPosition) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
221
225
|
var rwi = model._interactor;
|
|
222
226
|
var dx = position.x - model.previousPosition.x;
|
|
223
227
|
var dy = position.y - model.previousPosition.y;
|
|
@@ -251,6 +255,10 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
|
|
|
251
255
|
|
|
252
256
|
|
|
253
257
|
publicAPI.handleMouseSpin = function (renderer, position) {
|
|
258
|
+
if (!model.previousPosition) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
254
262
|
var rwi = model._interactor;
|
|
255
263
|
var camera = renderer.getActiveCamera();
|
|
256
264
|
var center = rwi.getView().getViewportCenter(renderer);
|
|
@@ -265,6 +273,10 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
|
|
|
265
273
|
|
|
266
274
|
|
|
267
275
|
publicAPI.handleMousePan = function (renderer, position) {
|
|
276
|
+
if (!model.previousPosition) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
268
280
|
var camera = renderer.getActiveCamera(); // Calculate the focal depth since we'll be using it a lot
|
|
269
281
|
|
|
270
282
|
var viewFocus = camera.getFocalPoint();
|
|
@@ -291,6 +303,10 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
|
|
|
291
303
|
|
|
292
304
|
|
|
293
305
|
publicAPI.handleMouseDolly = function (renderer, position) {
|
|
306
|
+
if (!model.previousPosition) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
294
310
|
var dy = position.y - model.previousPosition.y;
|
|
295
311
|
var rwi = model._interactor;
|
|
296
312
|
var center = rwi.getView().getViewportCenter(renderer);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function createContextProxyHandler() {
|
|
2
|
+
var cache = new Map();
|
|
3
|
+
var getParameterHandler = {
|
|
4
|
+
apply: function apply(target, gl, args) {
|
|
5
|
+
if (cache.has(args[0])) {
|
|
6
|
+
return cache.get(args[0]);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return target.apply(gl, args);
|
|
10
|
+
}
|
|
11
|
+
}; // only supports single-value setters
|
|
12
|
+
|
|
13
|
+
function cachedSetterHandler(key) {
|
|
14
|
+
return {
|
|
15
|
+
apply: function apply(target, gl, args) {
|
|
16
|
+
cache.set(key, args[0]);
|
|
17
|
+
return target.apply(gl, args);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
} // When a property is accessed on the webgl context proxy,
|
|
21
|
+
// it's accessed is intercepted. If the property name matches
|
|
22
|
+
// any of the keys of `propHandlers`, then that handler is called
|
|
23
|
+
// with the following arguments: (gl, prop, receiver, propValue)
|
|
24
|
+
// - gl (WebGL2RenderingContext): the underlying webgl context
|
|
25
|
+
// - propName (string): the property name
|
|
26
|
+
// - receiver (Proxy): the webgl context proxy
|
|
27
|
+
// - propValue (unknown): the value of `gl[propName]`
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var propHandlers = Object.create(null); // Sets getParameter(property) as a cached getter proxy.
|
|
31
|
+
// propValue.bind(gl) is to avoid Illegal Invocation errors.
|
|
32
|
+
|
|
33
|
+
propHandlers.getParameter = function (gl, prop, receiver, propValue) {
|
|
34
|
+
return new Proxy(propValue.bind(gl), getParameterHandler);
|
|
35
|
+
}; // Sets depthMask(flag) as a cached setter proxy.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
propHandlers.depthMask = function (gl, prop, receiver, propValue) {
|
|
39
|
+
return new Proxy(propValue.bind(gl), cachedSetterHandler(gl.DEPTH_WRITEMASK));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
get: function get(gl, prop, receiver) {
|
|
44
|
+
var value = Reflect.get(gl, prop, receiver);
|
|
45
|
+
|
|
46
|
+
if (value instanceof Function) {
|
|
47
|
+
// prevents Illegal Invocation errors
|
|
48
|
+
value = value.bind(gl);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var propHandler = propHandlers[prop];
|
|
52
|
+
|
|
53
|
+
if (propHandler) {
|
|
54
|
+
return propHandler(gl, prop, receiver, value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
var ContextProxy = {
|
|
62
|
+
createContextProxyHandler: createContextProxyHandler
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { createContextProxyHandler, ContextProxy as default };
|
|
@@ -12,6 +12,7 @@ import vtkTextureUnitManager from './TextureUnitManager.js';
|
|
|
12
12
|
import vtkViewNodeFactory from './ViewNodeFactory.js';
|
|
13
13
|
import vtkRenderPass from '../SceneGraph/RenderPass.js';
|
|
14
14
|
import vtkRenderWindowViewNode from '../SceneGraph/RenderWindowViewNode.js';
|
|
15
|
+
import { createContextProxyHandler } from './RenderWindow/ContextProxy.js';
|
|
15
16
|
|
|
16
17
|
var vtkDebugMacro = macro.vtkDebugMacro,
|
|
17
18
|
vtkErrorMacro = macro.vtkErrorMacro;
|
|
@@ -84,6 +85,7 @@ function popMonitorGLContextCount(cb) {
|
|
|
84
85
|
function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
85
86
|
// Set our className
|
|
86
87
|
model.classHierarchy.push('vtkOpenGLRenderWindow');
|
|
88
|
+
var cachingContextHandler = createContextProxyHandler();
|
|
87
89
|
|
|
88
90
|
publicAPI.getViewNodeFactory = function () {
|
|
89
91
|
return model.myFactory;
|
|
@@ -256,7 +258,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
|
|
|
256
258
|
result = model.canvas.getContext('webgl', options) || model.canvas.getContext('experimental-webgl', options);
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
return result;
|
|
261
|
+
return new Proxy(result, cachingContextHandler);
|
|
260
262
|
}; // Request an XR session on the user device with WebXR,
|
|
261
263
|
// typically in response to a user request such as a button press
|
|
262
264
|
|
package/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import Interaction from './Interaction/index.js';
|
|
|
5
5
|
import IO from './IO/index.js';
|
|
6
6
|
import Rendering from './Rendering/index.js';
|
|
7
7
|
import VTKProxy from './Proxy/index.js';
|
|
8
|
-
import { T as ThirdParty } from './ThirdParty/index.js';
|
|
9
8
|
import Widgets from './Widgets/index.js';
|
|
10
9
|
import macro from './macros.js';
|
|
11
10
|
import vtk from './vtk.js';
|
|
@@ -17,7 +16,6 @@ vtk.Interaction = Interaction;
|
|
|
17
16
|
vtk.IO = IO;
|
|
18
17
|
vtk.Proxy = VTKProxy;
|
|
19
18
|
vtk.Rendering = Rendering;
|
|
20
|
-
vtk.ThirdParty = ThirdParty;
|
|
21
19
|
vtk.Widgets = Widgets;
|
|
22
20
|
vtk.mtime = macro.getCurrentGlobalMTime;
|
|
23
21
|
vtk.macro = macro; // Expose vtk to global scope without exporting it so nested namespace
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitware/vtk.js",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.5.0",
|
|
4
4
|
"description": "Visualization Toolkit for the Web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"3d",
|
|
@@ -33,14 +33,13 @@
|
|
|
33
33
|
"@babel/runtime": "7.17.9",
|
|
34
34
|
"commander": "9.2.0",
|
|
35
35
|
"d3-scale": "4.0.2",
|
|
36
|
+
"fflate": "0.7.3",
|
|
36
37
|
"gl-matrix": "3.4.3",
|
|
37
38
|
"globalthis": "1.0.3",
|
|
38
|
-
"jszip": "3.9.1",
|
|
39
|
-
"pako": "2.0.4",
|
|
40
39
|
"seedrandom": "3.0.5",
|
|
41
40
|
"shader-loader": "1.3.1",
|
|
42
41
|
"shelljs": "0.8.5",
|
|
43
|
-
"spark-md5": "
|
|
42
|
+
"spark-md5": "3.0.2",
|
|
44
43
|
"stream-browserify": "3.0.0",
|
|
45
44
|
"webworker-promise": "0.5.0",
|
|
46
45
|
"worker-loader": "3.0.8",
|