@shapediver/viewer.data-engine.geometry-engine 3.9.0 → 3.9.2

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.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/GeometryEngine.d.ts +2 -2
  3. package/dist/GeometryEngine.d.ts.map +1 -1
  4. package/dist/GeometryEngine.js +47 -30
  5. package/dist/GeometryEngine.js.map +1 -1
  6. package/dist/gltfv1/GLTFLoader.d.ts +2 -2
  7. package/dist/gltfv1/GLTFLoader.d.ts.map +1 -1
  8. package/dist/gltfv1/GLTFLoader.js +143 -75
  9. package/dist/gltfv1/GLTFLoader.js.map +1 -1
  10. package/dist/gltfv1/SDGTFLoader.d.ts +1 -1
  11. package/dist/gltfv1/SDGTFLoader.d.ts.map +1 -1
  12. package/dist/gltfv1/SDGTFLoader.js +95 -74
  13. package/dist/gltfv1/SDGTFLoader.js.map +1 -1
  14. package/dist/gltfv2/GLTFLoader.d.ts +6 -6
  15. package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
  16. package/dist/gltfv2/GLTFLoader.js +200 -112
  17. package/dist/gltfv2/GLTFLoader.js.map +1 -1
  18. package/dist/gltfv2/draco/draco_decoder.d.ts.map +1 -1
  19. package/dist/gltfv2/draco/draco_decoder.js +101696 -49810
  20. package/dist/gltfv2/draco/draco_decoder.js.map +1 -1
  21. package/dist/gltfv2/loaders/AccessorLoader.d.ts +3 -3
  22. package/dist/gltfv2/loaders/AccessorLoader.d.ts.map +1 -1
  23. package/dist/gltfv2/loaders/AccessorLoader.js +21 -13
  24. package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
  25. package/dist/gltfv2/loaders/BufferLoader.d.ts +1 -1
  26. package/dist/gltfv2/loaders/BufferLoader.d.ts.map +1 -1
  27. package/dist/gltfv2/loaders/BufferLoader.js +10 -8
  28. package/dist/gltfv2/loaders/BufferLoader.js.map +1 -1
  29. package/dist/gltfv2/loaders/BufferViewLoader.d.ts +2 -2
  30. package/dist/gltfv2/loaders/BufferViewLoader.d.ts.map +1 -1
  31. package/dist/gltfv2/loaders/BufferViewLoader.js +5 -5
  32. package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -1
  33. package/dist/gltfv2/loaders/GeometryLoader.d.ts +7 -7
  34. package/dist/gltfv2/loaders/GeometryLoader.d.ts.map +1 -1
  35. package/dist/gltfv2/loaders/GeometryLoader.js +39 -28
  36. package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
  37. package/dist/gltfv2/loaders/MaterialLoader.d.ts +3 -3
  38. package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -1
  39. package/dist/gltfv2/loaders/MaterialLoader.js +301 -108
  40. package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
  41. package/dist/gltfv2/loaders/TextureLoader.d.ts +2 -2
  42. package/dist/gltfv2/loaders/TextureLoader.d.ts.map +1 -1
  43. package/dist/gltfv2/loaders/TextureLoader.js +23 -15
  44. package/dist/gltfv2/loaders/TextureLoader.js.map +1 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js.map +1 -1
  48. package/package.json +57 -57
