@shapediver/viewer.data-engine.geometry-engine 1.13.10 → 1.14.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 (38) hide show
  1. package/dist/GeometryEngine.d.ts.map +1 -1
  2. package/dist/GeometryEngine.js +1 -4
  3. package/dist/GeometryEngine.js.map +1 -1
  4. package/dist/gltfv1/GLTFLoader.js +1 -1
  5. package/dist/gltfv1/GLTFLoader.js.map +1 -1
  6. package/dist/gltfv2/GLTFLoader.d.ts +30 -20
  7. package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
  8. package/dist/gltfv2/GLTFLoader.js +300 -443
  9. package/dist/gltfv2/GLTFLoader.js.map +1 -1
  10. package/dist/gltfv2/draco/draco_decoder.d.ts +6 -0
  11. package/dist/gltfv2/draco/draco_decoder.d.ts.map +1 -0
  12. package/dist/gltfv2/draco/draco_decoder.js +54436 -0
  13. package/dist/gltfv2/draco/draco_decoder.js.map +1 -0
  14. package/dist/gltfv2/loaders/AccessorLoader.d.ts +14 -0
  15. package/dist/gltfv2/loaders/AccessorLoader.d.ts.map +1 -0
  16. package/dist/gltfv2/loaders/AccessorLoader.js +111 -0
  17. package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -0
  18. package/dist/gltfv2/loaders/BufferLoader.d.ts +12 -0
  19. package/dist/gltfv2/loaders/BufferLoader.d.ts.map +1 -0
  20. package/dist/gltfv2/loaders/BufferLoader.js +82 -0
  21. package/dist/gltfv2/loaders/BufferLoader.js.map +1 -0
  22. package/dist/gltfv2/loaders/BufferViewLoader.d.ts +11 -0
  23. package/dist/gltfv2/loaders/BufferViewLoader.d.ts.map +1 -0
  24. package/dist/gltfv2/loaders/BufferViewLoader.js +43 -0
  25. package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -0
  26. package/dist/gltfv2/loaders/GeometryLoader.d.ts +19 -0
  27. package/dist/gltfv2/loaders/GeometryLoader.d.ts.map +1 -0
  28. package/dist/gltfv2/loaders/GeometryLoader.js +172 -0
  29. package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -0
  30. package/dist/gltfv2/loaders/MaterialLoader.d.ts +15 -0
  31. package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -0
  32. package/dist/gltfv2/loaders/MaterialLoader.js +286 -0
  33. package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -0
  34. package/dist/gltfv2/loaders/TextureLoader.d.ts +15 -0
  35. package/dist/gltfv2/loaders/TextureLoader.d.ts.map +1 -0
  36. package/dist/gltfv2/loaders/TextureLoader.js +88 -0
  37. package/dist/gltfv2/loaders/TextureLoader.js.map +1 -0
  38. package/package.json +16 -9
@@ -13,37 +13,52 @@ exports.GLTFLoader = exports.GLTF_EXTENSIONS = void 0;
13
13
  const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
14
14
  const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
15
15
  const tsyringe_1 = require("tsyringe");
16
- const viewer_data_engine_shared_types_1 = require("@shapediver/viewer.data-engine.shared-types");
17
16
  const gl_matrix_1 = require("gl-matrix");
18
17
  const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
19
- const viewer_data_engine_material_engine_1 = require("@shapediver/viewer.data-engine.material-engine");
18
+ const viewer_rendering_engine_camera_engine_1 = require("@shapediver/viewer.rendering-engine.camera-engine");
19
+ const viewer_rendering_engine_light_engine_1 = require("@shapediver/viewer.rendering-engine.light-engine");
20
+ const BufferLoader_1 = require("./loaders/BufferLoader");
21
+ const BufferViewLoader_1 = require("./loaders/BufferViewLoader");
22
+ const AccessorLoader_1 = require("./loaders/AccessorLoader");
23
+ const TextureLoader_1 = require("./loaders/TextureLoader");
24
+ const MaterialLoader_1 = require("./loaders/MaterialLoader");
25
+ const GeometryLoader_1 = require("./loaders/GeometryLoader");
20
26
  var GLTF_EXTENSIONS;
21
27
  (function (GLTF_EXTENSIONS) {
22
28
  GLTF_EXTENSIONS["KHR_BINARY_GLTF"] = "KHR_binary_glTF";
29
+ GLTF_EXTENSIONS["KHR_DRACO_MESH_COMPRESSION"] = "KHR_draco_mesh_compression";
30
+ GLTF_EXTENSIONS["KHR_LIGHTS_PUNCTUAL"] = "KHR_lights_punctual";
31
+ GLTF_EXTENSIONS["KHR_MATERIALS_CLEARCOAT"] = "KHR_materials_clearcoat";
32
+ GLTF_EXTENSIONS["KHR_MATERIALS_IOR"] = "KHR_materials_ior";
23
33
  GLTF_EXTENSIONS["KHR_MATERIALS_PBRSPECULARGLOSSINESS"] = "KHR_materials_pbrSpecularGlossiness";
34
+ GLTF_EXTENSIONS["KHR_MATERIALS_SHEEN"] = "KHR_materials_sheen";
35
+ GLTF_EXTENSIONS["KHR_MATERIALS_SPECULAR"] = "KHR_materials_specular";
36
+ GLTF_EXTENSIONS["KHR_MATERIALS_TRANSMISSION"] = "KHR_materials_transmission";
24
37
  GLTF_EXTENSIONS["KHR_MATERIALS_UNLIT"] = "KHR_materials_unlit";
38
+ GLTF_EXTENSIONS["KHR_MATERIALS_VARIANTS"] = "KHR_materials_variants";
39
+ GLTF_EXTENSIONS["KHR_MATERIALS_VOLUME"] = "KHR_materials_volume";
40
+ GLTF_EXTENSIONS["KHR_MESH_QUANTIZATION"] = "KHR_mesh_quantization";
41
+ GLTF_EXTENSIONS["KHR_TEXTURE_TRANSFORM"] = "KHR_texture_transform";
25
42
  GLTF_EXTENSIONS["SHAPEDIVER_MATERIALS_PRESET"] = "SHAPEDIVER_materials_preset";
26
43
  })(GLTF_EXTENSIONS = exports.GLTF_EXTENSIONS || (exports.GLTF_EXTENSIONS = {}));
