@shapediver/viewer.data-engine.geometry-engine 2.8.5 → 2.9.1

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 +1 -1
  2. package/dist/GeometryEngine.d.ts.map +1 -1
  3. package/dist/GeometryEngine.js +7 -4
  4. package/dist/GeometryEngine.js.map +1 -1
  5. package/dist/gltfv1/GLTFLoader.d.ts +7 -2
  6. package/dist/gltfv1/GLTFLoader.d.ts.map +1 -1
  7. package/dist/gltfv1/GLTFLoader.js +28 -5
  8. package/dist/gltfv1/GLTFLoader.js.map +1 -1
  9. package/dist/gltfv1/SDGTFLoader.js +8 -8
  10. package/dist/gltfv1/SDGTFLoader.js.map +1 -1
  11. package/dist/gltfv2/GLTFLoader.d.ts +7 -2
  12. package/dist/gltfv2/GLTFLoader.d.ts.map +1 -1
  13. package/dist/gltfv2/GLTFLoader.js +97 -71
  14. package/dist/gltfv2/GLTFLoader.js.map +1 -1
  15. package/dist/gltfv2/loaders/AccessorLoader.d.ts +0 -1
  16. package/dist/gltfv2/loaders/AccessorLoader.d.ts.map +1 -1
  17. package/dist/gltfv2/loaders/AccessorLoader.js +3 -27
  18. package/dist/gltfv2/loaders/AccessorLoader.js.map +1 -1
  19. package/dist/gltfv2/loaders/GeometryLoader.js +4 -4
  20. package/dist/gltfv2/loaders/GeometryLoader.js.map +1 -1
  21. package/dist/gltfv2/loaders/MaterialLoader.d.ts.map +1 -1
  22. package/dist/gltfv2/loaders/MaterialLoader.js +11 -6
  23. package/dist/gltfv2/loaders/MaterialLoader.js.map +1 -1
  24. package/dist/gltfv2/loaders/TextureLoader.js +4 -4
  25. package/dist/gltfv2/loaders/TextureLoader.js.map +1 -1
  26. package/package.json +11 -11
  27. package/src/GeometryEngine.ts +7 -4
  28. package/src/gltfv1/GLTFLoader.ts +42 -7
  29. package/src/gltfv1/SDGTFLoader.ts +8 -8
  30. package/src/gltfv2/GLTFLoader.ts +39 -8
  31. package/src/gltfv2/loaders/AccessorLoader.ts +17 -50
  32. package/src/gltfv2/loaders/GeometryLoader.ts +4 -4
  33. package/src/gltfv2/loaders/MaterialLoader.ts +10 -6
  34. package/src/gltfv2/loaders/TextureLoader.ts +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"TextureLoader.js","sourceRoot":"","sources":["../../../src/gltfv2/loaders/TextureLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+EAAwF;AAIxF,MAAa,aAAa;IAUtB,4BAA4B;IAE5B,2BAA2B;IAE3B,YAA6B,QAAkB,EAAmB,iBAAmC,EAAU,QAAiB;QAAnG,aAAQ,GAAR,QAAQ,CAAU;QAAmB,sBAAiB,GAAjB,iBAAiB,CAAkB;QAAU,aAAQ,GAAR,QAAQ,CAAS;QAbhI,yBAAyB;QAER,eAAU,GAAc,kCAAS,CAAC,QAAQ,CAAC;QAC3C,gBAAW,GAAe,mCAAU,CAAC,QAAQ,CAAC;QAEvD,YAAO,GAEX,EAAE,CAAC;IAM6H,CAAC;IAErI,8BAA8B;IAE9B,6BAA6B;IAEtB,UAAU,CAAC,SAAiB;QAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;QACjG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QAC3G,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAC9F,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAEY,IAAI;;YACb,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;gBAAE,OAAO;YAEpC,IAAI,QAAQ,GAAoB,EAAE,CAAC;YACnC,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
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Michael Oppitz <michael@shapediver.com>",
@@ -39,15 +39,15 @@
39
39
  "testEnvironment": "node"
40
40
  },
