@shapediver/viewer.data-engine.geometry-engine 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/GeometryEngine.d.ts.map +1 -1
  2. package/dist/GeometryEngine.js +18 -14
  3. package/dist/GeometryEngine.js.map +1 -1
  4. package/dist/gltfv1/GLTFLoader.d.ts.map +1 -1
  5. package/dist/gltfv1/GLTFLoader.js +53 -49
  6. package/dist/gltfv1/GLTFLoader.js.map +1 -1
  7. package/dist/gltfv1/SDGTFLoader.js +98 -94
  8. package/dist/gltfv1/SDGTFLoader.js.map +1 -1
  9. package/dist/gltfv2/GLTFLoader.d.ts +2 -2
  10. package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
  11. package/dist/gltfv2/GLTFLoader.js +67 -63
  12. package/dist/gltfv2/GLTFLoader.js.map +1 -1
  13. package/dist/gltfv2/loaders/AccessorLoader.js +15 -11
  14. package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
  15. package/dist/gltfv2/loaders/BufferLoader.d.ts.map +1 -1
  16. package/dist/gltfv2/loaders/BufferLoader.js +10 -6
  17. package/dist/gltfv2/loaders/BufferLoader.js.map +1 -1
  18. package/dist/gltfv2/loaders/BufferViewLoader.js +5 -1
  19. package/dist/gltfv2/loaders/BufferViewLoader.js.map +1 -1
  20. package/dist/gltfv2/loaders/GeometryLoader.js +19 -15
  21. package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
  22. package/dist/gltfv2/loaders/MaterialLoader.js +55 -51
  23. package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
  24. package/dist/gltfv2/loaders/TextureLoader.d.ts.map +1 -1
  25. package/dist/gltfv2/loaders/TextureLoader.js +20 -18
  26. package/dist/gltfv2/loaders/TextureLoader.js.map +1 -1
  27. package/dist/index.js +5 -2
  28. package/dist/index.js.map +1 -1
  29. package/package.json +10 -10
  30. package/src/GeometryEngine.ts +29 -29
  31. package/src/gltfv1/GLTFLoader.ts +31 -31
  32. package/src/gltfv2/GLTFLoader.ts +66 -66
  33. package/src/gltfv2/loaders/BufferLoader.ts +10 -10
  34. package/src/gltfv2/loaders/TextureLoader.ts +24 -25
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,16 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { TreeNode } from '@shapediver/viewer.shared.node-tree';
11
- import { Logger, ShapeDiverViewerDataProcessingError } from '@shapediver/viewer.shared.services';
12
- import { ACCESSORCOMPONENTTYPE_V1 as ACCESSOR_COMPONENTTYPE, ACCESSORTYPE_V1 as ACCESSORTYPE, } from '@shapediver/viewer.data-engine.shared-types';
13
- import { AttributeData, GeometryData, PRIMITIVE_MODE, PrimitiveData, } from '@shapediver/viewer.shared.types';
14
- import { mat4, vec3, vec4 } from 'gl-matrix';
15
- export class SDGTFLoader {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SDGTFLoader = void 0;
13
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
14
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
15
+ const viewer_data_engine_shared_types_1 = require("@shapediver/viewer.data-engine.shared-types");
16
+ const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
17
+ const gl_matrix_1 = require("gl-matrix");
18
+ class SDGTFLoader {
16
19
  constructor() {
17
20
  // #region Properties (5)
18
21
  this.BINARY_EXTENSION_HEADER_LENGTH = 20;
19
- this._logger = Logger.instance;
22
+ this._logger = viewer_shared_services_1.Logger.instance;
20
23
  // #endregion Private Methods (6)
21
24
  }
22
25
  // #endregion Properties (5)
@@ -33,7 +36,7 @@ export class SDGTFLoader {
33
36
  contentFormat: headerDataView.getUint32(17, true)
34
37
  };
35
38
  if (header.magic != 'sdgTF')
36
- throw new ShapeDiverViewerDataProcessingError('SDGTFLoader.load: Invalid data: sdgTF magic wrong.');
39
+ throw new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('SDGTFLoader.load: Invalid data: sdgTF magic wrong.');
37
40
  // create content
38
41
  const contentDataView = new DataView(binaryGeometry, gltfLength + this.BINARY_EXTENSION_HEADER_LENGTH + 1, header.contentLength);
39
42
  const contentDecoded = new TextDecoder().decode(contentDataView);
@@ -41,7 +44,7 @@ export class SDGTFLoader {
41
44
  this._body = binaryGeometry.slice(gltfLength + this.BINARY_EXTENSION_HEADER_LENGTH + 1 + header.contentLength, gltfLength + header.length);
42
45
  }
43
46
  else {
44
- return new TreeNode();
47
+ return new viewer_shared_node_tree_1.TreeNode();
45
48
  }
46
49
  return yield this.loadScene();
47
50
  });