44
+ const DRACO = require('./draco/draco_decoder.js');
27
45
  class GLTFLoader {
28
46
  constructor() {
29
- // #region Properties (6)
47
+ // #region Properties (17)
30
48
  this.BINARY_EXTENSION_HEADER_LENGTH = 20;
49
+ this._converter = tsyringe_1.container.resolve(viewer_shared_services_1.Converter);
50
+ this._globalTransformation = gl_matrix_1.mat4.fromValues(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1);
31
51
  this._httpClient = tsyringe_1.container.resolve(viewer_shared_services_1.HttpClient);
32
- this._materialEngine = tsyringe_1.container.resolve(viewer_data_engine_material_engine_1.MaterialEngine);
33
- this._uuidGenerator = tsyringe_1.container.resolve(viewer_shared_services_1.UuidGenerator);
34
52
  this._logger = tsyringe_1.container.resolve(viewer_shared_services_1.Logger);
35
- this._globalTransformation = gl_matrix_1.mat4.fromValues(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1);
36
- this._converter = tsyringe_1.container.resolve(viewer_shared_services_1.Converter);
37
53
  this._performanceEvaluator = tsyringe_1.container.resolve(viewer_shared_services_1.PerformanceEvaluator);
38
- this._loaded = {};
39
- this._loadData = this._httpClient.loadData.bind(this._httpClient);
54
+ this._uuidGenerator = tsyringe_1.container.resolve(viewer_shared_services_1.UuidGenerator);
40
55
  this._nodes = {};
41
- // #endregion Private Methods (9)
56
+ // #endregion Private Methods (7)
42
57
  }
43
- // #endregion Properties (6)
44
- // #region Public Methods (1)
58
+ // #endregion Properties (17)
59
+ // #region Public Methods (2)
45
60
  load(content, gltfBinary, gltfHeader, baseUri) {
46
- var _a;
61
+ var _a, _b;
47
62
  return __awaiter(this, void 0, void 0, function* () {
48
63
  this._baseUri = baseUri;
49
64
  if (gltfBinary && gltfHeader)
@@ -51,10 +66,59 @@ class GLTFLoader {
51
66
  this._content = content;
52
67
  try {
53
68
  this.validateVersionAndExtensions();
54
- const node = yield this.loadScene();
69
+ const dracoModule = yield new DRACO();
70
+ this._bufferLoader = new BufferLoader_1.BufferLoader(this._content, this._body, this._baseUri);
71
+ yield this._bufferLoader.load();
72
+ this._bufferViewLoader = new BufferViewLoader_1.BufferViewLoader(this._content, this._bufferLoader);
73
+ this._bufferViewLoader.load();
74
+ this._accessorLoader = new AccessorLoader_1.AccessorLoader(this._content, this._bufferViewLoader);
75
+ this._accessorLoader.load();
76
+ this._textureLoader = new TextureLoader_1.TextureLoader(this._content, this._bufferViewLoader, this._baseUri);
77
+ yield this._textureLoader.load();
78
+ this._materialLoader = new MaterialLoader_1.MaterialLoader(this._content, this._textureLoader);
79
+ yield this._materialLoader.load();
80
+ this._geometryLoader = new GeometryLoader_1.GeometryLoader(this._content, this._accessorLoader, this._bufferViewLoader, this._materialLoader, dracoModule);
81
+ const node = this.loadScene();
82
+ if (this._content.extensions && this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
83
+ const variants = this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS].variants;
84
+ for (let i = 0; i < variants.length; i++)
85
+ this._geometryLoader.materialVariantsData.variants.push(variants[i].name);
86
+ this._geometryLoader.materialVariantsData.variantIndex = 0;
87
+ node.data.push(this._geometryLoader.materialVariantsData);
88
+ }
89
+ if (this._content.skins !== undefined && this._content.nodes !== undefined) {
90
+ for (let i = 0; i < ((_a = this._content.nodes) === null || _a === void 0 ? void 0 : _a.length); i++) {
91
+ if (this._content.nodes[i].skin !== undefined) {
92
+ const skinDef = this.loadSkin(this._content.nodes[i].skin);
93
+ const skinNode = this._nodes[i];
94
+ const bones = [];
95
+ const boneInverses = [];
96
+ for (let j = 0; j < skinDef.joints.length; j++) {
97
+ this._nodes[skinDef.joints[j]].bone = true;
98
+ bones.push(this._nodes[skinDef.joints[j]]);
99
+ let mat = gl_matrix_1.mat4.create();
100
+ if (skinDef.inverseBindMatrices !== undefined) {
101
+ const matricesArray = skinDef.inverseBindMatrices.array;
102
+ mat = gl_matrix_1.mat4.fromValues(matricesArray[j * 16 + 0], matricesArray[j * 16 + 1], matricesArray[j * 16 + 2], matricesArray[j * 16 + 3], matricesArray[j * 16 + 4], matricesArray[j * 16 + 5], matricesArray[j * 16 + 6], matricesArray[j * 16 + 7], matricesArray[j * 16 + 8], matricesArray[j * 16 + 9], matricesArray[j * 16 + 10], matricesArray[j * 16 + 11], matricesArray[j * 16 + 12], matricesArray[j * 16 + 13], matricesArray[j * 16 + 14], matricesArray[j * 16 + 15]);
103
+ }
104
+ boneInverses.push(mat);
105
+ }
106
+ const addBones = (node) => {
107
+ for (let j = 0; j < node.data.length; j++)
108
+ if (node.data[j] instanceof viewer_shared_types_1.GeometryData) {
109
+ node.data[j].bones = bones;
110
+ node.data[j].boneInverses = boneInverses;
111
+ }
112
+ for (let l = 0; l < node.children.length; l++)
113
+ addBones(node.children[l]);
114
+ };
115
+ addBones(skinNode);
116
+ }
117
+ }
118
+ }
55
119
  if (this._content.animations)
56
- for (let i = 0; i < ((_a = this._content.animations) === null || _a === void 0 ? void 0 : _a.length); i++)
57
- node.data.push(yield this.loadAnimation(i));
120
+ for (let i = 0; i < ((_b = this._content.animations) === null || _b === void 0 ? void 0 : _b.length); i++)
121
+ node.data.push(this.loadAnimation(i));
58
122
  return node;
59
123
  }
60
124
  catch (e) {
@@ -76,405 +140,263 @@ class GLTFLoader {
76
140
  catch (e) {
77
141
  throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `GLTFLoader.load`, e);
78
142
  }
143
+ let gltfContent, gltfBinary, gltfBaseUrl, gltfHeader;
79
144
  const magic = new TextDecoder().decode(new Uint8Array(axiosResponse.data, 0, 4));
80
145
  const isBinary = magic === 'glTF' || (axiosResponse.headers['content-type'] &&
81
146
  (axiosResponse.headers['content-type'] === 'model/gltf-binary' ||
82
147
  axiosResponse.headers['content-type'] === 'application/octet-stream' ||
83
148
  axiosResponse.headers['content-type'] === 'model/gltf.binary'));
84
149
  if (isBinary) {
85
- const binaryGeometry = axiosResponse.data;
150
+ gltfBinary = axiosResponse.data;
86
151
  // create header data
87
- const headerDataView = new DataView(binaryGeometry, 0, this.BINARY_EXTENSION_HEADER_LENGTH);
88
- const header = {
152
+ const headerDataView = new DataView(gltfBinary, 0, this.BINARY_EXTENSION_HEADER_LENGTH);
153
+ gltfHeader = {
89
154
  magic: magic,
90
155
  version: headerDataView.getUint32(4, true),
91
156
  length: headerDataView.getUint32(8, true),
92
157
  contentLength: headerDataView.getUint32(12, true),
93
158
  contentFormat: headerDataView.getUint32(16, true)
94
159
  };
95
- if (header.magic != 'glTF') {
160
+ if (gltfHeader.magic != 'glTF') {
96
161
  const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('GLTFLoader.load: Invalid data: sdgTF magic wrong.');
97
162
  throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `GLTFLoader.load`, error);
98
163
  }
99
164
  // create content
100
- const contentDataView = new DataView(binaryGeometry, this.BINARY_EXTENSION_HEADER_LENGTH, header.contentLength);
165
+ const contentDataView = new DataView(gltfBinary, this.BINARY_EXTENSION_HEADER_LENGTH, gltfHeader.contentLength);
101
166
  const contentDecoded = new TextDecoder().decode(contentDataView);
102
- this._content = JSON.parse(contentDecoded);
167
+ gltfContent = JSON.parse(contentDecoded);
103
168
  // create body
104
- this._body = binaryGeometry.slice(this.BINARY_EXTENSION_HEADER_LENGTH + header.contentLength + 8, header.length);
169
+ this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH + gltfHeader.contentLength + 8, gltfHeader.length);
105
170
  }
106
171
  else {
107
- this._content = JSON.parse(new TextDecoder().decode(axiosResponse.data));
172
+ gltfContent = JSON.parse(new TextDecoder().decode(axiosResponse.data));
108
173
  const removeLastDirectoryPartOf = (the_url) => {
109
174
  const dir_char = the_url.includes("/") ? "/" : "\\";
110
175
  const the_arr = the_url.split(dir_char);
111
176
  the_arr.pop();
112
177
  return the_arr.join(dir_char);
113
178
  };
114
- this._baseUri = removeLastDirectoryPartOf(url);
115
- if (!this._baseUri && window && window.location && window.location.href)
116
- this._baseUri = removeLastDirectoryPartOf(window.location.href);
117
- }
118
- try {
119
- this.validateVersionAndExtensions();
120
- const node = yield this.loadScene();
121
- this._performanceEvaluator.endSection('gltfProcessing.' + url);
122
- return node;
123
- }
124
- catch (e) {
125
- throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `GLTFLoader.load`, e);
126
- }
127
- });
128
- }
129
- // #endregion Public Methods (1)
130
- // #region Private Methods (9)
131
- loadAccessor(accessorId) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- if (!this._content.accessors)
134
- throw new Error('Accessors not available.');
135
- if (!this._content.accessors[accessorId])
136
- throw new Error('Accessor not available.');
137
- const accessor = this._content.accessors[accessorId];
138
- if (this._loaded['accessor'] && this._loaded['accessor'][accessorId])
139
- return this._loaded['accessor'][accessorId];
140
- if (accessor.bufferView === undefined) {
141
- // Ignore empty accessors, which may be used to declare runtime
142
- // information about attributes coming from another source (e.g. Draco
143
- // compression extension).
144
- return Promise.resolve(null);
145
- }
146
- const arrayBuffer = yield this.loadBufferView(accessor.bufferView);
147
- const itemSize = viewer_data_engine_shared_types_1.ACCESSORTYPE_V2[accessor.type];
148
- if (accessor.componentType === 5124)
149
- this._logger.warn(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, 'GLTFLoader.loadAccessor: The componentType for this accessor is 5124, which is not allowed. Trying to load it anyway.');
150
- const ArrayType = viewer_data_engine_shared_types_1.ACCESSORCOMPONENTTYPE_V2[accessor.componentType];
151
- const elementBytes = ArrayType.BYTES_PER_ELEMENT;
152
- const itemBytes = elementBytes * itemSize;
153
- const byteOffset = accessor.byteOffset || 0;
154
- const byteStride = accessor.bufferView !== undefined ? this._content.bufferViews ? this._content.bufferViews[accessor.bufferView].byteStride : undefined : undefined;
155
- const normalized = accessor.normalized === true;
156
- let array;
157
- if (byteStride && byteStride !== itemBytes) {
158
- // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
159
- // This makes sure that IBA.count reflects accessor.count properly
160
- const ibSlice = Math.floor(byteOffset / byteStride);
161
- array = new ArrayType(arrayBuffer, ibSlice * byteStride, accessor.count * byteStride / elementBytes);
162
- }
163
- else {
164
- if (arrayBuffer === null) {
165
- array = new ArrayType(accessor.count * itemSize);
166
- }
167
- else {
168
- array = new ArrayType(arrayBuffer, byteOffset, accessor.count * itemSize);
169
- }
179
+ gltfBaseUrl = removeLastDirectoryPartOf(url);
180
+ if (!gltfBaseUrl && window && window.location && window.location.href)
181
+ gltfBaseUrl = removeLastDirectoryPartOf(window.location.href);
170
182
  }
171
- if (accessor.sparse !== undefined) {
172
- const itemSizeIndices = viewer_data_engine_shared_types_1.ACCESSORTYPE_V2.SCALAR;
173
- const IndicesArrayType = viewer_data_engine_shared_types_1.ACCESSORCOMPONENTTYPE_V2[accessor.sparse.indices.componentType];
174
- const byteOffsetIndices = accessor.sparse.indices.byteOffset || 0;
175
- const byteOffsetValues = accessor.sparse.values.byteOffset || 0;
176
- if (!accessor.sparse.indices.bufferView || !accessor.sparse.values.bufferView)
177
- throw new Error('Sparse Mesh not properly defined.');
178
- const sparseIndices = new IndicesArrayType(yield this.loadBufferView(accessor.sparse.indices.bufferView), byteOffsetIndices, accessor.sparse.count * itemSizeIndices);
179
- const sparseValues = new ArrayType(yield this.loadBufferView(accessor.sparse.values.bufferView), byteOffsetValues, accessor.sparse.count * itemSize);
180
- if (!this._loaded['accessor'])
181
- this._loaded['accessor'] = {};
182
- this._loaded['accessor'][accessorId] = new viewer_shared_types_1.AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride, true, sparseIndices, sparseValues);
183
- return this._loaded['accessor'][accessorId];
184
- }
185
- if (!this._loaded['accessor'])
186
- this._loaded['accessor'] = {};
187
- this._loaded['accessor'][accessorId] = new viewer_shared_types_1.AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride);
188
- return this._loaded['accessor'][accessorId];
183
+ return yield this.load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl);
189
184
  });