41
41
  "dependencies": {
42
- "@shapediver/sdk.geometry-api-sdk-v2": "1.3.0",
43
- "@shapediver/viewer.data-engine.material-engine": "2.8.5",
44
- "@shapediver/viewer.data-engine.shared-types": "2.8.5",
45
- "@shapediver/viewer.rendering-engine.camera-engine": "2.8.5",
46
- "@shapediver/viewer.rendering-engine.light-engine": "2.8.5",
47
- "@shapediver/viewer.shared.build-data": "2.8.5",
48
- "@shapediver/viewer.shared.node-tree": "2.8.5",
49
- "@shapediver/viewer.shared.services": "2.8.5",
50
- "@shapediver/viewer.shared.types": "2.8.5",
42
+ "@shapediver/sdk.geometry-api-sdk-v2": "1.4.0",
43
+ "@shapediver/viewer.data-engine.material-engine": "2.9.1",
44
+ "@shapediver/viewer.data-engine.shared-types": "2.9.1",
45
+ "@shapediver/viewer.rendering-engine.camera-engine": "2.9.1",
46
+ "@shapediver/viewer.rendering-engine.light-engine": "2.9.1",
47
+ "@shapediver/viewer.shared.build-data": "2.9.1",
48
+ "@shapediver/viewer.shared.node-tree": "2.9.1",
49
+ "@shapediver/viewer.shared.services": "2.9.1",
50
+ "@shapediver/viewer.shared.types": "2.9.1",
51
51
  "axios": "^1.2.6",
52
52
  "gl-matrix": "3.3.0"
53
53
  },
@@ -56,5 +56,5 @@
56
56
  "path": false,
57
57
  "os": false
58
58
  },
59
- "gitHead": "a89e7b495fd87f1cb8bf6d412dec704190ee9585"
59
+ "gitHead": "c7b6d22d492066831588ca0e9ce66844b921dc6f"
60
60
  }
@@ -48,7 +48,7 @@ export class GeometryEngine {
48
48
  * @param content the geometry content
49
49
  * @returns the scene graph node
50
50
  */
51
- public async loadContent(content: ShapeDiverResponseOutputContent): Promise<ITreeNode> {
51
+ public async loadContent(content: ShapeDiverResponseOutputContent, taskEventId: string): Promise<ITreeNode> {
52
52
  if (!content || (content && !content.href))
53
53
  throw new ShapeDiverViewerDataProcessingError('GeometryEngine cannot load content.');
54
54
 
@@ -57,7 +57,7 @@ export class GeometryEngine {
57
57
 
58
58
  const url = content.href!;
59
59
  // eslint-disable-next-line no-async-promise-executor
60
- const loadingPromise = new Promise<ITreeNode>(async (resolve) => {
60
+ const loadingPromise = new Promise<ITreeNode>(async (resolve, reject) => {
61
61
  let gltfContent, gltfBinary, gltfBaseUrl, gltfHeader;
62
62
  let version = '2.0';
63
63
 
@@ -126,11 +126,14 @@ export class GeometryEngine {
126
126
  }
127
127
  }
128
128
 
129
+ let promise: Promise<ITreeNode>;
129
130
  if (version === '1.0') {
130
- resolve(await new GLTF_v1Loader().load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl));
131
+ promise = new GLTF_v1Loader().load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl, taskEventId)
131
132
  } else {
132
- resolve(await new GLTF_v2Loader().load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl));
133
+ promise = new GLTF_v2Loader().load(gltfContent, gltfBinary, gltfHeader, gltfBaseUrl, taskEventId);
133
134
  }
135
+ promise.catch(e => { reject(e) })
136
+ resolve(promise);
134
137
  })
135
138
 
136
139
  this._loadingQueue.push(loadingPromise);
@@ -1,5 +1,5 @@
1
1
  import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree'
2
- import { Converter, HttpClient, PerformanceEvaluator, UuidGenerator, Logger, ShapeDiverViewerDataProcessingError } from '@shapediver/viewer.shared.services'
2
+ import { Converter, HttpClient, PerformanceEvaluator, UuidGenerator, Logger, ShapeDiverViewerDataProcessingError, EventEngine, EVENTTYPE } from '@shapediver/viewer.shared.services'
3
3
  import {
4
4
  ACCESSORCOMPONENTTYPE_V1 as ACCESSOR_COMPONENTTYPE,
5
5
  ACCESSORTYPE_V1 as ACCESSORTYPE,
@@ -13,6 +13,9 @@ import {
13
13
  MATERIAL_SIDE,
14
14
  MaterialStandardData,
15
15
  PrimitiveData,
16
+ ITaskEvent,
17
+ TASK_TYPE,
18
+ PRIMITIVE_MODE,
16
19
  } from '@shapediver/viewer.shared.types'
17
20
 
18
21
  import { SDGTFLoader } from './SDGTFLoader'
@@ -26,18 +29,31 @@ export class GLTFLoader {
26
29
  private readonly _logger: Logger = Logger.instance;
27
30
  private readonly _implementedExtensions = ['KHR_materials_common'];
28
31
  private readonly _globalTransformation = mat4.fromValues(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1);
29
- private readonly _converter: Converter = Converter.instance;
32
+ private readonly _eventEngine: EventEngine = EventEngine.instance;
30
33
  private readonly _performanceEvaluator = PerformanceEvaluator.instance;
34
+ private readonly _progressUpdateLimit = 500;
31
35
 
32
36
  private _baseUri: string | undefined;
33
37
  private _body: ArrayBuffer | undefined;
34
38
  private _content!: IGLTF_v1;
39
+ private _eventId: string = "";
40
+ private _numberOfNodes = 0;
41
+ private _numberOfConvertedNodes = 0;
42
+ private _progressTimer = 0;
35
43
 
36
44
  // #endregion Properties (5)
37
45
 
38
46
  // #region Public Methods (1)
39
47
 
40
- public async load(content: IGLTF_v1, gltfBinary?: ArrayBuffer, gltfHeader?: { magic: string, version: number, length: number, contentLength: number, contentFormat: number }, baseUri?: string): Promise<ITreeNode> {
48
+ public async load(content: IGLTF_v1, gltfBinary?: ArrayBuffer, gltfHeader?: { magic: string, version: number, length: number, contentLength: number, contentFormat: number }, baseUri?: string, taskEventId?: string): Promise<ITreeNode> {
49
+ this._eventId = taskEventId || this._uuidGenerator.create();
50
+ const eventStart: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0, status: 'Starting glTF 1.0 loading.' };
51
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, eventStart);
52
+
53
+ this._numberOfConvertedNodes = 0;
54
+ this._numberOfNodes = content.nodes ? Object.values(content.nodes).length : 0;
55
+ this._progressTimer = performance.now();
56
+
41
57
  this._baseUri = baseUri;
42
58
  if(gltfBinary && gltfHeader)
43
59
  this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH + gltfHeader.contentLength, gltfHeader.length);
@@ -47,11 +63,19 @@ export class GLTFLoader {
47
63
  if(gltfBinary && gltfHeader)
48
64
  sdgtfNode = await new SDGTFLoader().load(gltfBinary, gltfHeader.length);
49
65
 
66
+
67
+ const eventProgressSDgTF: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0.25, status: 'Loaded SDgTF content.' };
68
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventProgressSDgTF);
69
+
70
+
50
71
  this.validateVersionAndExtensions();
51
72
  const node = await this.loadScene();
52
73
  if(sdgtfNode) node.addChild(sdgtfNode);
53
- return node;
54
74
 
75
+ const eventEnd: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 1, status: 'GlTF loading complete.' };
76
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
77
+
78
+ return node;
55
79
  }