@@ -66,12 +69,12 @@ export class SDGTFLoader {
66
69
  throw new Error('Accessor not available.');
67
70
  const accessor = this._content.accessors[accessorName];
68
71
  const bufferView = this._body;
69
- const itemSize = ACCESSORTYPE[accessor.type];
70
- const ArrayType = ACCESSOR_COMPONENTTYPE[accessor.componentType];
72
+ const itemSize = viewer_data_engine_shared_types_1.ACCESSORTYPE_V1[accessor.type];
73
+ const ArrayType = viewer_data_engine_shared_types_1.ACCESSORCOMPONENTTYPE_V1[accessor.componentType];
71
74
  const elementBytes = ArrayType.BYTES_PER_ELEMENT;
72
75
  const itemBytes = elementBytes * itemSize;
73
76
  const byteOffset = accessor.byteOffset || 0;
74
- return new AttributeData(new ArrayType(bufferView, byteOffset, itemSize * accessor.count), itemSize, itemBytes, byteOffset, elementBytes, false, accessor.count);
77
+ return new viewer_shared_types_1.AttributeData(new ArrayType(bufferView, byteOffset, itemSize * accessor.count), itemSize, itemBytes, byteOffset, elementBytes, false, accessor.count);
75
78
  });
76
79
  }
77
80
  loadArcs() {
@@ -79,22 +82,22 @@ export class SDGTFLoader {
79
82
  if (!this._content.arcs)
80
83
  throw new Error('Arcs not available.');
81
84
  const arc = this._content.arcs;
82
- const arcNode = new TreeNode('arcs');
85
+ const arcNode = new viewer_shared_node_tree_1.TreeNode('arcs');
83
86
  const data = yield this.loadAccessor(arc.attributes['ARCS']);
84
87
  // data with an absolute classic array of Vec12s ...
85
88
  // like you usually have it in any good program
86
89
  // not 4 Vec3s, no, that would be to logic, but a Vec12 instead
87
90
  const count = data.array.length / data.itemSize;
88
91
  for (let i = 0; i < count; ++i) {
89
- const singleArcNode = new TreeNode('arc_' + i);
92
+ const singleArcNode = new viewer_shared_node_tree_1.TreeNode('arc_' + i);
90
93
  const index = i * 12;
91
- const arcCenter = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
92
- const arcXAxis = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
93
- const arcYAxis = vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
94
+ const arcCenter = gl_matrix_1.vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
95
+ const arcXAxis = gl_matrix_1.vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
96
+ const arcYAxis = gl_matrix_1.vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
94
97
  const arcRadius = data.array[index + 9];
95
98
  const arcMinAngle = data.array[index + 10];
96
99
  const arcMaxAngle = data.array[index + 11];
97
- const arcZAxis = vec3.cross(vec3.create(), arcXAxis, arcYAxis);
100
+ const arcZAxis = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), arcXAxis, arcYAxis);
98
101
  if (arcRadius <= 0) {
99
102
  this._logger.warn('SDGTFLoader.loadArcs: Arc radius is <= 0.');
100
103
  continue;
@@ -120,14 +123,14 @@ export class SDGTFLoader {
120
123
  getPointOnArc(d / numberOfPoints);
121
124
  const array = new Float32Array(points);
122
125
  const attributes = {};
123
- attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
124
- const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
126
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
127
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.LINE_STRIP);
125
128
  singleArcNode.data.push(geometry);
126
129
  singleArcNode.addTransformation({
127
130
  id: 'arc_' + i + '_translation',
128
- matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(arcCenter[0], arcCenter[1], arcCenter[2]))
131
+ matrix: gl_matrix_1.mat4.translate(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(arcCenter[0], arcCenter[1], arcCenter[2]))
129
132
  });
130
- const arcRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(arcXAxis[0], arcYAxis[0], arcZAxis[0], 0, arcXAxis[1], arcYAxis[1], arcZAxis[1], 0, arcXAxis[2], arcYAxis[2], arcZAxis[2], 0, 0, 0, 0, 1));
133
+ const arcRotationMatrix = gl_matrix_1.mat4.transpose(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.fromValues(arcXAxis[0], arcYAxis[0], arcZAxis[0], 0, arcXAxis[1], arcYAxis[1], arcZAxis[1], 0, arcXAxis[2], arcYAxis[2], arcZAxis[2], 0, 0, 0, 0, 1));
131
134
  singleArcNode.addTransformation({
132
135
  id: 'arc_' + i + '_rotation',
133
136
  matrix: arcRotationMatrix
@@ -142,11 +145,11 @@ export class SDGTFLoader {
142
145
  if (!this._content.beziercurves[beziercurveName])
143
146
  throw new Error('Beziercurve not available.');
144
147
  const beziercurve = this._content.beziercurves[beziercurveName];
145
- const beziercurveNode = new TreeNode(beziercurveName);
148
+ const beziercurveNode = new viewer_shared_node_tree_1.TreeNode(beziercurveName);
146
149
  const controlPointsData = yield this.loadAccessor(beziercurve.attributes['CONTROLPOINTS']); // vec3
147
150
  const controlPoints = [];
148
151
  for (let i = 0; i < controlPointsData.array.length; i += 3)
149
- controlPoints.push(vec4.fromValues(controlPointsData.array[i], controlPointsData.array[i + 1], controlPointsData.array[i + 2], 1));
152
+ controlPoints.push(gl_matrix_1.vec4.fromValues(controlPointsData.array[i], controlPointsData.array[i + 1], controlPointsData.array[i + 2], 1));
150
153
  const knotsData = yield this.loadAccessor(beziercurve.attributes['KNOTS']); // scalar
151
154
  const knots = [knotsData.array[0]];
152
155
  for (let i = 0; i < knotsData.array.length; i++)
@@ -196,12 +199,12 @@ export class SDGTFLoader {
196
199
  const calcBSplinePoint = (u) => {
197
200
  const span = findSpan(u);
198
201
  const N = calcBasisFunctions(span, u);
199
- const C = vec4.create();
202
+ const C = gl_matrix_1.vec4.create();
200
203
  for (let j = 0; j <= degree; ++j) {
201
204
  const point = controlPoints[span - degree + j];
202
205
  const Nj = N[j];
203
206
  const wNj = point[3] * Nj;
204
- vec4.add(C, C, vec4.fromValues(point[0] * wNj, point[1] * wNj, point[2] * wNj, point[3] * Nj));
207
+ gl_matrix_1.vec4.add(C, C, gl_matrix_1.vec4.fromValues(point[0] * wNj, point[1] * wNj, point[2] * wNj, point[3] * Nj));
205
208
  }
206
209
  return C;
207
210
  };
@@ -212,7 +215,7 @@ export class SDGTFLoader {
212
215
  let hpoint = calcBSplinePoint(u);
213
216
  if (hpoint[3] !== 1.0) {
214
217
  // project to 3D space: (wx, wy, wz, w) -> (x, y, z, 1)
215
- hpoint = vec4.divide(vec4.create(), hpoint, vec4.fromValues(hpoint[3], hpoint[3], hpoint[3], hpoint[3]));
218
+ hpoint = gl_matrix_1.vec4.divide(gl_matrix_1.vec4.create(), hpoint, gl_matrix_1.vec4.fromValues(hpoint[3], hpoint[3], hpoint[3], hpoint[3]));
216
219
  }
217
220
  points.push(hpoint[0], hpoint[1], hpoint[2]);
218
221
  };
@@ -220,14 +223,14 @@ export class SDGTFLoader {
220
223
  // We go through the control points, measure the distance
221
224
  let distance = 0;
222
225
  for (let i = 1; i < controlPoints.length; i++)
223
- distance += vec3.distance(vec3.fromValues(controlPoints[i - 1][0], controlPoints[i - 1][1], controlPoints[i - 1][2]), vec3.fromValues(controlPoints[i][0], controlPoints[i][1], controlPoints[i][2]));
226
+ distance += gl_matrix_1.vec3.distance(gl_matrix_1.vec3.fromValues(controlPoints[i - 1][0], controlPoints[i - 1][1], controlPoints[i - 1][2]), gl_matrix_1.vec3.fromValues(controlPoints[i][0], controlPoints[i][1], controlPoints[i][2]));
224
227
  const numberOfPoints = Math.min(100, Math.max(25, Math.floor(distance / 0.1)));
225
228
  for (let d = 0; d <= numberOfPoints; d++)
226
229
  getPointOnBezierCurve(d / numberOfPoints);
227
230
  const array = new Float32Array(points);
228
231
  const attributes = {};
229
- attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
230
- const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
232
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
233
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.LINE_STRIP);
231
234
  beziercurveNode.data.push(geometry);
232
235
  return beziercurveNode;
233
236
  });
@@ -237,17 +240,17 @@ export class SDGTFLoader {
237
240
  if (!this._content.circles)
238
241
  throw new Error('Circles not available.');
239
242
  const circle = this._content.circles;
240
- const circleNode = new TreeNode('circles');
243
+ const circleNode = new viewer_shared_node_tree_1.TreeNode('circles');
241
244
  const data = yield this.loadAccessor(circle.attributes['CIRCLES']);
242
245
  const count = data.array.length / data.itemSize;
243
246
  for (let i = 0; i < count; i++) {
244
- const singleCircleNode = new TreeNode('circle_' + i);
247
+ const singleCircleNode = new viewer_shared_node_tree_1.TreeNode('circle_' + i);
245
248
  const index = i * 10;
246
- const circleCenter = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
247
- const circleXAxis = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
248
- const circleYAxis = vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
249
+ const circleCenter = gl_matrix_1.vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
250
+ const circleXAxis = gl_matrix_1.vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
251
+ const circleYAxis = gl_matrix_1.vec3.fromValues(data.array[index + 6], data.array[index + 7], data.array[index + 8]);
249
252
  const circleRadius = data.array[index + 9];
250
- const circleZAxis = vec3.cross(vec3.create(), circleXAxis, circleYAxis);
253
+ const circleZAxis = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), circleXAxis, circleYAxis);
251
254
  if (circleRadius <= 0) {
252
255
  this._logger.warn('SDGTFLoader.loadCircles: Circle radius is <= 0.');
253
256
  continue;
@@ -273,14 +276,14 @@ export class SDGTFLoader {
273
276
  getPointOnArc(d / numberOfPoints);
274
277
  const array = new Float32Array(points);
275
278
  const attributes = {};
276
- attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
277
- const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
279
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(array, 3, 0, 0, 0, false, array.length / 3);
280
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.LINE_STRIP);
278
281
  singleCircleNode.data.push(geometry);
279
282
  singleCircleNode.addTransformation({
280
283
  id: 'circle_' + i + '_translation',
281
- matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(circleCenter[0], circleCenter[1], circleCenter[2]))
284
+ matrix: gl_matrix_1.mat4.translate(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(circleCenter[0], circleCenter[1], circleCenter[2]))
282
285
  });
283
- const circleRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(circleXAxis[0], circleYAxis[0], circleZAxis[0], 0, circleXAxis[1], circleYAxis[1], circleZAxis[1], 0, circleXAxis[2], circleYAxis[2], circleZAxis[2], 0, 0, 0, 0, 1));
286
+ const circleRotationMatrix = gl_matrix_1.mat4.transpose(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.fromValues(circleXAxis[0], circleYAxis[0], circleZAxis[0], 0, circleXAxis[1], circleYAxis[1], circleZAxis[1], 0, circleXAxis[2], circleYAxis[2], circleZAxis[2], 0, 0, 0, 0, 1));
284
287
  singleCircleNode.addTransformation({
285
288
  id: 'circle_' + i + '_rotation',
286
289
  matrix: circleRotationMatrix
@@ -295,29 +298,29 @@ export class SDGTFLoader {
295
298
  if (!this._content.cylinders)
296
299
  throw new Error('Cylinders not available.');
297
300
  const cylinder = this._content.cylinders;
298
- const cylinderNode = new TreeNode('cylinders');
301
+ const cylinderNode = new viewer_shared_node_tree_1.TreeNode('cylinders');
299
302
  const data = yield this.loadAccessor(cylinder.attributes['CYLINDERS']);
300
303
  const count = data.array.length / data.itemSize;
301
304
  for (let i = 0; i < count; i++) {
302
- const singleCylinderNode = new TreeNode('cylinder_' + i);
305
+ const singleCylinderNode = new viewer_shared_node_tree_1.TreeNode('cylinder_' + i);
303
306
  const index = i * 7;
304
- const cylinderTop = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
305
- const cylinderBottom = vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
307
+ const cylinderTop = gl_matrix_1.vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
308
+ const cylinderBottom = gl_matrix_1.vec3.fromValues(data.array[index + 3], data.array[index + 4], data.array[index + 5]);
306
309
  const cylinderRadius = data.array[index + 6];
307
- const cylinderAxis = vec3.sub(vec3.create(), cylinderTop, cylinderBottom);
308
- const dotX = Math.abs(vec3.dot(cylinderAxis, vec3.fromValues(1, 0, 0)));
309
- const dotY = Math.abs(vec3.dot(cylinderAxis, vec3.fromValues(0, 1, 0)));
310
+ const cylinderAxis = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), cylinderTop, cylinderBottom);
311
+ const dotX = Math.abs(gl_matrix_1.vec3.dot(cylinderAxis, gl_matrix_1.vec3.fromValues(1, 0, 0)));
312
+ const dotY = Math.abs(gl_matrix_1.vec3.dot(cylinderAxis, gl_matrix_1.vec3.fromValues(0, 1, 0)));
310
313
  let cylinderXAxis;
311
314
  if (dotX < dotY) {
312
- cylinderXAxis = vec3.cross(vec3.create(), cylinderAxis, vec3.fromValues(1, 0, 0));
315
+ cylinderXAxis = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), cylinderAxis, gl_matrix_1.vec3.fromValues(1, 0, 0));
313
316
  }
314
317
  else {
315
- cylinderXAxis = vec3.cross(vec3.create(), cylinderAxis, vec3.fromValues(0, 1, 0));
318
+ cylinderXAxis = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), cylinderAxis, gl_matrix_1.vec3.fromValues(0, 1, 0));
316
319
  }
