@kitware/vtk.js 33.0.0-beta.2 → 33.0.0-beta.3
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/Common/Core/DataArray.d.ts +4 -0
- package/Common/Core/DataArray.js +3 -0
- package/Common/Core/Math/index.js +1 -1
- package/Common/Core/Math.js +1 -1
- package/Common/Core/URLExtract.js +2 -6
- package/Common/DataModel/Line.js +1 -0
- package/Common/DataModel/PolyLine.js +4 -0
- package/Filters/Core/ThresholdPoints.d.ts +72 -0
- package/Filters/Core/ThresholdPoints.js +219 -0
- package/Filters/General/ContourTriangulator/helper.js +1 -1
- package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +1 -1
- package/IO/Geometry/DracoReader.d.ts +4 -4
- package/IO/Geometry/DracoReader.js +154 -105
- package/IO/Geometry/GLTFImporter/Animations.js +239 -0
- package/IO/Geometry/GLTFImporter/Constants.js +87 -0
- package/IO/Geometry/GLTFImporter/Decoder.js +69 -0
- package/IO/Geometry/GLTFImporter/Extensions.js +110 -0
- package/IO/Geometry/GLTFImporter/ORMTexture.worker.js +42 -0
- package/IO/Geometry/GLTFImporter/Parser.js +359 -0
- package/IO/Geometry/GLTFImporter/Reader.js +518 -0
- package/IO/Geometry/GLTFImporter/Utils.js +165 -0
- package/IO/Geometry/GLTFImporter.d.ts +266 -0
- package/IO/Geometry/GLTFImporter.js +245 -0
- package/IO/Geometry/IFCImporter.d.ts +163 -0
- package/IO/Geometry/IFCImporter.js +270 -0
- package/IO/Geometry/STLReader.d.ts +14 -0
- package/IO/Geometry/STLReader.js +57 -1
- package/IO/Geometry.js +5 -1
- package/IO/Image/HDRReader/Utils.js +1 -1
- package/IO/Image/HDRReader.js +1 -1
- package/IO/Image/TGAReader/Constants.js +28 -0
- package/IO/Image/TGAReader.d.ts +121 -0
- package/IO/Image/TGAReader.js +418 -0
- package/IO/Image/TIFFReader.d.ts +133 -0
- package/IO/Image/TIFFReader.js +144 -0
- package/IO/Image.js +5 -1
- package/IO/XML/XMLPolyDataWriter.js +1 -0
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
- package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
- package/Rendering/Core/Glyph3DMapper.d.ts +45 -29
- package/Rendering/Core/ImageCPRMapper.js +1 -1
- package/Rendering/Core/ImageProperty.d.ts +22 -0
- package/Rendering/Core/PointPicker.js +10 -1
- package/Rendering/Core/Prop3D.js +1 -1
- package/Rendering/Core/RenderWindowInteractor.d.ts +1 -1
- package/Rendering/Core/RenderWindowInteractor.js +1 -1
- package/Rendering/Misc/CanvasView.js +4 -2
- package/Rendering/Misc/RemoteView.d.ts +9 -3
- package/Rendering/Misc/RemoteView.js +7 -3
- package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.d.ts +1 -1
- package/Rendering/OpenGL/ImageMapper.js +14 -7
- package/Rendering/OpenGL/Texture/supportsNorm16Linear.js +97 -0
- package/Rendering/OpenGL/Texture.js +18 -11
- package/Widgets/Widgets3D/AngleWidget/behavior.js +2 -0
- package/Widgets/Widgets3D/InteractiveOrientationWidget.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +17 -0
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -0
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +3 -0
- package/_virtual/rollup-plugin-worker-loader__module_Sources/IO/Geometry/GLTFImporter/ORMTexture.worker.js +296 -0
- package/index.d.ts +5 -0
- package/package.json +12 -10
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { vtkAlgorithm, vtkObject } from './../../interfaces';
|
|
2
|
+
import HtmlDataAccessHelper from './../Core/DataAccessHelper/HtmlDataAccessHelper';
|
|
3
|
+
import HttpDataAccessHelper from './../Core/DataAccessHelper/HttpDataAccessHelper';
|
|
4
|
+
import JSZipDataAccessHelper from './../Core/DataAccessHelper/JSZipDataAccessHelper';
|
|
5
|
+
import LiteHttpDataAccessHelper from './../Core/DataAccessHelper/LiteHttpDataAccessHelper';
|
|
6
|
+
|
|
7
|
+
import vtkActor from './../../Rendering/Core/Actor';
|
|
8
|
+
import vtkRenderer from './../../Rendering/Core/Renderer';
|
|
9
|
+
import vtkCamera from './../../Rendering/Core/Camera';
|
|
10
|
+
|
|
11
|
+
interface IGLTFImporterOptions {
|
|
12
|
+
binary?: boolean;
|
|
13
|
+
compression?: string;
|
|
14
|
+
progressCallback?: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IGLTFAnimation {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
channels: any[];
|
|
21
|
+
samplers: any[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IGLTFAnimationMixer {
|
|
25
|
+
addAnimation: (glTFAnimation: object) => void;
|
|
26
|
+
play: (name: string, weight?: number) => void;
|
|
27
|
+
stop: (name: string) => void;
|
|
28
|
+
stopAll: () => void;
|
|
29
|
+
update: (deltaTime: number) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IGLTFMaterialVariant {
|
|
33
|
+
material: number;
|
|
34
|
+
variants: number[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export interface IGLTFImporterInitialValues {}
|
|
41
|
+
|
|
42
|
+
type vtkGLTFImporterBase = vtkObject &
|
|
43
|
+
Omit<
|
|
44
|
+
vtkAlgorithm,
|
|
45
|
+
| 'getInputData'
|
|
46
|
+
| 'setInputData'
|
|
47
|
+
| 'setInputConnection'
|
|
48
|
+
| 'getInputConnection'
|
|
49
|
+
| 'addInputConnection'
|
|
50
|
+
| 'addInputData'
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
export interface vtkGLTFImporter extends vtkGLTFImporterBase {
|
|
54
|
+
/**
|
|
55
|
+
* Get the actors.
|
|
56
|
+
*/
|
|
57
|
+
getActors(): Map<string, vtkActor>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the animation mixer.
|
|
61
|
+
*/
|
|
62
|
+
getAnimationMixer(): IGLTFAnimationMixer;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the animations.
|
|
66
|
+
*/
|
|
67
|
+
getAnimations(): IGLTFAnimation[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the base url.
|
|
71
|
+
*/
|
|
72
|
+
getBaseURL(): string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the cameras.
|
|
76
|
+
*/
|
|
77
|
+
getCameras(): Map<string, vtkCamera>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
getDataAccessHelper():
|
|
83
|
+
| HtmlDataAccessHelper
|
|
84
|
+
| HttpDataAccessHelper
|
|
85
|
+
| JSZipDataAccessHelper
|
|
86
|
+
| LiteHttpDataAccessHelper;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Get the url of the object to load.
|
|
90
|
+
*/
|
|
91
|
+
getUrl(): string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the variant array.
|
|
95
|
+
*/
|
|
96
|
+
getVariants(): string[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get the variant mappings.
|
|
100
|
+
*/
|
|
101
|
+
getVariantMappings(): Map<string, IGLTFMaterialVariant[]>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Import the actors.
|
|
105
|
+
*/
|
|
106
|
+
importActors(): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Import the animations.
|
|
110
|
+
*/
|
|
111
|
+
importAnimations(): void;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Import the cameras.
|
|
115
|
+
*/
|
|
116
|
+
importCameras(): void;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Import the lights.
|
|
120
|
+
*/
|
|
121
|
+
importLights(): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Invoke the ready event.
|
|
125
|
+
*/
|
|
126
|
+
invokeReady(): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Load the object data.
|
|
130
|
+
* @param {IGLTFImporterOptions} [options]
|
|
131
|
+
*/
|
|
132
|
+
loadData(options?: IGLTFImporterOptions): Promise<any>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @param callback
|
|
137
|
+
*/
|
|
138
|
+
onReady(callback: () => void): void;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Parse data.
|
|
142
|
+
* @param {String | ArrayBuffer} content The content to parse.
|
|
143
|
+
*/
|
|
144
|
+
parse(content: string | ArrayBuffer): void;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Parse data as ArrayBuffer.
|
|
148
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
149
|
+
*/
|
|
150
|
+
parseAsArrayBuffer(content: ArrayBuffer): void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Parse data as text.
|
|
154
|
+
* @param {String} content The content to parse.
|
|
155
|
+
*/
|
|
156
|
+
parseAsText(content: string): void;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
*
|
|
160
|
+
* @param inData
|
|
161
|
+
* @param outData
|
|
162
|
+
*/
|
|
163
|
+
requestData(inData: any, outData: any): void;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
*
|
|
167
|
+
* @param dataAccessHelper
|
|
168
|
+
*/
|
|
169
|
+
setDataAccessHelper(
|
|
170
|
+
dataAccessHelper:
|
|
171
|
+
| HtmlDataAccessHelper
|
|
172
|
+
| HttpDataAccessHelper
|
|
173
|
+
| JSZipDataAccessHelper
|
|
174
|
+
| LiteHttpDataAccessHelper
|
|
175
|
+
): boolean;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Set the url of the object to load.
|
|
179
|
+
* @param {String} url the url of the object to load.
|
|
180
|
+
* @param {IGLTFImporterOptions} [option] The Draco reader options.
|
|
181
|
+
*/
|
|
182
|
+
setUrl(url: string, option?: IGLTFImporterOptions): Promise<string | any>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Set the camera id.
|
|
186
|
+
* @param cameraId The camera id.
|
|
187
|
+
*/
|
|
188
|
+
setCamera(cameraId: string): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Set the Draco decoder.
|
|
192
|
+
* @param dracoDecoder
|
|
193
|
+
*/
|
|
194
|
+
setDracoDecoder(dracoDecoder: any): void;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Set the vtk Renderer.
|
|
198
|
+
* @param renderer The vtk Renderer.
|
|
199
|
+
*/
|
|
200
|
+
setRenderer(renderer: vtkRenderer): void;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Switch to a variant.
|
|
204
|
+
* @param variantIndex The index of the variant to switch to.
|
|
205
|
+
*/
|
|
206
|
+
switchToVariant(variantIndex: number): void;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Method used to decorate a given object (publicAPI+model) with vtkGLTFImporter characteristics.
|
|
211
|
+
*
|
|
212
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
213
|
+
* @param model object on which data structure will be bounds (protected)
|
|
214
|
+
* @param {IGLTFImporterInitialValues} [initialValues] (default: {})
|
|
215
|
+
*/
|
|
216
|
+
export function extend(
|
|
217
|
+
publicAPI: object,
|
|
218
|
+
model: object,
|
|
219
|
+
initialValues?: IGLTFImporterInitialValues
|
|
220
|
+
): void;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Method used to create a new instance of vtkGLTFImporter
|
|
224
|
+
* @param {IGLTFImporterInitialValues} [initialValues] for pre-setting some of its content
|
|
225
|
+
*/
|
|
226
|
+
export function newInstance(
|
|
227
|
+
initialValues?: IGLTFImporterInitialValues
|
|
228
|
+
): vtkGLTFImporter;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Load the WASM decoder from url and set the decoderModule
|
|
232
|
+
* @param url
|
|
233
|
+
* @param binaryName
|
|
234
|
+
*/
|
|
235
|
+
export function setWasmBinary(
|
|
236
|
+
url: string,
|
|
237
|
+
binaryName: string
|
|
238
|
+
): Promise<boolean>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* vtkGLTFImporter can import glTF 2.0 files.
|
|
242
|
+
*
|
|
243
|
+
* The GL Transmission Format (glTF) is an API-neutral runtime asset delivery
|
|
244
|
+
* format. A glTF asset is represented by:
|
|
245
|
+
* * A JSON-formatted file (.gltf) containing a full scene description: node
|
|
246
|
+
* hierarchy, materials, cameras, as well as descriptor information for
|
|
247
|
+
* meshes, animations, and other constructs
|
|
248
|
+
* * Binary files (.bin) containing geometry and animation data, and other
|
|
249
|
+
* buffer-based data
|
|
250
|
+
* * Image files (.jpg, .png) for textures
|
|
251
|
+
*
|
|
252
|
+
* Supported extensions:
|
|
253
|
+
* * KHR_draco_mesh_compression
|
|
254
|
+
* * KHR_lights_punctual
|
|
255
|
+
* * KHR_materials_unlit
|
|
256
|
+
* * KHR_materials_ior
|
|
257
|
+
* * KHR_materials_specular
|
|
258
|
+
* * KHR_materials_variants
|
|
259
|
+
* * EXT_texture_webp
|
|
260
|
+
* * EXT_texture_avif
|
|
261
|
+
*/
|
|
262
|
+
export declare const vtkGLTFImporter: {
|
|
263
|
+
newInstance: typeof newInstance;
|
|
264
|
+
extend: typeof extend;
|
|
265
|
+
};
|
|
266
|
+
export default vtkGLTFImporter;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { m as macro } from '../../macros2.js';
|
|
2
|
+
import BinaryHelper from '../Core/BinaryHelper.js';
|
|
3
|
+
import DataAccessHelper from '../Core/DataAccessHelper.js';
|
|
4
|
+
import vtkDracoReader from './DracoReader.js';
|
|
5
|
+
import { parseGLTF, createVTKObjects, GLTFCameraToVTKCamera, applyTransformToCamera, createPropertyFromGLTFMaterial } from './GLTFImporter/Reader.js';
|
|
6
|
+
import parseGLB from './GLTFImporter/Decoder.js';
|
|
7
|
+
import { createAnimationMixer } from './GLTFImporter/Animations.js';
|
|
8
|
+
import { BINARY_HEADER_MAGIC } from './GLTFImporter/Constants.js';
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
vtkDebugMacro,
|
|
12
|
+
vtkErrorMacro
|
|
13
|
+
} = macro;
|
|
14
|
+
|
|
15
|
+
// ----------------------------------------------------------------------------
|
|
16
|
+
// vtkGLTFImporter methods
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
function vtkGLTFImporter(publicAPI, model) {
|
|
20
|
+
// Set our className
|
|
21
|
+
model.classHierarchy.push('vtkGLTFImporter');
|
|
22
|
+
|
|
23
|
+
// Create default dataAccessHelper if not available
|
|
24
|
+
if (!model.dataAccessHelper) {
|
|
25
|
+
model.dataAccessHelper = DataAccessHelper.get('http');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Internal method to fetch Array
|
|
29
|
+
function fetchData(url) {
|
|
30
|
+
let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
31
|
+
const {
|
|
32
|
+
compression,
|
|
33
|
+
progressCallback
|
|
34
|
+
} = model;
|
|
35
|
+
if (option.binary) {
|
|
36
|
+
return model.dataAccessHelper.fetchBinary(url, {
|
|
37
|
+
compression,
|
|
38
|
+
progressCallback
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return model.dataAccessHelper.fetchText(publicAPI, url, {
|
|
42
|
+
compression,
|
|
43
|
+
progressCallback
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Set DataSet url
|
|
48
|
+
publicAPI.setUrl = function (url) {
|
|
49
|
+
let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
50
|
+
binary: true
|
|
51
|
+
};
|
|
52
|
+
model.url = url;
|
|
53
|
+
|
|
54
|
+
// Remove the file in the URL
|
|
55
|
+
const path = url.split('/');
|
|
56
|
+
path.pop();
|
|
57
|
+
model.baseURL = path.join('/');
|
|
58
|
+
model.compression = option.compression;
|
|
59
|
+
model.sceneId = option.sceneId ? option.sceneId : 0;
|
|
60
|
+
|
|
61
|
+
// Fetch metadata
|
|
62
|
+
return publicAPI.loadData({
|
|
63
|
+
progressCallback: option.progressCallback,
|
|
64
|
+
binary: !!option.binary
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Fetch the actual data arrays
|
|
69
|
+
publicAPI.loadData = function () {
|
|
70
|
+
let option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
const promise = fetchData(model.url, option);
|
|
72
|
+
promise.then(publicAPI.parse);
|
|
73
|
+
return promise;
|
|
74
|
+
};
|
|
75
|
+
publicAPI.parse = content => {
|
|
76
|
+
if (typeof content === 'string') {
|
|
77
|
+
publicAPI.parseAsText(content);
|
|
78
|
+
} else {
|
|
79
|
+
publicAPI.parseAsBinary(content);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
publicAPI.parseAsBinary = async content => {
|
|
83
|
+
if (!content) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (content !== model.parseData) {
|
|
87
|
+
publicAPI.modified();
|
|
88
|
+
} else {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const glTF = {};
|
|
92
|
+
const options = {
|
|
93
|
+
baseUri: model.baseURL
|
|
94
|
+
};
|
|
95
|
+
const magic = BinaryHelper.arrayBufferToString(new Uint8Array(content, 0, 4));
|
|
96
|
+
if (magic === BINARY_HEADER_MAGIC) {
|
|
97
|
+
const {
|
|
98
|
+
json,
|
|
99
|
+
buffers
|
|
100
|
+
} = parseGLB(content);
|
|
101
|
+
vtkDebugMacro('Loaded GLB', json, buffers);
|
|
102
|
+
glTF.glbBuffers = buffers;
|
|
103
|
+
glTF.json = json;
|
|
104
|
+
} else {
|
|
105
|
+
glTF.json = JSON.parse(BinaryHelper.arrayBufferToString(content));
|
|
106
|
+
}
|
|
107
|
+
if (glTF.json.asset === undefined || glTF.json.asset.version[0] < 2) {
|
|
108
|
+
vtkErrorMacro('Unsupported asset. glTF versions >=2.0 are supported.');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
model.glTFTree = await parseGLTF(glTF, options);
|
|
112
|
+
model.actors = new Map();
|
|
113
|
+
model.cameras = new Map();
|
|
114
|
+
model.lights = new Map();
|
|
115
|
+
model.animations = [];
|
|
116
|
+
model.variants = [];
|
|
117
|
+
model.variantMappings = new Map();
|
|
118
|
+
await createVTKObjects(model);
|
|
119
|
+
model.scenes = model.glTFTree.scenes;
|
|
120
|
+
publicAPI.invokeReady();
|
|
121
|
+
};
|
|
122
|
+
publicAPI.parseAsText = content => {
|
|
123
|
+
if (!content) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (content !== model.parseData) {
|
|
127
|
+
publicAPI.modified();
|
|
128
|
+
} else {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
model.parseData = content;
|
|
132
|
+
};
|
|
133
|
+
publicAPI.requestData = (inData, outData) => {
|
|
134
|
+
publicAPI.parse(model.parseData);
|
|
135
|
+
};
|
|
136
|
+
publicAPI.setDracoDecoder = async dracoDecoder => {
|
|
137
|
+
await vtkDracoReader.setDracoDecoder(dracoDecoder);
|
|
138
|
+
};
|
|
139
|
+
publicAPI.importActors = () => {
|
|
140
|
+
// Add actors to renderer
|
|
141
|
+
model.actors.forEach(actor => model.renderer.addActor(actor));
|
|
142
|
+
};
|
|
143
|
+
publicAPI.importCameras = () => {
|
|
144
|
+
// Set up camera
|
|
145
|
+
model.glTFTree.cameras?.forEach(glTFcamera => {
|
|
146
|
+
const camera = GLTFCameraToVTKCamera(glTFcamera);
|
|
147
|
+
model.cameras.set(glTFcamera.id, camera);
|
|
148
|
+
});
|
|
149
|
+
model.scenes.forEach(scene => {
|
|
150
|
+
scene.nodes.forEach(node => {
|
|
151
|
+
const camera = model.cameras.get(node.camera?.id);
|
|
152
|
+
if (camera) {
|
|
153
|
+
applyTransformToCamera(camera, node.transform);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
publicAPI.importAnimations = () => {
|
|
159
|
+
// Set up animations
|
|
160
|
+
if (model.glTFTree.animations?.length > 0) {
|
|
161
|
+
model.animationMixer = createAnimationMixer(model.actors, model.glTFTree.accessors);
|
|
162
|
+
model.glTFTree.animations.forEach(animation => {
|
|
163
|
+
model.animationMixer.addAnimation(animation);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
model.animations = model.glTFTree.animations || [];
|
|
167
|
+
};
|
|
168
|
+
publicAPI.importLights = () => {
|
|
169
|
+
// Set up lights
|
|
170
|
+
model.lights?.forEach(light => {
|
|
171
|
+
vtkDebugMacro('Adding light', light);
|
|
172
|
+
model.renderer.addLight(light);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
publicAPI.setCamera = cameraId => {
|
|
176
|
+
const camera = model.cameras.get(cameraId);
|
|
177
|
+
if (!camera) {
|
|
178
|
+
vtkErrorMacro(`Camera ${cameraId} not found`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
vtkDebugMacro('Setting camera', camera);
|
|
182
|
+
model.renderer.setActiveCamera(camera);
|
|
183
|
+
};
|
|
184
|
+
publicAPI.switchToVariant = async variantIndex => {
|
|
185
|
+
const promises = Array.from(model.actors).map(async _ref => {
|
|
186
|
+
let [nodeId, actor] = _ref;
|
|
187
|
+
vtkDebugMacro('Switching to variant', variantIndex, 'for node', nodeId);
|
|
188
|
+
const variantMappings = model.variantMappings.get(nodeId);
|
|
189
|
+
if (variantMappings) {
|
|
190
|
+
const mapping = variantMappings.find(m => m.variants.includes(variantIndex));
|
|
191
|
+
if (mapping) {
|
|
192
|
+
const variantMaterial = model.glTFTree.materials[mapping.material];
|
|
193
|
+
await createPropertyFromGLTFMaterial(model, variantMaterial, actor);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
await Promise.all(promises);
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ----------------------------------------------------------------------------
|
|
202
|
+
// Object factory
|
|
203
|
+
// ----------------------------------------------------------------------------
|
|
204
|
+
|
|
205
|
+
const DEFAULT_VALUES = {
|
|
206
|
+
// baseURL: null,
|
|
207
|
+
// dataAccessHelper: null,
|
|
208
|
+
// url: null,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// ----------------------------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
function extend(publicAPI, model) {
|
|
214
|
+
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
215
|
+
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
216
|
+
|
|
217
|
+
// Build VTK API
|
|
218
|
+
macro.obj(publicAPI, model);
|
|
219
|
+
macro.get(publicAPI, model, ['url', 'baseURL', 'actors', 'scenes', 'cameras', 'animations', 'animationMixer', 'variants', 'variantMappings']);
|
|
220
|
+
macro.set(publicAPI, model, ['renderer', 'dracoDecoder']);
|
|
221
|
+
macro.event(publicAPI, model, 'ready');
|
|
222
|
+
|
|
223
|
+
// vtkGLTFImporter methods
|
|
224
|
+
vtkGLTFImporter(publicAPI, model);
|
|
225
|
+
|
|
226
|
+
// To support destructuring
|
|
227
|
+
if (!model.compression) {
|
|
228
|
+
model.compression = null;
|
|
229
|
+
}
|
|
230
|
+
if (!model.progressCallback) {
|
|
231
|
+
model.progressCallback = null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// ----------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
const newInstance = macro.newInstance(extend, 'vtkGLTFImporter');
|
|
237
|
+
|
|
238
|
+
// ----------------------------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
var vtkGLTFImporter$1 = {
|
|
241
|
+
extend,
|
|
242
|
+
newInstance
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export { vtkGLTFImporter$1 as default, extend, newInstance };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { vtkAlgorithm, vtkObject } from './../../interfaces';
|
|
2
|
+
import vtkRenderer from './../../Rendering/Core/Renderer';
|
|
3
|
+
import HtmlDataAccessHelper from './../Core/DataAccessHelper/HtmlDataAccessHelper';
|
|
4
|
+
import HttpDataAccessHelper from './../Core/DataAccessHelper/HttpDataAccessHelper';
|
|
5
|
+
import JSZipDataAccessHelper from './../Core/DataAccessHelper/JSZipDataAccessHelper';
|
|
6
|
+
import LiteHttpDataAccessHelper from './../Core/DataAccessHelper/LiteHttpDataAccessHelper';
|
|
7
|
+
|
|
8
|
+
interface IIFCImporterOptions {
|
|
9
|
+
compression?: string;
|
|
10
|
+
progressCallback?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export interface IIFCImporterInitialValues {
|
|
17
|
+
mergeGeometries?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type vtkIFCImporterBase = vtkObject &
|
|
21
|
+
Omit<
|
|
22
|
+
vtkAlgorithm,
|
|
23
|
+
| 'getInputData'
|
|
24
|
+
| 'setInputData'
|
|
25
|
+
| 'setInputConnection'
|
|
26
|
+
| 'getInputConnection'
|
|
27
|
+
| 'addInputConnection'
|
|
28
|
+
| 'addInputData'
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export interface vtkIFCImporter extends vtkIFCImporterBase {
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
getBaseURL(): string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
getDataAccessHelper():
|
|
41
|
+
| HtmlDataAccessHelper
|
|
42
|
+
| HttpDataAccessHelper
|
|
43
|
+
| JSZipDataAccessHelper
|
|
44
|
+
| LiteHttpDataAccessHelper;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the url of the object to load.
|
|
48
|
+
*/
|
|
49
|
+
getUrl(): string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Import actors into the renderer.
|
|
53
|
+
* @param {vtkRenderer} renderer The vtkRenderer to import the actors into.
|
|
54
|
+
*/
|
|
55
|
+
importActors(renderer: vtkRenderer): void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Load the object data.
|
|
59
|
+
* @param {IIFCImporterOptions} [options]
|
|
60
|
+
*/
|
|
61
|
+
loadData(options?: IIFCImporterOptions): Promise<any>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parse data.
|
|
65
|
+
* @param {String | ArrayBuffer} content The content to parse.
|
|
66
|
+
*/
|
|
67
|
+
parse(content: string | ArrayBuffer): void;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parse data as ArrayBuffer.
|
|
71
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
72
|
+
*/
|
|
73
|
+
parseAsArrayBuffer(content: ArrayBuffer): void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @param inData
|
|
78
|
+
* @param outData
|
|
79
|
+
*/
|
|
80
|
+
requestData(inData: any, outData: any): void;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param dataAccessHelper
|
|
85
|
+
*/
|
|
86
|
+
setDataAccessHelper(
|
|
87
|
+
dataAccessHelper:
|
|
88
|
+
| HtmlDataAccessHelper
|
|
89
|
+
| HttpDataAccessHelper
|
|
90
|
+
| JSZipDataAccessHelper
|
|
91
|
+
| LiteHttpDataAccessHelper
|
|
92
|
+
): boolean;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set the url of the object to load.
|
|
96
|
+
* @param {String} url the url of the object to load.
|
|
97
|
+
* @param {IIFCImporterOptions} [option] The PLY reader options.
|
|
98
|
+
*/
|
|
99
|
+
setUrl(url: string, option?: IIFCImporterOptions): Promise<string | any>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Set WebIFC api to be used by vtkIFCImporter
|
|
104
|
+
* @param {object} ifcApi
|
|
105
|
+
*/
|
|
106
|
+
export function setIFCAPI(ifcApi: any): void;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Method used to decorate a given object (publicAPI+model) with vtkIFCImporter characteristics.
|
|
110
|
+
*
|
|
111
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
112
|
+
* @param model object on which data structure will be bounds (protected)
|
|
113
|
+
* @param {IIFCImporterInitialValues} [initialValues] (default: {})
|
|
114
|
+
*/
|
|
115
|
+
export function extend(
|
|
116
|
+
publicAPI: object,
|
|
117
|
+
model: object,
|
|
118
|
+
initialValues?: IIFCImporterInitialValues
|
|
119
|
+
): void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Method used to create a new instance of vtkIFCImporter
|
|
123
|
+
* @param {IIFCImporterInitialValues} [initialValues] for pre-setting some of its content
|
|
124
|
+
*/
|
|
125
|
+
export function newInstance(
|
|
126
|
+
initialValues?: IIFCImporterInitialValues
|
|
127
|
+
): vtkIFCImporter;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* vtkIFCImporter is a source object that reads Industry Foundation Class(IFC) files.
|
|
131
|
+
*
|
|
132
|
+
* The vtkIFCImporter is using web-ifc library to parse the IFC file.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```js
|
|
136
|
+
* import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader';
|
|
137
|
+
* import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter';
|
|
138
|
+
*
|
|
139
|
+
* function update() {
|
|
140
|
+
* importer.onReady(() => {
|
|
141
|
+
* importer.importActors(renderer);
|
|
142
|
+
* renderer.resetCamera();
|
|
143
|
+
* renderWindow.render();
|
|
144
|
+
* });
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* vtkResourceLoader
|
|
148
|
+
* .loadScript('https://cdn.jsdelivr.net/npm/web-ifc@0.0.55/web-ifc-api-iife.js')
|
|
149
|
+
* .then(() => {
|
|
150
|
+
* // Pass WebIFC api to vtkIFCImporter
|
|
151
|
+
* vtkIFCImporter.setIFCAPI(window.WebIFC);
|
|
152
|
+
*
|
|
153
|
+
* // Trigger data download
|
|
154
|
+
* importer.setUrl(`${__BASE_PATH__}/data/ifc/house.ifc`).then(update);
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare const vtkIFCImporter: {
|
|
159
|
+
newInstance: typeof newInstance;
|
|
160
|
+
extend: typeof extend;
|
|
161
|
+
setIFCAPI: typeof setIFCAPI;
|
|
162
|
+
};
|
|
163
|
+
export default vtkIFCImporter;
|