56
80
 
57
81
  public async loadWithUrl(url?: string | undefined): Promise<ITreeNode> {
@@ -129,12 +153,13 @@ export class GLTFLoader {
129
153
  const byteOffset = accessor.byteOffset || 0;
130
154
  const byteStride = accessor.byteStride;
131
155
  const normalized = false;
156
+ const target = this._content.bufferViews![accessor.bufferView] ? this._content.bufferViews![accessor.bufferView].target : undefined;
132
157
 
133
158
  const min = this._content.asset && this._content.asset?.generator === "ShapeDiverGltfV1Writer" ? accessor.min || [] : [];
134
159
  const max = this._content.asset && this._content.asset?.generator === "ShapeDiverGltfV1Writer" ? accessor.max || [] : [];
135
160
 
136
161
  // The buffer is not interleaved if the stride is the item size in bytes.
137
- return new AttributeData(new ArrayType(bufferView), itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, min, max, byteStride);
162
+ return new AttributeData(new ArrayType(bufferView), itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, min, max, byteStride, target);
138
163
  }
139
164
 
140
165
  private async loadBuffer(bufferName: string): Promise<ArrayBuffer> {
@@ -247,14 +272,14 @@ export class GLTFLoader {
247
272
 
248
273
  attributes[attributeName] = await this.loadAccessor(primitive.attributes[attribute]);
249
274
  if(attributeName.startsWith('COLOR'))
250
- attributes[attributeName] = new AttributeData(attributes[attributeName].array, attributes[attributeName].itemSize, attributes[attributeName].itemBytes, attributes[attributeName].byteOffset, attributes[attributeName].elementBytes, true, attributes[attributeName].count, [], [], attributes[attributeName].byteStride)
275
+ attributes[attributeName] = new AttributeData(attributes[attributeName].array, attributes[attributeName].itemSize, attributes[attributeName].itemBytes, attributes[attributeName].byteOffset, attributes[attributeName].elementBytes, true, attributes[attributeName].count, [], [], attributes[attributeName].byteStride, attributes[attributeName].target)
251
276
  }
252
277
 
253
278
  let material: MaterialStandardData | undefined;
254
279
  if(primitive.material)
255
280
  material = await this.loadMaterial(primitive.material);
256
281
 
257
- const geometry = new GeometryData(new PrimitiveData(attributes, 4, await this.loadAccessor(primitive.indices!), material));
282
+ const geometry = new GeometryData(new PrimitiveData(attributes, await this.loadAccessor(primitive.indices!)), PRIMITIVE_MODE.TRIANGLES, material);
258
283
  primitiveNode.data.push(geometry);
259
284
  }
260
285
  return meshNode;
@@ -298,6 +323,16 @@ export class GLTFLoader {
298
323
  }
299
324
  }