@@ -1 +1 @@
1
- {"version":3,"file":"GLTFLoader.d.ts","sourceRoot":"","sources":["../../src/gltfv2/GLTFLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,qCAAqC,CAAC;AAW1E,OAAO,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AA2BvE,oBAAY,eAAe;IACvB,eAAe,oBAAoB;IACnC,0BAA0B,+BAA+B;IACzD,mBAAmB,wBAAwB;IAC3C,uBAAuB,4BAA4B;IACnD,iBAAiB,sBAAsB;IACvC,mCAAmC,wCAAwC;IAC3E,mBAAmB,wBAAwB;IAC3C,sBAAsB,2BAA2B;IACjD,0BAA0B,+BAA+B;IACzD,mBAAmB,wBAAwB;IAC3C,sBAAsB,2BAA2B;IACjD,oBAAo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,QAAQ,CAAC,oBAAoB,CAAO;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyC;IAExE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAEP;IACP,OAAO,CAAC,uBAAuB,CAAK;IACpC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAiB;IAM1B,IAAI,CAChB,OAAO,EAAE,QAAQ,EACjB,UAAU,CAAC,EAAE,WAAW,EACxB,UAAU,CAAC,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;KACtB,EACD,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC;IA6JR,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IA8FtE;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAiDrB,OAAO,CAAC,UAAU;IAmClB,OAAO,CAAC,UAAU;YAsFJ,QAAQ;YAkPR,SAAS;IAkBvB,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,4BAA4B;CA4EpC"}
@@ -10,18 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GLTFLoader = exports.GLTF_EXTENSIONS = void 0;
13
+ const viewer_rendering_engine_camera_engine_1 = require("@shapediver/viewer.rendering-engine.camera-engine");
14
+ const viewer_rendering_engine_light_engine_1 = require("@shapediver/viewer.rendering-engine.light-engine");
13
15
  const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
14
16
  const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
15
- const gl_matrix_1 = require("gl-matrix");
16
17
  const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
17
- const viewer_rendering_engine_camera_engine_1 = require("@shapediver/viewer.rendering-engine.camera-engine");
18
- const viewer_rendering_engine_light_engine_1 = require("@shapediver/viewer.rendering-engine.light-engine");
18
+ const gl_matrix_1 = require("gl-matrix");
19
+ const AccessorLoader_1 = require("./loaders/AccessorLoader");
19
20
  const BufferLoader_1 = require("./loaders/BufferLoader");
20
21
  const BufferViewLoader_1 = require("./loaders/BufferViewLoader");
21
- const AccessorLoader_1 = require("./loaders/AccessorLoader");
22
- const TextureLoader_1 = require("./loaders/TextureLoader");
23
- const MaterialLoader_1 = require("./loaders/MaterialLoader");
24
22
  const GeometryLoader_1 = require("./loaders/GeometryLoader");
23
+ const MaterialLoader_1 = require("./loaders/MaterialLoader");
24
+ const TextureLoader_1 = require("./loaders/TextureLoader");
25
25
  var GLTF_EXTENSIONS;
26
26
  (function (GLTF_EXTENSIONS) {
27
27
  GLTF_EXTENSIONS["KHR_BINARY_GLTF"] = "KHR_binary_glTF";
@@ -42,7 +42,7 @@ var GLTF_EXTENSIONS;
42
42
  GLTF_EXTENSIONS["EXT_MESH_GPU_INSTANCING"] = "EXT_mesh_gpu_instancing";
43
43
  })(GLTF_EXTENSIONS = exports.GLTF_EXTENSIONS || (exports.GLTF_EXTENSIONS = {}));
44
44
  // eslint-disable-next-line @typescript-eslint/no-var-requires
45
- const DRACO = require('./draco/draco_decoder.js');
45
+ const DRACO = require("./draco/draco_decoder.js");
46
46
  class GLTFLoader {
47
47
  constructor() {
48
48
  // #region Properties (22)
@@ -54,7 +54,7 @@ class GLTFLoader {
54
54
  this._performanceEvaluator = viewer_shared_services_1.PerformanceEvaluator.instance;
55
55
  this._progressUpdateLimit = 500;
56
56
  this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
57
- this._eventId = '';
57
+ this._eventId = "";
58
58
  this._nodes = {};
59
59
  this._numberOfConvertedNodes = 0;
60
60
  this._numberOfNodes = 0;
@@ -67,14 +67,21 @@ class GLTFLoader {
67
67
  var _a, _b;
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
69
  this._eventId = taskEventId || this._uuidGenerator.create();
70
- const eventStart = { type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0, status: 'Starting glTF 2.0 loading.' };
70
+ const eventStart = {
71
+ type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
72
+ id: this._eventId,
73
+ progress: 0,
74
+ status: "Starting glTF 2.0 loading.",
75
+ };
71
76
  this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
72
77
  this._numberOfConvertedNodes = 0;
73
78
  this._numberOfNodes = content.nodes ? content.nodes.length : 0;
74
79
  this._progressTimer = performance.now();
75
80
  this._baseUri = baseUri;
76
81
  if (gltfBinary && gltfHeader)
77
- this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH + gltfHeader.contentLength + 8, gltfHeader.length);
82
+ this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
83
+ gltfHeader.contentLength +
84
+ 8, gltfHeader.length);
78
85
  this._content = content;
79
86
  this.validateVersionAndExtensions();
80
87
  const dracoModule = yield new DRACO();
@@ -89,17 +96,25 @@ class GLTFLoader {
89
96
  this._materialLoader = new MaterialLoader_1.MaterialLoader(this._content, this._textureLoader);
90
97
  yield this._materialLoader.load();
91
98
  this._geometryLoader = new GeometryLoader_1.GeometryLoader(this._content, this._accessorLoader, this._bufferViewLoader, this._materialLoader, dracoModule);
92
- const eventProgressInit = { type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0.1, status: 'Initial logic of glTF loading.' };
99
+ const eventProgressInit = {
100
+ type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
101
+ id: this._eventId,
102
+ progress: 0.1,
103
+ status: "Initial logic of glTF loading.",
104
+ };
93
105
  this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventProgressInit);
94
106
  const node = yield this.loadScene();
95
- if (this._content.extensions && this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
96
- const variants = this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS].variants;
107
+ if (this._content.extensions &&
108
+ this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
109
+ const variants = this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]
110
+ .variants;
97
111
  for (let i = 0; i < variants.length; i++)
98
112
  this._geometryLoader.materialVariantsData.variants.push(variants[i].name);
99
113
  this._geometryLoader.materialVariantsData.variantIndex = 0;
100
114
  node.data.push(this._geometryLoader.materialVariantsData);
101
115
  }
102
- if (this._content.skins !== undefined && this._content.nodes !== undefined) {
116
+ if (this._content.skins !== undefined &&
117
+ this._content.nodes !== undefined) {
103
118
  for (let i = 0; i < ((_a = this._content.nodes) === null || _a === void 0 ? void 0 : _a.length); i++) {
104
119
  if (this._content.nodes[i].skin !== undefined) {
105
120
  const skinDef = this.loadSkin(this._content.nodes[i].skin);
@@ -125,25 +140,34 @@ class GLTFLoader {
125
140
  if (this._content.animations)
126
141
  for (let i = 0; i < ((_b = this._content.animations) === null || _b === void 0 ? void 0 : _b.length); i++)
127
142
  node.data.push(this.loadAnimation(i));
128
- const eventEnd = { type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 1, status: 'GlTF loading complete.' };
143
+ const eventEnd = {
144
+ type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
145
+ id: this._eventId,
146
+ progress: 1,
147
+ status: "GlTF loading complete.",
148
+ };
129
149
  this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
130
150
  return node;
131
151
  });
132
152
  }
133
153
  loadWithUrl(url) {
134
154
  return __awaiter(this, void 0, void 0, function* () {
135
- this._performanceEvaluator.startSection('gltfProcessing.' + url);
136
- this._performanceEvaluator.startSection('loadGltf.' + url);
137
- const axiosResponse = yield this._httpClient.get(url, {
138
- responseType: 'arraybuffer'
139
- });
140
- this._performanceEvaluator.endSection('loadGltf.' + url);
155
+ this._performanceEvaluator.startSection("gltfProcessing." + url);
156
+ this._performanceEvaluator.startSection("loadGltf." + url);
157
+ const axiosResponse = (yield this._httpClient.get(url, {
158
+ responseType: "arraybuffer",
159
+ }));
160
+ this._performanceEvaluator.endSection("loadGltf." + url);
141
161
  let gltfContent, gltfBinary, gltfBaseUrl, gltfHeader;
142
162
  const magic = new TextDecoder().decode(new Uint8Array(axiosResponse.data, 0, 4));
143
- const isBinary = magic === 'glTF' || (axiosResponse.headers['content-type'] &&
144
- (axiosResponse.headers['content-type'] === 'model/gltf-binary' ||
145
- axiosResponse.headers['content-type'] === 'application/octet-stream' ||
146
- axiosResponse.headers['content-type'] === 'model/gltf.binary'));
163
+ const isBinary = magic === "glTF" ||
164
+ (axiosResponse.headers["content-type"] &&
165
+ (axiosResponse.headers["content-type"] ===
166
+ "model/gltf-binary" ||
167
+ axiosResponse.headers["content-type"] ===
168
+ "application/octet-stream" ||
169
+ axiosResponse.headers["content-type"] ===
170
+ "model/gltf.binary"));
147
171
  if (isBinary) {
148
172
  gltfBinary = axiosResponse.data;
149
173
  // create header data
@@ -153,27 +177,32 @@ class GLTFLoader {
153
177
  version: headerDataView.getUint32(4, true),
154
178
  length: headerDataView.getUint32(8, true),
155
179
  contentLength: headerDataView.getUint32(12, true),
156
- contentFormat: headerDataView.getUint32(16, true)
180
+ contentFormat: headerDataView.getUint32(16, true),
157
181
  };
158
- if (gltfHeader.magic != 'glTF')
159
- throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('GLTFLoader.load: Invalid data: sdgTF magic wrong.');
182
+ if (gltfHeader.magic != "glTF")
183
+ throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError("GLTFLoader.load: Invalid data: sdgTF magic wrong.");
160
184
  // create content
161
185
  const contentDataView = new DataView(gltfBinary, this.BINARY_EXTENSION_HEADER_LENGTH, gltfHeader.contentLength);
162
186
  const contentDecoded = new TextDecoder().decode(contentDataView);
163
187
  gltfContent = JSON.parse(contentDecoded);
164
188
  // create body
165
- this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH + gltfHeader.contentLength + 8, gltfHeader.length);
189
+ this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH +
190
+ gltfHeader.contentLength +
191
+ 8, gltfHeader.length);
166
192
  }
167
193
  else {
168
194
  gltfContent = JSON.parse(new TextDecoder().decode(axiosResponse.data));
169
195
  const removeLastDirectoryPartOf = (the_url) => {
170
- const dir_char = the_url.includes('/') ? '/' : '\\';
196
+ const dir_char = the_url.includes("/") ? "/" : "\\";
171
197
  const the_arr = the_url.split(dir_char);
172
198
  the_arr.pop();
173
199
  return the_arr.join(dir_char);
174
200
  };
175
201
  gltfBaseUrl = removeLastDirectoryPartOf(url);
176
- if (!gltfBaseUrl && window && window.location && window.location.href)
202
+ if (!gltfBaseUrl &&
203
+ window &&
204
+ window.location &&
205
+ window.location.href)
177
206
  gltfBaseUrl = removeLastDirectoryPartOf(window.location.href);
178
207
  }
179
208
  return yield this.load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl);
@@ -182,15 +211,15 @@ class GLTFLoader {
182
211
  // #endregion Public Methods (2)
183
212
  // #region Private Methods (7)
184
213
  /**
185
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
186
- * @param {number} animationIndex
187
- * @return {Promise<AnimationClip>}
188
- */
214
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
215
+ * @param {number} animationIndex
216
+ * @return {Promise<AnimationClip>}
217
+ */
189
218
  loadAnimation(animationId) {
190
219
  if (!this._content.animations)
191
- throw new Error('Animations not available.');
220
+ throw new Error("Animations not available.");
192
221
  if (!this._content.animations[animationId])
193
- throw new Error('Animations not available.');
222
+ throw new Error("Animations not available.");
194
223
  const animationDef = this._content.animations[animationId];
195
224
  const animationTracks = [];
196
225
  let min = Infinity, max = -Infinity;
@@ -201,36 +230,36 @@ class GLTFLoader {
201
230
  const path = target.path;
202
231
  const node = this._nodes[target.node];
203
232
  if (node === undefined)
204
- throw new Error('Animation node not available.');
233
+ throw new Error("Animation node not available.");
205
234
  const input = this._accessorLoader.getAccessor(sampler.input);
206
235
  min = Math.min(min, input.min[0]);
207
236
  max = Math.max(max, input.max[0]);
208
237
  const output = this._accessorLoader.getAccessor(sampler.output);
209
238
  let interpolation = sampler.interpolation;
210
- if (interpolation === 'CUBICSPLINE') {
211
- this._logger.warn('Animation with CUBICSPLINE interpolation is currently not supported. Assigning linear interpolation instead.');
212
- interpolation = 'linear';
239
+ if (interpolation === "CUBICSPLINE") {
240
+ this._logger.warn("Animation with CUBICSPLINE interpolation is currently not supported. Assigning linear interpolation instead.");
241
+ interpolation = "linear";
213
242
  }
214
243
  animationTracks.push({
215
244
  node,
216
245
  times: input.array,
217
246
  values: output.array,
218
247
  path: path,
219
- interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase()
248
+ interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase(),
220
249
  });
221
250
  }
222
- return new viewer_shared_types_1.AnimationData(animationDef.name || 'gltf_animation_' + animationId, animationTracks, min, max - min);
251
+ return new viewer_shared_types_1.AnimationData(animationDef.name || "gltf_animation_" + animationId, animationTracks, min, max - min);
223
252
  }
224
253
  loadCamera(cameraId) {
225
254
  if (!this._content.cameras)
226
- throw new Error('Cameras not available.');
255
+ throw new Error("Cameras not available.");
227
256
  if (!this._content.cameras[cameraId])
228
- throw new Error('Cameras not available.');
257
+ throw new Error("Cameras not available.");
229
258
  const cameraDef = this._content.cameras[cameraId];
230
- const cameraNode = new viewer_shared_node_tree_1.TreeNode(cameraDef.name || 'camera_' + cameraId);
259
+ const cameraNode = new viewer_shared_node_tree_1.TreeNode(cameraDef.name || "camera_" + cameraId);
231
260
  cameraNode.originalName = cameraDef.name;
232
261
  let cameraData;
233
- if (cameraDef.type === 'perspective') {
262
+ if (cameraDef.type === "perspective") {
234
263
  const perspectiveCameraDef = cameraDef.perspective;
235
264
  cameraData = new viewer_rendering_engine_camera_engine_1.PerspectiveCamera(cameraNode.id);
236
265
  cameraNode.data.push(cameraData);
@@ -255,26 +284,35 @@ class GLTFLoader {
255
284
  return cameraNode;
256
285
  }
257
286
  loadLights(lightId) {
258
- if (!this._content.extensions || !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL] || !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights)
287
+ if (!this._content.extensions ||
288
+ !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL] ||
289
+ !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
290
+ .lights)
259
291
  throw new Error(`Extension ${GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL} not available.`);
260
- if (!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights[lightId])
261
- throw new Error('Light not available.');
262
- const lightDef = this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights[lightId];
263
- const lightNode = new viewer_shared_node_tree_1.TreeNode(lightDef.name || 'light_' + lightId);
292
+ if (!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
293
+ .lights[lightId])
294
+ throw new Error("Light not available.");
295
+ const lightDef = this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL]
296
+ .lights[lightId];
297
+ const lightNode = new viewer_shared_node_tree_1.TreeNode(lightDef.name || "light_" + lightId);
264
298
  lightNode.originalName = lightDef.name;
265
- let color = '#ffffffff';
299
+ let color = "#ffffffff";
266
300
  if (lightDef.color !== undefined)
267
- color = [lightDef.color[0] * 255, lightDef.color[1] * 255, lightDef.color[2] * 255];
301
+ color = [
302
+ lightDef.color[0] * 255,
303
+ lightDef.color[1] * 255,
304
+ lightDef.color[2] * 255,
305
+ ];
268
306
  const range = lightDef.range !== undefined ? lightDef.range : 0;
269
307
  let lightData;
270
- if (lightDef.type === 'directional') {
308
+ if (lightDef.type === "directional") {
271
309
  lightData = new viewer_rendering_engine_light_engine_1.DirectionalLight({ color });
272
310
  lightNode.data.push(lightData);
273
311
  const directionalLightData = lightData;
274
312
  if (lightDef.intensity !== undefined)
275
313
  directionalLightData.intensity = lightDef.intensity;
276
314
  }
277
- else if (lightDef.type === 'point') {
315
+ else if (lightDef.type === "point") {
278
316
  lightData = new viewer_rendering_engine_light_engine_1.PointLight({ color });
279
317
  lightNode.data.push(lightData);
280
318
  const pointLightData = lightData;
@@ -284,16 +322,24 @@ class GLTFLoader {
284
322
  lightData.intensity = lightDef.intensity;
285
323
  pointLightData.position = [0, 0, 0];
286
324
  }
287
- else if (lightDef.type === 'spot') {
325
+ else if (lightDef.type === "spot") {
288
326
  lightData = new viewer_rendering_engine_light_engine_1.SpotLight({ color });
289
327
  lightNode.data.push(lightData);
290
328
  lightDef.spot = lightDef.spot || {};
291
- lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
292
- lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
329
+ lightDef.spot.innerConeAngle =
330
+ lightDef.spot.innerConeAngle !== undefined
331
+ ? lightDef.spot.innerConeAngle
332
+ : 0;
333
+ lightDef.spot.outerConeAngle =
334
+ lightDef.spot.outerConeAngle !== undefined
335
+ ? lightDef.spot.outerConeAngle
336
+ : Math.PI / 4.0;
293
337
  const spotLightData = lightData;
294
338
  spotLightData.distance = range;
295
339
  spotLightData.angle = lightDef.spot.outerConeAngle;
296
- spotLightData.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
340
+ spotLightData.penumbra =
341
+ 1.0 -
342
+ lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
297
343
  spotLightData.decay = 2;
298
344
  if (lightDef.intensity !== undefined)
299
345
  lightData.intensity = lightDef.intensity;
@@ -301,7 +347,7 @@ class GLTFLoader {
301
347
  spotLightData.target = [0, 0, -1];
302
348
  }
303
349
  else {
304
- throw new Error('Unexpected light type: ' + lightDef.type);
350
+ throw new Error("Unexpected light type: " + lightDef.type);
305
351
  }
306
352
  lightData.useNodeData = true;
307
353
  return lightNode;
@@ -309,56 +355,66 @@ class GLTFLoader {
309
355
  loadNode(nodeId) {
310
356
  return __awaiter(this, void 0, void 0, function* () {
311
357
  if (!this._content.nodes)
312
- throw new Error('Nodes not available.');
358
+ throw new Error("Nodes not available.");
313
359
  if (!this._content.nodes[nodeId])
314
- throw new Error('Node not available.');
360
+ throw new Error("Node not available.");
315
361
  const node = this._content.nodes[nodeId];
316
- const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || 'node_' + nodeId);
362
+ const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || "node_" + nodeId);
317
363
  nodeDef.originalName = node.name;
318
364
  this._nodes[nodeId] = nodeDef;
319
365
  if (node.matrix) {
320
366
  nodeDef.addTransformation({
321
- id: 'gltf_matrix',
322
- matrix: gl_matrix_1.mat4.fromValues(node.matrix[0], node.matrix[1], node.matrix[2], node.matrix[3], node.matrix[4], node.matrix[5], node.matrix[6], node.matrix[7], node.matrix[8], node.matrix[9], node.matrix[10], node.matrix[11], node.matrix[12], node.matrix[13], node.matrix[14], node.matrix[15])
367
+ id: "gltf_matrix",
368
+ matrix: gl_matrix_1.mat4.fromValues(node.matrix[0], node.matrix[1], node.matrix[2], node.matrix[3], node.matrix[4], node.matrix[5], node.matrix[6], node.matrix[7], node.matrix[8], node.matrix[9], node.matrix[10], node.matrix[11], node.matrix[12], node.matrix[13], node.matrix[14], node.matrix[15]),
323
369
  });
324
370
  nodeDef.addTransformation({
325
- id: 'gltf_matrix_translation',
326
- matrix: gl_matrix_1.mat4.create()
371
+ id: "gltf_matrix_translation",
372
+ matrix: gl_matrix_1.mat4.create(),
327
373
  });
328
374
  nodeDef.addTransformation({
329
- id: 'gltf_matrix_rotation',
330
- matrix: gl_matrix_1.mat4.create()
375
+ id: "gltf_matrix_rotation",
376
+ matrix: gl_matrix_1.mat4.create(),
331
377
  });
332
378
  nodeDef.addTransformation({
333
- id: 'gltf_matrix_scale',
334
- matrix: gl_matrix_1.mat4.create()
379
+ id: "gltf_matrix_scale",
380
+ matrix: gl_matrix_1.mat4.create(),
335
381
  });
336
382
  }
337
383
  else if (node.translation || node.scale || node.rotation) {
338
- const matT = node.translation ? gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.translation[0], node.translation[1], node.translation[2])) : gl_matrix_1.mat4.create();
339
- const matS = node.scale ? gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.scale[0], node.scale[1], node.scale[2])) : gl_matrix_1.mat4.create();
340
- const matR = node.rotation ? gl_matrix_1.mat4.fromQuat(gl_matrix_1.mat4.create(), gl_matrix_1.vec4.fromValues(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3])) : gl_matrix_1.mat4.create();
384
+ const matT = node.translation
385
+ ? gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.translation[0], node.translation[1], node.translation[2]))
386
+ : gl_matrix_1.mat4.create();
387
+ const matS = node.scale
388
+ ? gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(node.scale[0], node.scale[1], node.scale[2]))
389
+ : gl_matrix_1.mat4.create();
390
+ const matR = node.rotation
391
+ ? gl_matrix_1.mat4.fromQuat(gl_matrix_1.mat4.create(), gl_matrix_1.vec4.fromValues(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]))
392
+ : gl_matrix_1.mat4.create();
341
393
  nodeDef.addTransformation({
342
- id: 'gltf_matrix_translation',
343
- matrix: matT
394
+ id: "gltf_matrix_translation",
395
+ matrix: matT,
344
396
  });
345
397
  nodeDef.addTransformation({
346
- id: 'gltf_matrix_rotation',
347
- matrix: matR
398
+ id: "gltf_matrix_rotation",
399
+ matrix: matR,
348
400
  });
349
401
  nodeDef.addTransformation({
350
- id: 'gltf_matrix_scale',
351
- matrix: matS
402
+ id: "gltf_matrix_scale",
403
+ matrix: matS,
352
404
  });
353
405
  }
354
406
  const instanceTransformations = [];
355
- if (node.extensions && node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING]) {
356
- const ext = node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING].attributes;
357
- if (ext['TRANSLATION'] && ext['ROTATION'] && ext['SCALE']) {
358
- const translationAttribute = this._accessorLoader.getAccessor(ext['TRANSLATION']);
359
- const rotationAttribute = this._accessorLoader.getAccessor(ext['ROTATION']);
360
- const scaleAttribute = this._accessorLoader.getAccessor(ext['SCALE']);
361
- if (translationAttribute && rotationAttribute && scaleAttribute) {
407
+ if (node.extensions &&
408
+ node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING]) {
409
+ const ext = node.extensions[GLTF_EXTENSIONS.EXT_MESH_GPU_INSTANCING]
410
+ .attributes;
411
+ if (ext["TRANSLATION"] && ext["ROTATION"] && ext["SCALE"]) {
412
+ const translationAttribute = this._accessorLoader.getAccessor(ext["TRANSLATION"]);
413
+ const rotationAttribute = this._accessorLoader.getAccessor(ext["ROTATION"]);
414
+ const scaleAttribute = this._accessorLoader.getAccessor(ext["SCALE"]);
415
+ if (translationAttribute &&
416
+ rotationAttribute &&
417
+ scaleAttribute) {
362
418
  const translationMatrices = [];
363
419
  for (let i = 0; i < translationAttribute.array.length; i += 3)
364
420
  translationMatrices.push(gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(translationAttribute.array[i], translationAttribute.array[i + 1], translationAttribute.array[i + 2])));
@@ -368,7 +424,9 @@ class GLTFLoader {
368
424
  const scaleMatrices = [];
369
425
  for (let i = 0; i < scaleAttribute.array.length; i += 3)
370
426
  scaleMatrices.push(gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(scaleAttribute.array[i], scaleAttribute.array[i + 1], scaleAttribute.array[i + 2])));
371
- if (translationMatrices.length === rotationMatrices.length && translationMatrices.length === scaleMatrices.length) {
427
+ if (translationMatrices.length ===
428
+ rotationMatrices.length &&
429
+ translationMatrices.length === scaleMatrices.length) {
372
430
  for (let i = 0; i < translationMatrices.length; i++) {
373
431
  const transformationMatrix = gl_matrix_1.mat4.create();
374
432
  gl_matrix_1.mat4.multiply(transformationMatrix, translationMatrices[i], rotationMatrices[i]);
@@ -383,7 +441,8 @@ class GLTFLoader {
383
441
  nodeDef.addChild(this._geometryLoader.loadMesh(node.mesh, node.weights, instanceTransformations));
384
442
  if (node.camera !== undefined)
385
443
  nodeDef.addChild(this.loadCamera(node.camera));
386
- if (node.extensions && node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL])
444
+ if (node.extensions &&
445
+ node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL])
387
446
  nodeDef.addChild(this.loadLights(node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light));
388
447
  if (node.children) {
389
448
  for (let i = 0, len = node.children.length; i < len; i++) {
@@ -396,11 +455,18 @@ class GLTFLoader {
396
455
  nodeDef.data.push(customData);
397
456
  }
398
457
  this._numberOfConvertedNodes++;
399
- if (performance.now() - this._progressTimer > this._progressUpdateLimit) {
458
+ if (performance.now() - this._progressTimer >
459
+ this._progressUpdateLimit) {
400
460
  this._progressTimer = performance.now();
401
- const eventProgress = { type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: (this._numberOfConvertedNodes / this._numberOfNodes) / 2 + 0.1, status: `GlTF conversion progress: ${this._numberOfConvertedNodes}/${this._numberOfNodes} nodes.` };
461
+ const eventProgress = {
462
+ type: viewer_shared_types_1.TASK_TYPE.GLTF_CONTENT_LOADING,
463
+ id: this._eventId,
464
+ progress: this._numberOfConvertedNodes / this._numberOfNodes / 2 +
465
+ 0.1,
466
+ status: `GlTF conversion progress: ${this._numberOfConvertedNodes}/${this._numberOfNodes} nodes.`,
467
+ };
402
468
  this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventProgress);
403
- yield new Promise(resolve => setTimeout(resolve, 0));
469
+ yield new Promise((resolve) => setTimeout(resolve, 0));
404
470
  }
405
471
  return nodeDef;
406
472
  });
@@ -408,16 +474,16 @@ class GLTFLoader {
408
474
  loadScene() {
409
475
  return __awaiter(this, void 0, void 0, function* () {
410
476
  if (!this._content.scenes)
411
- throw new Error('Scenes not available.');
477
+ throw new Error("Scenes not available.");
412
478
  const sceneId = this._content.scene || 0;
413
479
  if (!this._content.scenes[sceneId])
414
- throw new Error('Scene not available.');
480
+ throw new Error("Scene not available.");
415
481
  const scene = this._content.scenes[sceneId];
416
- const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name || 'scene_' + sceneId + '');
482
+ const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name || "scene_" + sceneId + "");
417
483
  sceneDef.originalName = scene.name;
418
484
  sceneDef.addTransformation({
419
485
  id: this._uuidGenerator.create(),
420
- matrix: this._globalTransformation
486
+ matrix: this._globalTransformation,
421
487
  });
422
488
  if (scene.nodes)
423
489
  for (let i = 0, len = scene.nodes.length; i < len; i++)
@@ -427,13 +493,13 @@ class GLTFLoader {
427
493
  }
428
494
  loadSkin(skinId) {
429
495
  if (!this._content.skins)
430
- throw new Error('Skins not available.');
496
+ throw new Error("Skins not available.");
431
497
  if (!this._content.skins[skinId])
432
- throw new Error('Skin not available.');
498
+ throw new Error("Skin not available.");
433
499
  const skinDef = this._content.skins[skinId];
434
500
  const skinEntry = {
435
501
  joints: skinDef.joints,
436
- inverseBindMatrices: null
502
+ inverseBindMatrices: null,
437
503
  };
438
504
  if (skinDef.inverseBindMatrices === undefined) {
439
505
  return skinEntry;
@@ -443,13 +509,15 @@ class GLTFLoader {
443
509
  }
444
510
  validateVersionAndExtensions() {
445
511
  if (!this._content.asset)
446
- throw new Error('Asset not available.');
512
+ throw new Error("Asset not available.");
447
513
  const asset = this._content.asset;
448
514
  if (!asset.version)
449
- throw new Error('Asset does not have a version.');
450
- const version = asset.minVersion ? asset.minVersion : asset.version;
451
- if (!version.startsWith('2'))
452
- throw new Error('Version of the glTF not supported.');
515
+ throw new Error("Asset does not have a version.");
516
+ const version = asset.minVersion
517
+ ? asset.minVersion
518
+ : asset.version;
519
+ if (!version.startsWith("2"))
520
+ throw new Error("Version of the glTF not supported.");
453
521
  if (this._content.extensionsUsed) {
454
522
  const notSupported = [];
455
523
  for (let i = 0; i < this._content.extensionsUsed.length; i++) {
@@ -457,12 +525,22 @@ class GLTFLoader {
457
525
  notSupported.push(this._content.extensionsUsed[i]);
458
526
  }
459
527
  if (notSupported.length > 0) {
460
- let message = 'Extension' + (notSupported.length === 1 ? ' ' : 's ');
528
+ let message = "Extension" + (notSupported.length === 1 ? " " : "s ");
461
529
  notSupported.forEach((element, index) => {
462
- message += '"' + element + '"' + (index === notSupported.length - 1 ? '' : index === notSupported.length - 2 ? ' and ' : ', ');
530
+ message +=
531
+ '"' +
532
+ element +
533
+ '"' +
534
+ (index === notSupported.length - 1
535
+ ? ""
536
+ : index === notSupported.length - 2
537
+ ? " and "
538
+ : ", ");
463
539
  });
464
- message += (notSupported.length === 1 ? ' is' : ' are') + ' not supported, but used. Loading glTF regardless.';
465
- this._logger.info('GLTFLoader.validateVersionAndExtensions: ' + message);
540
+ message +=
541
+ (notSupported.length === 1 ? " is" : " are") +
542
+ " not supported, but used. Loading glTF regardless.";
543
+ this._logger.info("GLTFLoader.validateVersionAndExtensions: " + message);
466
544
  }
467
545
  }
468
546
  if (this._content.extensionsRequired) {
@@ -472,11 +550,21 @@ class GLTFLoader {
472
550
  notSupported.push(this._content.extensionsRequired[i]);
473
551
  }
474
552
  if (notSupported.length > 0) {
475
- let message = 'Extension' + (notSupported.length === 1 ? ' ' : 's ');
553
+ let message = "Extension" + (notSupported.length === 1 ? " " : "s ");
476
554
  notSupported.forEach((element, index) => {
477
- message += '"' + element + '"' + (index === notSupported.length - 1 ? '' : index === notSupported.length - 2 ? ' and ' : ', ');
555
+ message +=
556
+ '"' +
557
+ element +
558
+ '"' +
559
+ (index === notSupported.length - 1
560
+ ? ""
561
+ : index === notSupported.length - 2
562
+ ? " and "
563
+ : ", ");
478
564
  });
479
- message += (notSupported.length === 1 ? ' is' : ' are') + ' not supported, but required. Aborting glTF loading.';
565
+ message +=
566
+ (notSupported.length === 1 ? " is" : " are") +
567
+ " not supported, but required. Aborting glTF loading.";
480
568
  throw new Error(message);
481
569
  }
482
570
  }