190
185
  }
191
- loadBuffer(bufferId) {
192
- return __awaiter(this, void 0, void 0, function* () {
193
- if (!this._content.buffers)
194
- throw new Error('Buffers not available.');
195
- if (!this._content.buffers[bufferId])
196
- throw new Error('Buffer not available.');
197
- const buffer = this._content.buffers[bufferId];
198
- if (this._loaded['buffer'] && this._loaded['buffer'][bufferId])
199
- return this._loaded['buffer'][bufferId];
200
- if (buffer.type && buffer.type !== 'arraybuffer') {
201
- throw new Error(`GLTFLoader.loadBuffer: ${buffer.type} is not supported.`);
202
- }
203
- // If present, GLB container is required to be the first buffer.
204
- if (buffer.uri === undefined && bufferId === 0) {
205
- if (!this._body)
206
- throw new Error(`GLTFLoader.loadBuffer: Buffer not available.`);
207
- return Promise.resolve(this._body);
208
- }
209
- const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
210
- const dataUriRegexResult = buffer.uri.match(dataUriRegex);
211
- let result;
212
- // Safari can not handle Data URIs through XMLHttpRequest so process manually
213
- if (dataUriRegexResult) {
214
- const isBase64 = !!dataUriRegexResult[2];
215
- let data = dataUriRegexResult[3];
216
- data = decodeURIComponent(data);
217
- if (isBase64)
218
- data = atob(data);
219
- const view = new Uint8Array(data.length);
220
- for (let i = 0; i < data.length; i++) {
221
- view[i] = data.charCodeAt(i);
222
- }
223
- result = view.buffer;
224
- }
225
- else {
226
- let httpResult = yield this._httpClient.get(this._baseUri + '/' + buffer.uri, {
227
- responseType: 'arraybuffer'
228
- });
229
- result = (httpResult.data);
230
- }
231
- if (!this._loaded['buffer'])
232
- this._loaded['buffer'] = {};
233
- this._loaded['buffer'][bufferId] = result;
234
- return this._loaded['buffer'][bufferId];
235
- });
236
- }
237
- loadBufferView(bufferViewId) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- if (!this._content.bufferViews)
240
- throw new Error('BufferViews not available.');
241
- if (!this._content.bufferViews[bufferViewId])
242
- throw new Error('BufferView not available.');
243
- const bufferView = this._content.bufferViews[bufferViewId];
244
- if (this._loaded['bufferView'] && this._loaded['bufferView'][bufferViewId])
245
- return this._loaded['bufferView'][bufferViewId];
246
- const byteLength = bufferView.byteLength || 0;
247
- const byteOffset = bufferView.byteOffset || 0;
248
- if (bufferView.buffer === undefined)
249
- throw new Error('BufferView has no buffer defined.');
250
- const buffer = yield this.loadBuffer(bufferView.buffer);
251
- const result = buffer.slice(byteOffset, byteOffset + byteLength);
252
- if (!this._loaded['bufferView'])
253
- this._loaded['bufferView'] = {};
254
- this._loaded['bufferView'][bufferViewId] = result;
255
- return this._loaded['bufferView'][bufferViewId];
256
- });
257
- }
258
- loadMap(textureId) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- if (!this._content.textures)
261
- throw new Error('Textures not available.');
262
- const texture = this._content.textures[textureId];
263
- if (this._loaded['texture'] && this._loaded['texture'][textureId])
264
- return this._loaded['texture'][textureId].clone();
265
- if (!this._content.images)
266
- throw new Error('Images not available.');
267
- const image = this._content.images[texture.source];
268
- const sampler = this._content.samplers && texture.sampler && this._content.samplers[texture.sampler] ? this._content.samplers[texture.sampler] : {};
269
- const DATA_URI_REGEX = /^data:(.*?)(;base64)?,(.*)$/;
270
- const HTTPS_URI_REGEX = /^https:\/\//;
271
- let mapData;
272
- if (image.bufferView !== undefined) {
273
- const bufferView = yield this.loadBufferView(image.bufferView);
274
- const dataView = new DataView(bufferView);
275
- const array = [];
276
- for (let i = 0; i < dataView.byteLength; i += 1)
277
- array[i] = dataView.getUint8(i);
278
- const blob = new Blob([new Uint8Array(array)], { type: image.mimeType });
279
- const dataUri = window.URL.createObjectURL(blob);
280
- mapData = new viewer_shared_types_1.MapData(yield this._converter.responseToImage(yield this._loadData(dataUri)), sampler.wrapS, sampler.wrapT, sampler.minFilter, sampler.magFilter, undefined, undefined, undefined, undefined, undefined, false);
281
- }
282
- else {
283
- const url = DATA_URI_REGEX.test(image.uri) || HTTPS_URI_REGEX.test(image.uri) ? image.uri : `${this._baseUri}/${image.uri}`;
284
- mapData = new viewer_shared_types_1.MapData(yield this._converter.responseToImage(yield this._loadData(url)), sampler.wrapS, sampler.wrapT, sampler.minFilter, sampler.magFilter, undefined, undefined, undefined, undefined, undefined, false);
285
- }
286
- if (!this._loaded['texture'])
287
- this._loaded['texture'] = {};
288
- this._loaded['texture'][textureId] = mapData;
289
- return this._loaded['texture'][textureId].clone();
290
- });
186
+ // #endregion Public Methods (2)
187
+ // #region Private Methods (7)
188
+ /**
189
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
190
+ * @param {number} animationIndex
191
+ * @return {Promise<AnimationClip>}
192
+ */
193
+ loadAnimation(animationId) {
194
+ if (!this._content.animations)
195
+ throw new Error('Animations not available.');
196
+ if (!this._content.animations[animationId])
197
+ throw new Error('Animations not available.');
198
+ const animationDef = this._content.animations[animationId];
199
+ const animationTracks = [];
200
+ let min = Infinity, max = -Infinity;
201
+ for (let i = 0; i < animationDef.channels.length; i++) {
202
+ const channel = animationDef.channels[i];
203
+ const sampler = animationDef.samplers[channel.sampler];
204
+ const target = channel.target;
205
+ const path = target.path;
206
+ const node = this._nodes[target.node];
207
+ if (node === undefined)
208
+ throw new Error('Animation node not available.');
209
+ const input = this._accessorLoader.getAccessor(sampler.input);
210
+ min = Math.min(min, input.min[0]);
211
+ max = Math.max(max, input.max[0]);
212
+ const output = this._accessorLoader.getAccessor(sampler.output);
213
+ let interpolation = sampler.interpolation;
214
+ if (interpolation === 'CUBICSPLINE') {
215
+ this._logger.warn(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, 'Animation with CUBICSPLINE interpolation is currently not supported. Assigning linear interpolation instead.');
216
+ interpolation = 'linear';
217
+ }
218
+ animationTracks.push({
219
+ node,
220
+ times: input.array,
221
+ values: output.array,
222
+ path: path,
223
+ interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase()
224
+ });
225
+ }
226
+ return new viewer_shared_types_1.AnimationData(animationDef.name || 'gltf_animation_' + animationId, animationTracks, min, max - min);
291
227
  }