300
325
 
326
+
327
+ this._numberOfConvertedNodes++;
328
+
329
+ if(performance.now() - this._progressTimer > this._progressUpdateLimit) {
330
+ this._progressTimer = performance.now();
331
+ const eventProgress: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: (this._numberOfConvertedNodes / this._numberOfNodes) / 2 + 0.25, status: `GlTF conversion progress: ${this._numberOfConvertedNodes}/${this._numberOfNodes} nodes.` };
332
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventProgress);
333
+ await new Promise(resolve => setTimeout(resolve, 0));
334
+ }
335
+
301
336
  return nodeDef;
302
337
  }
303
338
 
@@ -136,7 +136,7 @@ export class SDGTFLoader {
136
136
  } = {};
137
137
  attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3)
138
138
 
139
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.LINE_STRIP, null));
139
+ const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
140
140
  singleArcNode.data.push(geometry);
141
141
 
142
142
  singleArcNode.addTransformation({
@@ -263,7 +263,7 @@ export class SDGTFLoader {
263
263
  } = {};
264
264
  attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3)
265
265
 
266
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.LINE_STRIP, null));
266
+ const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
267
267
  beziercurveNode.data.push(geometry);
268
268
 
269
269
  return beziercurveNode;
@@ -317,7 +317,7 @@ export class SDGTFLoader {
317
317
  } = {};
318
318
  attributes['POSITION'] = new AttributeData(array, 3, 0, 0, 0, false, array.length / 3)
319
319
 
320
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.LINE_STRIP, null));
320
+ const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
321
321
  singleCircleNode.data.push(geometry);
322
322
 
323
323
  singleCircleNode.addTransformation({
@@ -449,7 +449,7 @@ export class SDGTFLoader {
449
449
  attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3)
450
450
  attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2)
451
451
 
452
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.TRIANGLES, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)));
452
+ const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
453
453
  singleCylinderNode.data.push(geometry);
454
454
 
455
455
  singleCylinderNode.addTransformation({
@@ -567,7 +567,7 @@ export class SDGTFLoader {
567
567
  attributes['NORMAL'] = new AttributeData(new Float32Array(normals), 3, 0, 0, 0, false, normals.length / 3)
568
568
  attributes['TEXCOORD_0'] = new AttributeData(new Float32Array(uvs), 2, 0, 0, 0, false, uvs.length / 2)
569
569
 
570
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.TRIANGLES, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)));
570
+ const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
571
571
  singleSphereNode.data.push(geometry);
572
572
 
573
573
  singleSphereNode.addTransformation({
@@ -592,7 +592,7 @@ export class SDGTFLoader {
592
592
  const data = await this.loadAccessor(point.attributes['POINTS']);
593
593
  attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count)
594
594
 
595
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.POINTS, null));
595
+ const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.POINTS);
596
596
  pointNode.data.push(geometry);
597
597
 
598
598
  return pointNode;
@@ -610,7 +610,7 @@ export class SDGTFLoader {
610
610
  const data = await this.loadAccessor(polyLine.attributes['VERTICES']);
611
611
  attributes['POSITION'] = new AttributeData(data.array, 3, data.itemBytes, data.byteOffset, data.elementBytes, data.normalized, data.count)
612
612
 
613
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.LINE_STRIP, null));
613
+ const geometry = new GeometryData(new PrimitiveData(attributes, null), PRIMITIVE_MODE.LINE_STRIP);
614
614
  polyLineNode.data.push(geometry);