317
- const cylinderYAxis = vec3.cross(vec3.create(), cylinderAxis, cylinderXAxis);
318
- vec3.normalize(cylinderAxis, cylinderAxis);
319
- vec3.normalize(cylinderXAxis, cylinderXAxis);
320
- vec3.normalize(cylinderYAxis, cylinderYAxis);
320
+ const cylinderYAxis = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), cylinderAxis, cylinderXAxis);
321
+ gl_matrix_1.vec3.normalize(cylinderAxis, cylinderAxis);
322
+ gl_matrix_1.vec3.normalize(cylinderXAxis, cylinderXAxis);
323
+ gl_matrix_1.vec3.normalize(cylinderYAxis, cylinderYAxis);
321
324
  if (cylinderRadius <= 0) {
322
325
  this._logger.warn('SDGTFLoader.loadCylinders: Cylinder radius is <= 0.');
323
326
  continue;
@@ -326,14 +329,14 @@ export class SDGTFLoader {
326
329
  const vertices = [];
327
330
  const normals = [];
328
331
  const uvs = [];
329
- const height = vec3.distance(cylinderTop, cylinderBottom);
332
+ const height = gl_matrix_1.vec3.distance(cylinderTop, cylinderBottom);
330
333
  const halfHeight = height / 2;
331
334
  const thetaStart = 0, thetaLength = Math.PI * 2;
332
335
  let indexCounter = 0;
333
336
  const indexArray = [];
334
337
  const heightSegments = 1, radialSegments = 50;
335
- const normal = vec3.create();
336
- const vertex = vec3.create();
338
+ const normal = gl_matrix_1.vec3.create();
339
+ const vertex = gl_matrix_1.vec3.create();
337
340
  let groupCount = 0;
338
341
  // this will be used to calculate the normal
339
342
  const slope = 0;
@@ -354,7 +357,7 @@ export class SDGTFLoader {
354
357
  vertex[2] = radius * cosTheta;
355
358
  vertices.push(vertex[0], vertex[1], vertex[2]);
356
359
  // normal
357
- vec3.normalize(normal, vec3.fromValues(sinTheta, slope, cosTheta));
360
+ gl_matrix_1.vec3.normalize(normal, gl_matrix_1.vec3.fromValues(sinTheta, slope, cosTheta));
358
361
  normals.push(normal[0], normal[1], normal[2]);
359
362
  // uv
360
363
  uvs.push(u, 1 - v);
@@ -380,27 +383,27 @@ export class SDGTFLoader {
380
383
  }
381
384
  }
382
385
  const attributes = {};
383
- attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
384
- attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
385
- attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
386
- const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
386
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
387
+ attributes['NORMAL'] = new viewer_shared_types_1.AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
388
+ attributes['TEXCOORD_0'] = new viewer_shared_types_1.AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
389
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, new viewer_shared_types_1.AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), viewer_shared_types_1.PRIMITIVE_MODE.TRIANGLES);
387
390
  singleCylinderNode.data.push(geometry);