292
- loadMaterial(materialId) {
293
- return __awaiter(this, void 0, void 0, function* () {
294
- if (!this._content.materials)
295
- throw new Error('Materials not available.');
296
- const material = this._content.materials[materialId];
297
- const materialData = new viewer_shared_types_1.MaterialData();
298
- if (material.name !== undefined)
299
- materialData.name = material.name;
300
- if (material.extensions && material.extensions.SHAPEDIVER_materials_preset) {
301
- const materialPreset = material.extensions.SHAPEDIVER_materials_preset;
302
- yield this._materialEngine.loadPresetMaterial(materialPreset.materialpreset, materialData);
303
- materialData.color = this._converter.toColor(materialPreset.color);
304
- return materialData;
305
- }
306
- if (material.extensions && material.extensions.KHR_materials_pbrSpecularGlossiness) {
307
- const pbrSpecularGlossiness = material.extensions.KHR_materials_pbrSpecularGlossiness;
308
- materialData.KHR_materials_pbrSpecularGlossiness = true;
309
- materialData.color = '#ffffff';
310
- materialData.opacity = 1.0;
311
- if (pbrSpecularGlossiness.diffuseFactor !== undefined) {
312
- materialData.color = this._converter.toColor([pbrSpecularGlossiness.diffuseFactor[0] * 255, pbrSpecularGlossiness.diffuseFactor[1] * 255, pbrSpecularGlossiness.diffuseFactor[2] * 255]);
313
- materialData.opacity = pbrSpecularGlossiness.diffuseFactor[3];
314
- }
315
- if (pbrSpecularGlossiness.diffuseTexture !== undefined)
316
- materialData.map = yield this.loadMap(pbrSpecularGlossiness.diffuseTexture.index);
317
- materialData.emissiveness = '#000000';
318
- materialData.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
319
- materialData.specular = '#ffffff';
320
- if (pbrSpecularGlossiness.specularFactor !== undefined) {
321
- materialData.specular = this._converter.toColor([pbrSpecularGlossiness.specularFactor[0] * 255, pbrSpecularGlossiness.specularFactor[1] * 255, pbrSpecularGlossiness.specularFactor[2] * 255]);
322
- }
323
- if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
324
- materialData.specularGlossinessMap = yield this.loadMap(pbrSpecularGlossiness.specularGlossinessTexture.index);
325
- }
326
- }
327
- else if (material.extensions && material.extensions.KHR_materials_unlit) {
328
- materialData.KHR_materials_unlit = true;
329
- materialData.color = '#ffffff';
330
- materialData.opacity = 1.0;
331
- if (material.pbrMetallicRoughness !== undefined) {
332
- if (material.pbrMetallicRoughness.baseColorFactor !== undefined) {
333
- materialData.color = this._converter.toColor([material.pbrMetallicRoughness.baseColorFactor[0] * 255, material.pbrMetallicRoughness.baseColorFactor[1] * 255, material.pbrMetallicRoughness.baseColorFactor[2] * 255]);
334
- materialData.opacity = material.pbrMetallicRoughness.baseColorFactor[3];
335
- }
336
- if (material.pbrMetallicRoughness.baseColorTexture !== undefined) {
337
- materialData.map = yield this.loadMap(material.pbrMetallicRoughness.baseColorTexture.index);
338
- }
339
- }
340
- }
341
- else {
342
- if (material.pbrMetallicRoughness !== undefined) {
343
- materialData.color = '#ffffff';
344
- if (material.pbrMetallicRoughness.baseColorFactor !== undefined) {
345
- materialData.color = this._converter.toColor([material.pbrMetallicRoughness.baseColorFactor[0] * 255, material.pbrMetallicRoughness.baseColorFactor[1] * 255, material.pbrMetallicRoughness.baseColorFactor[2] * 255]);
346
- materialData.opacity = material.pbrMetallicRoughness.baseColorFactor[3];
347
- }
348
- if (material.pbrMetallicRoughness.baseColorTexture !== undefined) {
349
- materialData.map = yield this.loadMap(material.pbrMetallicRoughness.baseColorTexture.index);
350
- }
351
- if (material.pbrMetallicRoughness.metallicFactor !== undefined) {
352
- materialData.metalness = material.pbrMetallicRoughness.metallicFactor;
353
- }
354
- if (material.pbrMetallicRoughness.roughnessFactor !== undefined) {
355
- materialData.roughness = material.pbrMetallicRoughness.roughnessFactor;
356
- }
357
- if (material.pbrMetallicRoughness.metallicRoughnessTexture !== undefined) {
358
- materialData.metalnessRoughnessMap = yield this.loadMap(material.pbrMetallicRoughness.metallicRoughnessTexture.index);
359
- }
360
- }
361
- }
362
- if (material.normalTexture !== undefined) {
363
- materialData.normalMap = yield this.loadMap(material.normalTexture.index);
364
- materialData.normalScale = 1;
365
- if (material.normalTexture.scale !== undefined) {
366
- materialData.normalScale = material.normalTexture.scale;
367
- }
368
- }
369
- if (material.occlusionTexture !== undefined) {
370
- materialData.aoMap = yield this.loadMap(material.occlusionTexture.index);
371
- if (material.occlusionTexture.strength !== undefined) {
372
- materialData.aoMapIntensity = material.occlusionTexture.strength;
373
- }
374
- }
375
- if (material.emissiveTexture !== undefined) {
376
- materialData.emissiveMap = yield this.loadMap(material.emissiveTexture.index);
377
- }
378
- if (material.emissiveFactor !== undefined) {
379
- materialData.emissiveness = this._converter.toColor([material.emissiveFactor[0] * 255, material.emissiveFactor[1] * 255, material.emissiveFactor[2] * 255]);
380
- }
381
- if (material.alphaMode !== undefined) {
382
- materialData.alphaMode = material.alphaMode.toLowerCase() === viewer_shared_types_1.MATERIAL_ALPHA.MASK ? viewer_shared_types_1.MATERIAL_ALPHA.MASK : material.alphaMode.toLowerCase() === viewer_shared_types_1.MATERIAL_ALPHA.BLEND ? viewer_shared_types_1.MATERIAL_ALPHA.BLEND : viewer_shared_types_1.MATERIAL_ALPHA.OPAQUE;
383
- if (materialData.alphaMode === viewer_shared_types_1.MATERIAL_ALPHA.MASK) {
384
- materialData.alphaCutoff = material.alphaCutoff !== undefined ? material.alphaCutoff : 0.5;
385
- }
386
- }
387
- if (material.alphaCutoff !== undefined) {
388
- materialData.alphaCutoff = material.alphaCutoff;
389
- }
390
- if (material.doubleSided !== undefined) {
391
- materialData.side = material.doubleSided ? viewer_shared_types_1.MATERIAL_SIDE.DOUBLE : viewer_shared_types_1.MATERIAL_SIDE.FRONT;
392
- }
393
- return materialData;
394
- });
228
+ loadCamera(cameraId) {
229
+ if (!this._content.cameras)
230
+ throw new Error('Cameras not available.');
231
+ if (!this._content.cameras[cameraId])
232
+ throw new Error('Cameras not available.');
233
+ const cameraDef = this._content.cameras[cameraId];
234
+ const cameraNode = new viewer_shared_node_tree_1.TreeNode(cameraDef.name || 'camera_' + cameraId);
235
+ let cameraData;
236
+ if (cameraDef.type === 'perspective') {
237
+ const perspectiveCameraDef = cameraDef.perspective;
238
+ cameraData = new viewer_rendering_engine_camera_engine_1.PerspectiveCamera(cameraNode.id);
239
+ cameraNode.data.push(cameraData);
240
+ cameraData.fov = perspectiveCameraDef.yfov * (180 / Math.PI);
241
+ cameraData.aspect = perspectiveCameraDef.aspectRatio || 1;
242
+ cameraData.near = perspectiveCameraDef.znear || 1;
243
+ cameraData.far = perspectiveCameraDef.zfar || 2e6;
244
+ }
245
+ else {
246
+ const orthographicCameraDef = cameraDef.orthographic;
247
+ cameraData = new viewer_rendering_engine_camera_engine_1.OrthographicCamera(cameraNode.id);
248
+ cameraNode.data.push(cameraData);
249
+ cameraData.left = -orthographicCameraDef.xmag;
250
+ cameraData.right = orthographicCameraDef.xmag;
251
+ cameraData.top = -orthographicCameraDef.ymag;
252
+ cameraData.bottom = orthographicCameraDef.ymag;
253
+ cameraData.near = orthographicCameraDef.znear || 1;
254
+ cameraData.far = orthographicCameraDef.zfar || 2e6;
255
+ }
256
+ cameraData.useNodeData = true;
257
+ cameraData.node = cameraNode;
258
+ return cameraNode;
395
259
  }