615
615
 
616
616
  return polyLineNode;
@@ -767,7 +767,7 @@ export class SDGTFLoader {
767
767
  // in our geometry loader, this array will cause the computation of vertex normals
768
768
  attributes['NORMAL'] = new AttributeData(new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3, 0, 0, 0, false, vertices.length / 3);
769
769
 
770
- const geometry = new GeometryData(new PrimitiveData(attributes, PRIMITIVE_MODE.TRIANGLES, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)));
770
+ const geometry = new GeometryData(new PrimitiveData(attributes, new AttributeData(this.convertToIndicesArray(indices), 1, 0, 0, 0, false, indices.length)), PRIMITIVE_MODE.TRIANGLES);
771
771
  surfacepatchNode.data.push(geometry);
772
772
 
773
773
  return surfacepatchNode;
@@ -1,6 +1,8 @@
1
1
  import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree'
2
2
  import {
3
3
  Converter,
4
+ EventEngine,
5
+ EVENTTYPE,
4
6
  HttpClient,
5
7
  Logger,
6
8
  PerformanceEvaluator,
@@ -14,7 +16,9 @@ import {
14
16
  IAnimationTrack,
15
17
  AttributeData,
16
18
  BoneData,
17
- Color
19
+ Color,
20
+ ITaskEvent,
21
+ TASK_TYPE
18
22
  } from '@shapediver/viewer.shared.types'
19
23
  import { OrthographicCamera, PerspectiveCamera } from '@shapediver/viewer.rendering-engine.camera-engine'
20
24
  import {
@@ -55,11 +59,12 @@ export class GLTFLoader {
55
59
  // #region Properties (17)
56
60
 
57
61
  private readonly BINARY_EXTENSION_HEADER_LENGTH = 20;
58
- private readonly _converter: Converter = Converter.instance;
62
+ private readonly _eventEngine: EventEngine = EventEngine.instance;
59
63
  private readonly _globalTransformation = mat4.fromValues(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1);
60
64
  private readonly _httpClient: HttpClient = HttpClient.instance;
61
65
  private readonly _logger: Logger = Logger.instance;
62
66
  private readonly _performanceEvaluator = PerformanceEvaluator.instance;
67
+ private readonly _progressUpdateLimit = 500;
63
68
  private readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
64
69
 
65
70
  private _accessorLoader!: AccessorLoader;
@@ -68,18 +73,30 @@ export class GLTFLoader {
68
73
  private _bufferLoader!: BufferLoader;
69
74
  private _bufferViewLoader!: BufferViewLoader;
70
75
  private _content!: IGLTF_v2;
76
+ private _eventId: string = "";
71
77
  private _geometryLoader!: GeometryLoader;
72
78
  private _materialLoader!: MaterialLoader;
73
79
  private _nodes: {
74
80
  [key: number]: ITreeNode
75
81
  } = {};
82
+ private _numberOfNodes = 0;
83
+ private _numberOfConvertedNodes = 0;
76
84
  private _textureLoader!: TextureLoader;
85
+ private _progressTimer = 0;
77
86
 
78
87
  // #endregion Properties (17)
79
88
 
80
89
  // #region Public Methods (2)
81
90
 
82
- public async load(content: IGLTF_v2, gltfBinary?: ArrayBuffer, gltfHeader?: { magic: string, version: number, length: number, contentLength: number, contentFormat: number }, baseUri?: string): Promise<ITreeNode> {
91
+ public async load(content: IGLTF_v2, gltfBinary?: ArrayBuffer, gltfHeader?: { magic: string, version: number, length: number, contentLength: number, contentFormat: number }, baseUri?: string, taskEventId?: string): Promise<ITreeNode> {
92
+ this._eventId = taskEventId || this._uuidGenerator.create();
93
+ const eventStart: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0, status: 'Starting glTF 2.0 loading.' };
94
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, eventStart);
95
+
96
+ this._numberOfConvertedNodes = 0;
97
+ this._numberOfNodes = content.nodes ? content.nodes.length : 0;
98
+ this._progressTimer = performance.now();
99
+
83
100
  this._baseUri = baseUri;
84
101
  if (gltfBinary && gltfHeader)
85
102
  this._body = gltfBinary.slice(this.BINARY_EXTENSION_HEADER_LENGTH + gltfHeader.contentLength + 8, gltfHeader.length);
@@ -101,7 +118,10 @@ export class GLTFLoader {
101
118
  await this._materialLoader.load();
102
119
  this._geometryLoader = new GeometryLoader(this._content, this._accessorLoader, this._bufferViewLoader, this._materialLoader, dracoModule);
103
120
 
104
- const node = this.loadScene();
121
+ const eventProgressInit: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 0.1, status: 'Initial logic of glTF loading.' };
122
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventProgressInit);
123
+
124
+ const node = await this.loadScene();
105
125
 
106
126
  if (this._content.extensions && this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
107
127
  const variants = this._content.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS].variants;
@@ -146,6 +166,9 @@ export class GLTFLoader {
146
166
  if (this._content.animations)
147
167
  for (let i = 0; i < this._content.animations?.length; i++)
148
168
  node.data.push(this.loadAnimation(i));
169
+
170
+ const eventEnd: ITaskEvent = { type: TASK_TYPE.GLTF_CONTENT_LOADING, id: this._eventId, progress: 1, status: 'GlTF loading complete.' };
171
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
149
172
  return node;
150
173
  }
151
174
 
@@ -342,7 +365,7 @@ export class GLTFLoader {
342
365
  return lightNode;
343
366
  }
344
367
 
345
- private loadNode(nodeId: number): ITreeNode {
368
+ private async loadNode(nodeId: number): Promise<ITreeNode> {
346
369
  if (!this._content.nodes) throw new Error('Nodes not available.')
347
370
  if (!this._content.nodes[nodeId]) throw new Error('Node not available.')
348
371
  const node = this._content.nodes[nodeId];
@@ -401,14 +424,22 @@ export class GLTFLoader {
401
424
  if (node.children) {
402
425
  for (let i = 0, len = node.children.length; i < len; i++) {
403
426
  // got through all children
404
- nodeDef.addChild(this.loadNode(node.children[i]));
427
+ nodeDef.addChild(await this.loadNode(node.children[i]));
405
428
  }
406
429
  }
407
430
 
431
+ this._numberOfConvertedNodes++;
432
+ if(performance.now() - this._progressTimer > this._progressUpdateLimit) {
433
+ this._progressTimer = performance.now();
434
+ const eventProgress: ITaskEvent = { type: 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.` };
435
+ this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventProgress);
436
+ await new Promise(resolve => setTimeout(resolve, 0));
437
+ }
438
+
408
439
  return nodeDef;
409
440
  }
410
441
 
411
- private loadScene(): ITreeNode {
442
+ private async loadScene(): Promise<ITreeNode> {
412
443
  if (!this._content.scenes) throw new Error('Scenes not available.')
413
444
  const sceneId = this._content.scene || 0;
414
445
  if (!this._content.scenes[sceneId]) throw new Error('Scene not available.')
@@ -420,7 +451,7 @@ export class GLTFLoader {
420
451
  })
421
452
  if (scene.nodes)
422
453
  for (let i = 0, len = scene.nodes.length; i < len; i++)
423
- sceneDef.addChild(this.loadNode(scene.nodes[i]));
454
+ sceneDef.addChild(await this.loadNode(scene.nodes[i]));
424
455
  return sceneDef;
425
456
  }
426
457
 
@@ -1,40 +1,40 @@
1
1
  import { AttributeData } from '@shapediver/viewer.shared.types'
2
2
  import {
3
- ACCESSORCOMPONENTTYPE_V2 as ACCESSOR_COMPONENTTYPE,
4
- ACCESSORTYPE_V2 as ACCESSORTYPE,
5
- IGLTF_v2
3
+ ACCESSORCOMPONENTTYPE_V2 as ACCESSOR_COMPONENTTYPE,
4
+ ACCESSORTYPE_V2 as ACCESSORTYPE,
5
+ IGLTF_v2
6
6
  } from '@shapediver/viewer.data-engine.shared-types'
7
7
  import { Logger } from '@shapediver/viewer.shared.services'
8
8
 
9
9
  import { BufferViewLoader } from './BufferViewLoader'
10
10
 
11
11
  export class AccessorLoader {
12
- // #region Properties (2)
12
+ // #region Properties (2)
13
13
 
14
- private readonly _logger: Logger = Logger.instance;
14
+ private readonly _logger: Logger = Logger.instance;
15
15
 
16
- private _loaded: {
16
+ private _loaded: {
17
17
  [key: string]: AttributeData | null
18
18
  } = {};
19
19
 
20
- // #endregion Properties (2)
20
+ // #endregion Properties (2)
21
21
 
22
- // #region Constructors (1)
22
+ // #region Constructors (1)
23
23
 
24
- constructor(private readonly _content: IGLTF_v2, private readonly _bufferViewLoader: BufferViewLoader) { }
24
+ constructor(private readonly _content: IGLTF_v2, private readonly _bufferViewLoader: BufferViewLoader) { }
25
25
 
26
- // #endregion Constructors (1)
26
+ // #endregion Constructors (1)
27
27
 
28
- // #region Public Methods (2)
28
+ // #region Public Methods (2)
29
29
 
30
- public getAccessor(accessorId: number): AttributeData | null {
30
+ public getAccessor(accessorId: number): AttributeData | null {
31
31
  if (!this._content.accessors) throw new Error('AccessorLoader.getAccessor: Accessors not available.')
32
32
  if (!this._content.accessors[accessorId]) throw new Error('AccessorLoader.getAccessor: Accessor not available.')
33
33
  if (!this._loaded[accessorId]) throw new Error('AccessorLoader.getAccessor: Accessor not loaded.')
34
34
  return this._loaded[accessorId];
35
35
  }
36
36
 
37
- public load(): void {
37
+ public load(): void {
38
38
  if (!this._content.accessors) return;
39
39
  for (let i = 0; i < this._content.accessors.length; i++) {
40
40
  const accessorId = i;
@@ -60,6 +60,7 @@ export class AccessorLoader {
60
60
  const byteOffset = accessor.byteOffset || 0;
61
61
  const byteStride = accessor.bufferView !== undefined ? this._content.bufferViews ? this._content.bufferViews[accessor.bufferView].byteStride : undefined : undefined;
62
62
  const normalized = accessor.normalized === true;
63
+ const target = this._content.bufferViews ? this._content.bufferViews[accessor.bufferView].target : undefined;
63
64
  let array;
64
65
 
65
66
  if (byteStride && byteStride !== itemBytes) {
@@ -75,14 +76,6 @@ export class AccessorLoader {
75
76
  }
76
77
  }
77
78
 
78
- if (normalized) {
79
- const scale = this.getNormalizedComponentScale(ArrayType);
80
- const scaled = new Float32Array(array.length);
81
- for (let j = 0, jl = array.length; j < jl; j++)
82
- scaled[j] = array[j] * scale;
83
- array = scaled;
84
- }
85
-
86
79
  if (accessor.sparse !== undefined) {
87
80
  const itemSizeIndices = ACCESSORTYPE.SCALAR;
88
81
  const IndicesArrayType = ACCESSOR_COMPONENTTYPE[<keyof typeof ACCESSOR_COMPONENTTYPE>accessor.sparse.indices.componentType];
@@ -95,39 +88,13 @@ export class AccessorLoader {
95
88
  const sparseIndices = new IndicesArrayType(this._bufferViewLoader.getBufferView(accessor.sparse.indices.bufferView!), byteOffsetIndices, accessor.sparse.count * itemSizeIndices);
96
89
  const sparseValues = new ArrayType(this._bufferViewLoader.getBufferView(accessor.sparse.values.bufferView!), byteOffsetValues, accessor.sparse.count * itemSize);
97
90
 
98
- this._loaded[accessorId] = new AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride, true, sparseIndices, sparseValues);
91
+ this._loaded[accessorId] = new AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride, target, true, sparseIndices, sparseValues);
99
92
  continue;
100
93
  }
101
94
 
102
- this._loaded[accessorId] = new AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride);
103
- }
104
- }
105
-
106
- // #endregion Public Methods (2)
107
-
108
- // #region Private Methods (1)
109
-
110
- private getNormalizedComponentScale(constructor: Uint8ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor) {
111
- // Reference:
112
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
113
-
114
- switch (constructor) {
115
- case Int8Array:
116
- return 1 / 127;
117
-
118
- case Uint8Array:
119
- return 1 / 255;
120
-
121
- case Int16Array:
122
- return 1 / 32767;
123
-
124
- case Uint16Array:
125
- return 1 / 65535;
126
-
127
- default:
128
- throw new Error('THREE.GLTFLoader: Unsupported normalized accessor component type.');
95
+ this._loaded[accessorId] = new AttributeData(array, itemSize, itemBytes, byteOffset, elementBytes, normalized, accessor.count, accessor.min, accessor.max, byteStride, target);
129
96
  }
130
97
  }
131
98
 
132
- // #endregion Private Methods (1)
99
+ // #endregion Public Methods (2)
133
100
  }
@@ -193,21 +193,21 @@ export class GeometryLoader {
193
193
  if (primitive.material || primitive.material === 0)
194
194
  material = this._materialLoader.getMaterial(primitive.material);
195
195
 
196
- const primitiveData = new PrimitiveData(attributes, primitive.mode, indices, material);
196
+ const primitiveData = new PrimitiveData(attributes, indices);
197
+ const geometryData = new GeometryData(primitiveData, primitive.mode, material);
197
198
 
198
199
  if (primitive.extensions && primitive.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS]) {
199
- this._materialVariantsData.primitiveData.push(primitiveData);
200
+ this._materialVariantsData.geometryData.push(geometryData);
200
201
  const variantsExtension = primitive.extensions[GLTF_EXTENSIONS.KHR_MATERIALS_VARIANTS];
201
202
 
202
203
  for (let i = 0; i < variantsExtension.mappings.length; i++) {
203
204
  const mapping = variantsExtension.mappings[i];
204
205
  const material = this._materialLoader.getMaterial(mapping.material);
205
206
  for (let j = 0; j < mapping.variants.length; j++)
206
- primitiveData.materialVariants.push({ variant: mapping.variants[j], material });
207
+ geometryData.materialVariants.push({ variant: mapping.variants[j], material });
207
208
  }
208
209
  }
209
210
 
210
- const geometryData = new GeometryData(primitiveData);
211
211
  geometryData.morphWeights = weights;
212
212
  this._loaded['mesh_' + meshId + '_primitive_' + index] = geometryData;
213
213
 
@@ -66,12 +66,16 @@ export class MaterialLoader {
66
66
  if (materialExtensions[GLTF_EXTENSIONS.SHAPEDIVER_MATERIALS_PRESET]) {
67
67
  const materialPreset: ISHAPEDIVER_materials_preset = materialExtensions[GLTF_EXTENSIONS.SHAPEDIVER_MATERIALS_PRESET];
68
68
  promises.push(
69
- new Promise(async resolve => {
70
- const materialData = await this._materialEngine.loadPresetMaterial(materialPreset.materialpreset);
71
- materialData.name = material.name;
72
- materialData.color = materialPreset.color;
73
- this._loaded[materialId] = materialData;
74
- resolve();
69
+ new Promise<void>(async (resolve, reject) => {
70
+ try {
71
+ const materialData = await this._materialEngine.loadPresetMaterial(materialPreset.materialpreset);
72
+ materialData.name = material.name;
73
+ materialData.color = materialPreset.color;
74
+ this._loaded[materialId] = materialData;
75
+ resolve();
76
+ } catch (e) {
77
+ reject(e);
78
+ }
75
79
  })
76
80
  )
77
81
  continue;
@@ -1,5 +1,5 @@
1
1
  import { IGLTF_v2 } from '@shapediver/viewer.data-engine.shared-types'
2
- import { Converter, HttpClient, HttpResponse } from '@shapediver/viewer.shared.services'
2
+ import { Converter, HttpClient } from '@shapediver/viewer.shared.services'
3
3
 
4
4
  import { BufferViewLoader } from './BufferViewLoader'
5
5
 
@@ -54,28 +54,28 @@ export class TextureLoader {
54
54
  const dataUri = URL.createObjectURL(blob);
55
55
 
56
56
  promises.push(
57
- new Promise<void>(resolve => {
57
+ new Promise<void>((resolve, reject) => {
58
58
  this._httpClient.loadTexture(dataUri)
59
59
  .then(response => {
60
60
  this._converter.responseToImage(response).then(img => {
61
61
  this._loaded[textureId] = img;
62
62
  URL.revokeObjectURL(dataUri)
63
63
  resolve()
64
- });
64
+ }).catch(e => reject(e));
65
65
  })
66
66
  })
67
67
  );
68
68
  } else {
69
69
  const url = DATA_URI_REGEX.test(image.uri!) || HTTPS_URI_REGEX.test(image.uri!) ? image.uri : `${this._baseUri}/${image.uri}`;
70
70
  promises.push(
71
- new Promise<void>(resolve => {
71
+ new Promise<void>((resolve, reject) => {
72
72
  this._httpClient.loadTexture(url!)
73
73
  .then(response => {
74
74
  this._converter.responseToImage(response).then(img => {
75
75
  this._loaded[textureId] = img;
76
76
  resolve()
77
77
  });
78
- })
78
+ }).catch(e => reject(e));
79
79
  })
80
80
  );
81
81
  }