388
391
  singleCylinderNode.addTransformation({
389
392
  id: 'cylinder_' + i + '_translation',
390
- matrix: mat4.translate(mat4.create(), mat4.create(), cylinderBottom)
393
+ matrix: gl_matrix_1.mat4.translate(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), cylinderBottom)
391
394
  });
392
- const cylinderRotationMatrix = mat4.transpose(mat4.create(), mat4.fromValues(cylinderXAxis[0], cylinderYAxis[0], cylinderAxis[0], 0, cylinderXAxis[1], cylinderYAxis[1], cylinderAxis[1], 0, cylinderXAxis[2], cylinderYAxis[2], cylinderAxis[2], 0, 0, 0, 0, 1));
395
+ const cylinderRotationMatrix = gl_matrix_1.mat4.transpose(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.fromValues(cylinderXAxis[0], cylinderYAxis[0], cylinderAxis[0], 0, cylinderXAxis[1], cylinderYAxis[1], cylinderAxis[1], 0, cylinderXAxis[2], cylinderYAxis[2], cylinderAxis[2], 0, 0, 0, 0, 1));
393
396
  singleCylinderNode.addTransformation({
394
397
  id: 'cylinder_' + i + '_rotation',
395
398
  matrix: cylinderRotationMatrix
396
399
  });