396
- loadMesh(meshId) {
397
- return __awaiter(this, void 0, void 0, function* () {
398
- if (!this._content.meshes)
399
- throw new Error('Meshes not available.');
400
- if (!this._content.meshes[meshId])
401
- throw new Error('Mesh not available.');
402
- const mesh = this._content.meshes[meshId];
403
- const meshNode = new viewer_shared_node_tree_1.TreeNode(mesh.name || 'mesh_' + meshId);
404
- if (mesh.primitives)
405
- for (let i = 0, len = mesh.primitives.length; i < len; i++)
406
- meshNode.addChild(yield this.loadPrimitive(mesh.primitives, i));
407
- // weights https://shapediver.atlassian.net/browse/SS-2944
408
- return meshNode;
409
- });
260
+ loadLights(lightId) {
261
+ if (!this._content.extensions || !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL] || !this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights)
262
+ throw new Error(`Extension ${GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL} not available.`);
263
+ if (!this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights[lightId])
264
+ throw new Error('Light not available.');
265
+ const lightDef = this._content.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].lights[lightId];
266
+ const lightNode = new viewer_shared_node_tree_1.TreeNode(lightDef.name || 'light_' + lightId);
267
+ let color = '#ffffffff';
268
+ if (lightDef.color !== undefined)
269
+ color = this._converter.toColor([lightDef.color[0] * 255, lightDef.color[1] * 255, lightDef.color[2] * 255]);
270
+ const range = lightDef.range !== undefined ? lightDef.range : 0;
271
+ let lightData;
272
+ if (lightDef.type === 'directional') {
273
+ lightData = new viewer_rendering_engine_light_engine_1.DirectionalLight({ color });
274
+ lightNode.data.push(lightData);
275
+ const directionalLightData = lightData;
276
+ if (lightDef.intensity !== undefined)
277
+ directionalLightData.intensity = lightDef.intensity;
278
+ }
279
+ else if (lightDef.type === 'point') {
280
+ lightData = new viewer_rendering_engine_light_engine_1.PointLight({ color });
281
+ lightNode.data.push(lightData);
282
+ const pointLightData = lightData;
283
+ pointLightData.distance = range;
284
+ pointLightData.decay = 2;
285
+ if (lightDef.intensity !== undefined)
286
+ lightData.intensity = lightDef.intensity;
287
+ pointLightData.position = [0, 0, 0];
288
+ }
289
+ else if (lightDef.type === 'spot') {
290
+ lightData = new viewer_rendering_engine_light_engine_1.SpotLight({ color });
291
+ lightNode.data.push(lightData);
292
+ lightDef.spot = lightDef.spot || {};
293
+ lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
294
+ lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
295
+ const spotLightData = lightData;
296
+ spotLightData.distance = range;
297
+ spotLightData.angle = lightDef.spot.outerConeAngle;
298
+ spotLightData.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
299
+ spotLightData.decay = 2;
300
+ if (lightDef.intensity !== undefined)
301
+ lightData.intensity = lightDef.intensity;
302
+ spotLightData.position = [0, 0, 0];
303
+ spotLightData.target = [0, 0, -1];
304
+ }
305
+ else {
306
+ throw new Error('Unexpected light type: ' + lightDef.type);
307
+ }
308
+ lightData.useNodeData = true;
309
+ return lightNode;
410
310
  }
411
311
  loadNode(nodeId) {
412
- return __awaiter(this, void 0, void 0, function* () {
413
- if (!this._content.nodes)
414
- throw new Error('Nodes not available.');
415
- if (!this._content.nodes[nodeId])
416
- throw new Error('Node not available.');
417
- const node = this._content.nodes[nodeId];
418
- const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || 'node_' + nodeId);
419
- this._nodes[nodeId] = nodeDef;
420
- if (node.matrix) {
421
- nodeDef.transformations.push({
422
- id: 'gltf_matrix',
423
- 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])
424
- });
425
- }
426
- else if (node.translation || node.scale || node.rotation) {
427
- 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();
428
- 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();
429
- 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();
430
- const matrix = gl_matrix_1.mat4.mul(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.mul(gl_matrix_1.mat4.create(), matT, matR), matS);
431
- nodeDef.transformations.push({
432
- id: 'gltf_matrix',
433
- matrix: matrix
434
- });
435
- }
436
- if (node.mesh !== undefined)
437
- nodeDef.addChild(yield this.loadMesh(node.mesh));
438
- if (node.children) {
439
- for (let i = 0, len = node.children.length; i < len; i++) {
440
- // got through all children
441
- nodeDef.addChild(yield this.loadNode(node.children[i]));
442
- }
312
+ if (!this._content.nodes)
313
+ throw new Error('Nodes not available.');
314
+ if (!this._content.nodes[nodeId])
315
+ throw new Error('Node not available.');
316
+ const node = this._content.nodes[nodeId];
317
+ const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || 'node_' + nodeId);
318
+ this._nodes[nodeId] = nodeDef;
319
+ if (node.matrix) {
320
+ nodeDef.transformations.push({
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])
323
+ });
324
+ nodeDef.transformations.push({
325
+ id: 'gltf_matrix_translation',
326
+ matrix: gl_matrix_1.mat4.create()
327
+ });
328
+ nodeDef.transformations.push({
329
+ id: 'gltf_matrix_rotation',
330
+ matrix: gl_matrix_1.mat4.create()
331
+ });
332
+ nodeDef.transformations.push({
333
+ id: 'gltf_matrix_scale',
334
+ matrix: gl_matrix_1.mat4.create()
335
+ });
336
+ }
337
+ 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();
341
+ nodeDef.transformations.push({
342
+ id: 'gltf_matrix_translation',
343
+ matrix: matT
344
+ });
345
+ nodeDef.transformations.push({
346
+ id: 'gltf_matrix_rotation',
347
+ matrix: matR
348
+ });
349
+ nodeDef.transformations.push({
350
+ id: 'gltf_matrix_scale',
351
+ matrix: matS
352
+ });
353
+ }
354
+ if (node.mesh !== undefined)
355
+ nodeDef.addChild(this._geometryLoader.loadMesh(node.mesh, node.weights));
356
+ if (node.camera !== undefined)
357
+ nodeDef.addChild(this.loadCamera(node.camera));
358
+ if (node.extensions && node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL])
359
+ nodeDef.addChild(this.loadLights(node.extensions[GLTF_EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light));
360
+ if (node.children) {
361
+ for (let i = 0, len = node.children.length; i < len; i++) {
362
+ // got through all children
363
+ nodeDef.addChild(this.loadNode(node.children[i]));
443
364
  }
444
- // camera, skin, weights https://shapediver.atlassian.net/browse/SS-2944
445
- return nodeDef;
446
- });
365
+ }
366
+ return nodeDef;
447
367
  }