397
400
  singleCylinderNode.addTransformation({
398
401
  id: 'cylinder_' + i + '_rotation2',
399
- matrix: mat4.rotateX(mat4.create(), mat4.create(), 0.5 * Math.PI)
402
+ matrix: gl_matrix_1.mat4.rotateX(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), 0.5 * Math.PI)
400
403
  });
401
404
  singleCylinderNode.addTransformation({
402
405
  id: 'cylinder_' + i + '_translation2',
403
- matrix: mat4.translate(mat4.create(), mat4.create(), vec3.fromValues(0, 0, 0.5 * vec3.distance(cylinderTop, cylinderBottom)))
406
+ matrix: gl_matrix_1.mat4.translate(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(0, 0, 0.5 * gl_matrix_1.vec3.distance(cylinderTop, cylinderBottom)))
404
407
  });
405
408
  cylinderNode.addChild(singleCylinderNode);
406
409
  }
@@ -412,13 +415,13 @@ export class SDGTFLoader {
412
415
  if (!this._content.spheres)
413
416
  throw new Error('Spheres not available.');
414
417
  const sphere = this._content.spheres;
415
- const sphereNode = new TreeNode('spheres');
418
+ const sphereNode = new viewer_shared_node_tree_1.TreeNode('spheres');
416
419
  const data = yield this.loadAccessor(sphere.attributes['SPHERES']);
417
420
  const count = data.array.length / data.itemSize;
418
421
  for (let i = 0; i < count; i++) {
419
- const singleSphereNode = new TreeNode('sphere_' + i);
422
+ const singleSphereNode = new viewer_shared_node_tree_1.TreeNode('sphere_' + i);
420
423
  const index = i * 4;
421
- const sphereTranslation = vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
424
+ const sphereTranslation = gl_matrix_1.vec3.fromValues(data.array[index + 0], data.array[index + 1], data.array[index + 2]);
422
425
  const sphereRadius = data.array[index + 3];
423
426
  if (sphereRadius <= 0) {
424
427
  this._logger.warn('SDGTFLoader.loadSpheres: Sphere radius is <= 0.');
@@ -450,10 +453,10 @@ export class SDGTFLoader {
450
453
  for (let ix = 0; ix <= widthSegments; ix++) {
451
454
  const u = ix / widthSegments;
452
455
  // vertex
453
- const vertex = vec3.fromValues(-sphereRadius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength), sphereRadius * Math.cos(thetaStart + v * thetaLength), sphereRadius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength));
456
+ const vertex = gl_matrix_1.vec3.fromValues(-sphereRadius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength), sphereRadius * Math.cos(thetaStart + v * thetaLength), sphereRadius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength));
454
457
  vertices.push(vertex[0], vertex[1], vertex[2]);
455
458
  // normal
456
- const normal = vec3.normalize(vec3.create(), vertex);
459
+ const normal = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), vertex);
457
460
  normals.push(normal[0], normal[1], normal[2]);
458
461
  // uv
459
462
  uvs.push(u + uOffset, 1 - v);
@@ -475,14 +478,14 @@ export class SDGTFLoader {
475
478
  }
476
479
  }
477
480
  const attributes = {};
478
- attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
479
- attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
480
- attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
481
- const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
481
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
482
+ attributes['NORMAL'] = new viewer_shared_types_1.AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3);
483
+ attributes['TEXCOORD_0'] = new viewer_shared_types_1.AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2);
484
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, new viewer_shared_types_1.AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), viewer_shared_types_1.PRIMITIVE_MODE.TRIANGLES);
482
485
  singleSphereNode.data.push(geometry);
483
486
  singleSphereNode.addTransformation({
484
487
  id: 'sphere_' + i + '_translation',
485
- matrix: mat4.translate(mat4.create(), mat4.create(), sphereTranslation)
488
+ matrix: gl_matrix_1.mat4.translate(gl_matrix_1.mat4.create(), gl_matrix_1.mat4.create(), sphereTranslation)
486
489
  });
487
490
  sphereNode.addChild(singleSphereNode);
488
491
  }
@@ -494,11 +497,11 @@ export class SDGTFLoader {
494
497
  if (!this._content.points[pointName])
495
498
  throw new Error('Point not available.');
496
499
  const point = this._content.points[pointName];
497
- const pointNode = new TreeNode(pointName);
500
+ const pointNode = new viewer_shared_node_tree_1.TreeNode(pointName);
498
501
  const attributes = {};
499
502
  const data = yield this.loadAccessor(point.attributes['POINTS']);
500
- attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
501
- const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.POINTS);
503
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
504
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.POINTS);
502
505
  pointNode.data.push(geometry);