448
- loadPrimitive(primitives, index) {
449
- return __awaiter(this, void 0, void 0, function* () {
450
- const primitive = primitives[index];
451
- const primitiveNode = new viewer_shared_node_tree_1.TreeNode('primitive_' + index);
452
- const attributes = {};
453
- for (let attribute in primitive.attributes) {
454
- // attribute name conversion to be consistent witg gltf
455
- let attributeName = attribute;
456
- if (/\d/.test(attributeName) && !attributeName.includes('_')) {
457
- const index = attributeName.search(/\d/);
458
- attributeName = attributeName.substring(0, index) + '_' + attributeName.substring(index, attributeName.length);
459
- }
460
- else if (attributeName === 'TEXCOORD' || attributeName === 'COLOR' || attributeName === 'JOINTS' || attributeName === 'WEIGHTS') {
461
- attributeName += '_0';
462
- }
463
- else if (attributeName === 'UV') {
464
- attributeName = 'TEXCOORD_0';
465
- }
466
- attributes[attributeName] = (yield this.loadAccessor(primitive.attributes[attribute]));
467
- }
468
- let indices = null;
469
- if (primitive.indices || primitive.indices === 0)
470
- indices = yield this.loadAccessor(primitive.indices);
471
- let material = null;
472
- if (primitive.material || primitive.material === 0)
473
- material = yield this.loadMaterial(primitive.material);
474
- primitiveNode.data.push(new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, primitive.mode, indices, material)));
475
- // targets https://shapediver.atlassian.net/browse/SS-2944
476
- return primitiveNode;
368
+ loadScene() {
369
+ if (!this._content.scenes)
370
+ throw new Error('Scenes not available.');
371
+ const sceneID = this._content.scene || 0;
372
+ if (!this._content.scenes[sceneID])
373
+ throw new Error('Scene not available.');
374
+ const scene = this._content.scenes[sceneID];
375
+ const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name || 'scene_' + sceneID + '');
376
+ sceneDef.transformations.push({
377
+ id: this._uuidGenerator.create(),
378
+ matrix: this._globalTransformation
477
379
  });
380
+ if (scene.nodes)
381
+ for (let i = 0, len = scene.nodes.length; i < len; i++)
382
+ sceneDef.addChild(this.loadNode(scene.nodes[i]));
383
+ return sceneDef;
384
+ }
385
+ loadSkin(skinId) {
386
+ if (!this._content.skins)
387
+ throw new Error('Skins not available.');
388
+ if (!this._content.skins[skinId])
389
+ throw new Error('Skin not available.');
390
+ const skinDef = this._content.skins[skinId];
391
+ const skinEntry = {
392
+ joints: skinDef.joints,
393
+ inverseBindMatrices: null
394
+ };
395
+ if (skinDef.inverseBindMatrices === undefined) {
396
+ return skinEntry;
397
+ }
398
+ skinEntry.inverseBindMatrices = this._accessorLoader.getAccessor(skinDef.inverseBindMatrices);
399
+ return skinEntry;
478
400
  }