503
506
  return pointNode;
504
507
  });
@@ -508,11 +511,11 @@ export class SDGTFLoader {
508
511
  if (!this._content.polylines[polylineName])
509
512
  throw new Error('Polyline not available.');
510
513
  const polyLine = this._content.polylines[polylineName];
511
- const polyLineNode = new TreeNode(polylineName);
514
+ const polyLineNode = new viewer_shared_node_tree_1.TreeNode(polylineName);
512
515
  const attributes = {};
513
516
  const data = yield this.loadAccessor(polyLine.attributes['VERTICES']);
514
- attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
515
- const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
517
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count);
518
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, null), viewer_shared_types_1.PRIMITIVE_MODE.LINE_STRIP);
516
519
  polyLineNode.data.push(geometry);
517
520
  return polyLineNode;
518
521
  });
@@ -522,7 +525,7 @@ export class SDGTFLoader {
522
525
  if (!this._content.surfacepatches[surfacepatchName])
523
526
  throw new Error('Surfacepatch not available.');
524
527
  const surfacepatch = this._content.surfacepatches[surfacepatchName];
525
- const surfacepatchNode = new TreeNode(surfacepatchName);
528
+ const surfacepatchNode = new viewer_shared_node_tree_1.TreeNode(surfacepatchName);
526
529
  const controlPointCountU = surfacepatch.controlPointCountU;
527
530
  const controlPointCountV = surfacepatch.controlPointCountV;
528
531
  const controlPointsData = yield this.loadAccessor(surfacepatch.attributes['CONTROLPOINTS']); // vec3
@@ -531,7 +534,7 @@ export class SDGTFLoader {
531
534
  for (let u = 0; u < controlPointCountU; u++) {
532
535
  let innerArray = [];
533
536
  for (let v = 0; v < controlPointCountV; v++) {
534
- innerArray.push(vec4.fromValues(controlPointsData.array[pointCount * 3], controlPointsData.array[pointCount * 3 + 1], controlPointsData.array[pointCount * 3 + 2], 1));
537
+ innerArray.push(gl_matrix_1.vec4.fromValues(controlPointsData.array[pointCount * 3], controlPointsData.array[pointCount * 3 + 1], controlPointsData.array[pointCount * 3 + 2], 1));
535
538
  pointCount++;
536
539
  }
537
540
  controlPoints.push(innerArray);
@@ -595,22 +598,22 @@ export class SDGTFLoader {
595
598
  const Nv = calcBasisFunctions(knotsV, degreeV, vspan, v);
596
599
  const temp = [];
597
600
  for (let l = 0; l <= degreeV; ++l) {
598
- temp[l] = vec4.create();
601
+ temp[l] = gl_matrix_1.vec4.create();
599
602
  for (let k = 0; k <= degreeU; ++k) {
600
- const point = vec4.clone(controlPoints[uspan - degreeU + k][vspan - degreeV + l]);
603
+ const point = gl_matrix_1.vec4.clone(controlPoints[uspan - degreeU + k][vspan - degreeV + l]);
601
604
  const w = point[3];
602
605
  point[0] *= w;
603
606
  point[1] *= w;
604
607
  point[2] *= w;
605
- vec4.add(temp[l], temp[l], vec4.multiply(vec4.create(), point, vec4.fromValues(Nu[k], Nu[k], Nu[k], Nu[k])));
608
+ gl_matrix_1.vec4.add(temp[l], temp[l], gl_matrix_1.vec4.multiply(gl_matrix_1.vec4.create(), point, gl_matrix_1.vec4.fromValues(Nu[k], Nu[k], Nu[k], Nu[k])));
606
609
  }
607
610
  }
608
- const Sw = vec4.create();
611
+ const Sw = gl_matrix_1.vec4.create();
609
612
  for (let l = 0; l <= degreeV; ++l) {
610
- vec4.add(Sw, Sw, vec4.multiply(vec4.create(), temp[l], vec4.fromValues(Nv[l], Nv[l], Nv[l], Nv[l])));
613
+ gl_matrix_1.vec4.add(Sw, Sw, gl_matrix_1.vec4.multiply(gl_matrix_1.vec4.create(), temp[l], gl_matrix_1.vec4.fromValues(Nv[l], Nv[l], Nv[l], Nv[l])));
611
614
  }
612
- vec4.divide(Sw, Sw, vec4.fromValues(Sw[3], Sw[3], Sw[3], Sw[3]));
613
- return vec3.fromValues(Sw[0], Sw[1], Sw[2]);
615
+ gl_matrix_1.vec4.divide(Sw, Sw, gl_matrix_1.vec4.fromValues(Sw[3], Sw[3], Sw[3], Sw[3]));
616
+ return gl_matrix_1.vec3.fromValues(Sw[0], Sw[1], Sw[2]);
614
617
  };
615
618
  const getPointOnSurfacepatch = (t1, t2) => {
616
619
  const u = knotsU[0] + t1 * (knotsU[knotsU.length - 1] - knotsU[0]); // linear mapping t1->u
@@ -640,18 +643,18 @@ export class SDGTFLoader {
640
643
  }
641
644
  }
642
645
  const attributes = {};
643
- attributes['POSITION'] = new AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
646
+ attributes['POSITION'] = new viewer_shared_types_1.AttributeData(new Float32Array(vertices), 3, 0, 0, 0, false, vertices.length / 3);
644
647
  // to not compute normals ourselves, we just let three.js do it
645
648
  // in our geometry loader, this array will cause the computation of vertex normals
646
- attributes['NORMAL'] = new AttributeData(new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3, 0, 0, 0, false, vertices.length / 3);
647
- const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
649
+ attributes['NORMAL'] = new viewer_shared_types_1.AttributeData(new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3, 0, 0, 0, false, vertices.length / 3);
650
+ const geometry = new viewer_shared_types_1.GeometryData(new viewer_shared_types_1.PrimitiveData(attributes, new viewer_shared_types_1.AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), viewer_shared_types_1.PRIMITIVE_MODE.TRIANGLES);
648
651
  surfacepatchNode.data.push(geometry);
649
652
  return surfacepatchNode;
650
653
  });
651
654
  }
652
655
  loadScene() {
653
656
  return __awaiter(this, void 0, void 0, function* () {
654
- const sceneNode = new TreeNode('sdgtf_content');
657
+ const sceneNode = new viewer_shared_node_tree_1.TreeNode('sdgtf_content');
655
658
  // arcs
656
659
  if (this._content.arcs)
657
660
  sceneNode.addChild(yield this.loadArcs());
@@ -688,4 +691,5 @@ export class SDGTFLoader {
688
691
  });
689
692
  }
690
693
  }
694
+ exports.SDGTFLoader = SDGTFLoader;
691
695
  //# sourceMappingURL=SDGTFLoader.js.map