479
401
  validateVersionAndExtensions() {
480
402
  if (!this._content.asset)
@@ -516,71 +438,6 @@ class GLTFLoader {
516
438
  }
517
439
  }
518
440
  }
519
- loadScene() {
520
- return __awaiter(this, void 0, void 0, function* () {
521
- if (!this._content.scenes)
522
- throw new Error('Scenes not available.');
523
- const sceneID = this._content.scene || 0;
524
- if (!this._content.scenes[sceneID])
525
- throw new Error('Scene not available.');
526
- const scene = this._content.scenes[sceneID];
527
- const sceneDef = new viewer_shared_node_tree_1.TreeNode(scene.name || 'scene_' + sceneID + '');
528
- sceneDef.transformations.push({
529
- id: this._uuidGenerator.create(),
530
- matrix: this._globalTransformation
531
- });
532
- if (scene.nodes)
533
- for (let i = 0, len = scene.nodes.length; i < len; i++)
534
- sceneDef.addChild(yield this.loadNode(scene.nodes[i]));
535
- return sceneDef;
536
- });
537
- }
538
- /**
539
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
540
- * @param {number} animationIndex
541
- * @return {Promise<AnimationClip>}
542
- */
543
- loadAnimation(animationId) {
544
- return __awaiter(this, void 0, void 0, function* () {
545
- if (!this._content.animations)
546
- throw new Error('Animations not available.');
547
- if (!this._content.animations[animationId])
548
- throw new Error('Animations not available.');
549
- const animationDef = this._content.animations[animationId];
550
- const animationTracks = [];
551
- let min = Infinity, max = -Infinity;
552
- for (let i = 0; i < animationDef.channels.length; i++) {
553
- const channel = animationDef.channels[i];
554
- const sampler = animationDef.samplers[channel.sampler];
555
- const target = channel.target;
556
- const path = target.path;
557
- const node = this._nodes[target.node];
558
- if (node === undefined)
559
- throw new Error('Animation node not available.');
560
- const input = yield this.loadAccessor(sampler.input);
561
- min = Math.min(min, input.min[0]);
562
- max = Math.max(max, input.max[0]);
563
- const output = yield this.loadAccessor(sampler.output);
564
- let interpolation = sampler.interpolation;
565
- if (interpolation === 'CUBICSPLINE') {
566
- this._logger.warn(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, 'Animation with CUBICSPLINE interpolation is currently not supported. Assigning linear interpolation instead.');
567
- interpolation = 'linear';
568
- }
569
- if (target.path === 'weights') {
570
- this._logger.warn(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, 'Animation with weights is currently not supported.');
571
- break;
572
- }
573
- animationTracks.push({
574
- node,
575
- times: input.array,
576
- values: output.array,
577
- path: path,
578
- interpolation: interpolation === null || interpolation === void 0 ? void 0 : interpolation.toLowerCase()
579
- });
580
- }
581
- return new viewer_shared_types_1.AnimationData(animationDef.name || 'gltf_animation_' + animationId, animationTracks, min, max - min);
582
- });
583
- }
584
441
  }
585
442
  exports.GLTFLoader = GLTFLoader;
586
443
  //# sourceMappingURL=GLTFLoader.js.map