@shapediver/viewer.session-engine.session-engine 2.12.8 → 3.0.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.
- package/dist/implementation/OutputDelayException.js +1 -1
- package/dist/implementation/OutputDelayException.js.map +1 -1
- package/dist/implementation/OutputLoader.d.ts +9 -7
- package/dist/implementation/OutputLoader.d.ts.map +1 -1
- package/dist/implementation/OutputLoader.js +56 -41
- package/dist/implementation/OutputLoader.js.map +1 -1
- package/dist/implementation/SessionData.d.ts +1 -1
- package/dist/implementation/SessionData.d.ts.map +1 -1
- package/dist/implementation/SessionData.js +2 -2
- package/dist/implementation/SessionData.js.map +1 -1
- package/dist/implementation/SessionEngine.d.ts +30 -3
- package/dist/implementation/SessionEngine.d.ts.map +1 -1
- package/dist/implementation/SessionEngine.js +115 -48
- package/dist/implementation/SessionEngine.js.map +1 -1
- package/dist/implementation/SessionOutputData.d.ts +1 -1
- package/dist/implementation/SessionOutputData.d.ts.map +1 -1
- package/dist/implementation/SessionOutputData.js +2 -2
- package/dist/implementation/SessionOutputData.js.map +1 -1
- package/dist/implementation/SessionTreeNode.d.ts +1 -1
- package/dist/implementation/SessionTreeNode.d.ts.map +1 -1
- package/dist/implementation/SessionTreeNode.js +1 -1
- package/dist/implementation/SessionTreeNode.js.map +1 -1
- package/dist/implementation/dto/Export.d.ts +4 -4
- package/dist/implementation/dto/Export.d.ts.map +1 -1
- package/dist/implementation/dto/Export.js +2 -2
- package/dist/implementation/dto/Export.js.map +1 -1
- package/dist/implementation/dto/FileParameter.d.ts +2 -2
- package/dist/implementation/dto/FileParameter.d.ts.map +1 -1
- package/dist/implementation/dto/FileParameter.js +69 -31
- package/dist/implementation/dto/FileParameter.js.map +1 -1
- package/dist/implementation/dto/Output.js +2 -2
- package/dist/implementation/dto/Output.js.map +1 -1
- package/dist/implementation/dto/Parameter.d.ts +6 -6
- package/dist/implementation/dto/Parameter.d.ts.map +1 -1
- package/dist/implementation/dto/Parameter.js +106 -87
- package/dist/implementation/dto/Parameter.js.map +1 -1
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -10
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ISessionData.d.ts +2 -2
- package/dist/interfaces/ISessionData.d.ts.map +1 -1
- package/dist/interfaces/ISessionEngine.d.ts +11 -46
- package/dist/interfaces/ISessionEngine.d.ts.map +1 -1
- package/dist/interfaces/ISessionEngine.js +0 -4
- package/dist/interfaces/ISessionEngine.js.map +1 -1
- package/dist/interfaces/ISessionOutputData.d.ts +2 -2
- package/dist/interfaces/ISessionOutputData.d.ts.map +1 -1
- package/dist/interfaces/ISessionTreeNode.d.ts +1 -1
- package/dist/interfaces/dto/IExport.d.ts +2 -2
- package/dist/interfaces/dto/IExport.d.ts.map +1 -1
- package/dist/interfaces/dto/IFileParameter.d.ts +1 -1
- package/dist/interfaces/dto/IFileParameter.d.ts.map +1 -1
- package/dist/interfaces/dto/IOutput.d.ts +13 -13
- package/dist/interfaces/dto/IOutput.d.ts.map +1 -1
- package/dist/interfaces/dto/IOutput.js +1 -0
- package/dist/interfaces/dto/IOutput.js.map +1 -1
- package/dist/interfaces/dto/IParameter.d.ts +3 -3
- package/dist/interfaces/dto/IParameter.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/implementation/OutputDelayException.ts +3 -3
- package/src/implementation/OutputLoader.ts +139 -104
- package/src/implementation/SessionData.ts +9 -9
- package/src/implementation/SessionEngine.ts +133 -53
- package/src/implementation/SessionOutputData.ts +8 -8
- package/src/implementation/SessionTreeNode.ts +8 -5
- package/src/implementation/dto/Export.ts +24 -11
- package/src/implementation/dto/FileParameter.ts +72 -37
- package/src/implementation/dto/Output.ts +2 -2
- package/src/implementation/dto/Parameter.ts +115 -85
- package/src/index.ts +17 -21
- package/src/interfaces/ISessionData.ts +2 -2
- package/src/interfaces/ISessionEngine.ts +19 -60
- package/src/interfaces/ISessionOutputData.ts +2 -2
- package/src/interfaces/ISessionTreeNode.ts +1 -1
- package/src/interfaces/dto/IExport.ts +4 -4
- package/src/interfaces/dto/IFileParameter.ts +2 -2
- package/src/interfaces/dto/IOutput.ts +38 -26
- package/src/interfaces/dto/IParameter.ts +3 -3
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import {
|
|
2
|
+
AbstractMaterialData,
|
|
3
|
+
GeometryData,
|
|
4
|
+
IMaterialAbstractData,
|
|
5
|
+
ITaskEvent,
|
|
6
|
+
TASK_TYPE
|
|
7
|
+
} from '@shapediver/viewer.shared.types';
|
|
8
|
+
import {
|
|
9
|
+
EventEngine,
|
|
10
|
+
EVENTTYPE,
|
|
11
|
+
IEvent,
|
|
12
|
+
PerformanceEvaluator
|
|
13
|
+
} from '@shapediver/viewer.shared.services';
|
|
14
|
+
import { ISessionEngine } from '../interfaces/ISessionEngine';
|
|
15
|
+
import { ISessionTreeNode } from '../interfaces/ISessionTreeNode';
|
|
16
|
+
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
17
|
+
import { OutputDelayException } from './OutputDelayException';
|
|
18
|
+
import { SessionOutputData } from './SessionOutputData';
|
|
19
|
+
import { SessionTreeNode } from './SessionTreeNode';
|
|
20
|
+
import { ShapeDiverResponseOutput, ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
21
|
+
|
|
22
|
+
// #region Type aliases (1)
|
|
12
23
|
|
|
13
24
|
export type OutputLoaderTaskEventInfo = {
|
|
14
25
|
eventId: string,
|
|
@@ -17,27 +28,33 @@ export type OutputLoaderTaskEventInfo = {
|
|
|
17
28
|
min: number,
|
|
18
29
|
max: number
|
|
19
30
|
},
|
|
20
|
-
data:
|
|
31
|
+
data: unknown
|
|
21
32
|
}
|
|
22
33
|
|
|
34
|
+
// #endregion Type aliases (1)
|
|
35
|
+
|
|
36
|
+
// #region Classes (1)
|
|
37
|
+
|
|
23
38
|
export class OutputLoader {
|
|
24
|
-
// #region Properties (
|
|
39
|
+
// #region Properties (6)
|
|
25
40
|
|
|
26
|
-
private readonly _dataEngine:
|
|
41
|
+
private readonly _dataEngine?: { loadContent: (content: ShapeDiverResponseOutputContent, jwtToken?: string, taskEventId?: string) => Promise<ITreeNode> };
|
|
27
42
|
private readonly _eventEngine: EventEngine = EventEngine.instance;
|
|
28
|
-
private readonly
|
|
43
|
+
private readonly _lastOutputNodes: {
|
|
29
44
|
[key: string]: {
|
|
30
45
|
[key: string]: ISessionTreeNode
|
|
31
|
-
};
|
|
46
|
+
};
|
|
32
47
|
} = {};
|
|
33
|
-
private readonly
|
|
48
|
+
private readonly _loadedOutputNodes: {
|
|
34
49
|
[key: string]: {
|
|
35
50
|
[key: string]: ISessionTreeNode
|
|
36
|
-
};
|
|
51
|
+
};
|
|
37
52
|
} = {};
|
|
38
53
|
private readonly _performanceEvaluator: PerformanceEvaluator = PerformanceEvaluator.instance;
|
|
39
54
|
|
|
40
|
-
|
|
55
|
+
private _reloadSdtf = false;
|
|
56
|
+
|
|
57
|
+
// #endregion Properties (6)
|
|
41
58
|
|
|
42
59
|
// #region Constructors (1)
|
|
43
60
|
|
|
@@ -46,11 +63,38 @@ export class OutputLoader {
|
|
|
46
63
|
*
|
|
47
64
|
* @param _session the session for this output loader
|
|
48
65
|
*/
|
|
49
|
-
constructor(private readonly _sessionEngine: ISessionEngine) {
|
|
66
|
+
constructor(private readonly _sessionEngine: ISessionEngine) {
|
|
67
|
+
try {
|
|
68
|
+
// Attempt to load the package
|
|
69
|
+
require.resolve('@shapediver/viewer.data-engine.data-engine');
|
|
70
|
+
|
|
71
|
+
// If the package is installed, set the exported properties
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
73
|
+
this._dataEngine = require('@shapediver/viewer.data-engine.data-engine').DataEngine.instance;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// data engine not available
|
|
76
|
+
}
|
|
77
|
+
}
|
|
50
78
|
|
|
51
79
|
// #endregion Constructors (1)
|
|
52
80
|
|
|
53
|
-
// #region Public
|
|
81
|
+
// #region Public Getters And Setters (1)
|
|
82
|
+
|
|
83
|
+
public set reloadSdtf(value: boolean) {
|
|
84
|
+
this._reloadSdtf = value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// #endregion Public Getters And Setters (1)
|
|
88
|
+
|
|
89
|
+
// #region Public Methods (2)
|
|
90
|
+
|
|
91
|
+
public getCurrentOutputVersions(): { [key: string]: string } {
|
|
92
|
+
const versions: { [key: string]: string } = {};
|
|
93
|
+
for (const o in this._lastOutputNodes)
|
|
94
|
+
versions[o] = Object.keys(this._lastOutputNodes[o])[0];
|
|
95
|
+
|
|
96
|
+
return versions;
|
|
97
|
+
}
|
|
54
98
|
|
|
55
99
|
/**
|
|
56
100
|
* Load the outputs and return the scene graph node of the result.
|
|
@@ -59,23 +103,25 @@ export class OutputLoader {
|
|
|
59
103
|
* @param outputs the outputs to load
|
|
60
104
|
* @returns promise with a scene graph node
|
|
61
105
|
*/
|
|
62
|
-
|
|
106
|
+
public async loadOutputs(nodeName: string, outputs: { [key: string]: ShapeDiverResponseOutput; }, outputsFreeze: { [key: string]: boolean; }, taskEventInfo: OutputLoaderTaskEventInfo, throwDelay = true): Promise<SessionTreeNode> {
|
|
63
107
|
this._performanceEvaluator.startSection('outputLoading');
|
|
64
108
|
const node = new SessionTreeNode(nodeName);
|
|
65
|
-
|
|
109
|
+
const currentNodes: {
|
|
66
110
|
[key: string]: {
|
|
67
111
|
[key: string]: ISessionTreeNode
|
|
68
|
-
};
|
|
112
|
+
};
|
|
113
|
+
} = {};
|
|
114
|
+
const outputInfo: {
|
|
115
|
+
[key: string]: {
|
|
116
|
+
version: string,
|
|
117
|
+
contentFormat: string[],
|
|
118
|
+
}
|
|
69
119
|
} = {};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
contentFormat: string[],
|
|
73
|
-
} } = {};
|
|
74
|
-
let promises: Promise<ITreeNode>[] = [];
|
|
75
|
-
let promisesNodes: ISessionTreeNode[] = [];
|
|
120
|
+
const promises: Promise<ITreeNode>[] = [];
|
|
121
|
+
const promisesNodes: ISessionTreeNode[] = [];
|
|
76
122
|
let maxDelay = 0;
|
|
77
123
|
|
|
78
|
-
|
|
124
|
+
const progress: {
|
|
79
125
|
[key: string]: number
|
|
80
126
|
} = {};
|
|
81
127
|
|
|
@@ -83,7 +129,7 @@ export class OutputLoader {
|
|
|
83
129
|
|
|
84
130
|
const cb = (e: IEvent) => {
|
|
85
131
|
const taskEvent = e as ITaskEvent;
|
|
86
|
-
if(outputIDs.find(oId => taskEvent.id.startsWith(oId))) {
|
|
132
|
+
if (outputIDs.find(oId => taskEvent.id.startsWith(oId))) {
|
|
87
133
|
progress[taskEvent.id] = taskEvent.progress;
|
|
88
134
|
|
|
89
135
|
let sum = 0;
|
|
@@ -93,38 +139,46 @@ export class OutputLoader {
|
|
|
93
139
|
const eventProgressUpdate: ITaskEvent = { type: taskEventInfo.type, id: taskEventInfo.eventId, progress: outputLoadingProgress, data: taskEventInfo.data, status: 'Output content loading progress.' };
|
|
94
140
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventProgressUpdate);
|
|
95
141
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const listenerTokens = [];
|
|
99
145
|
listenerTokens.push(this._eventEngine.addListener(EVENTTYPE.TASK.TASK_START, cb));
|
|
100
146
|
listenerTokens.push(this._eventEngine.addListener(EVENTTYPE.TASK.TASK_PROCESS, cb));
|
|
101
147
|
listenerTokens.push(this._eventEngine.addListener(EVENTTYPE.TASK.TASK_CANCEL, cb));
|
|
102
148
|
listenerTokens.push(this._eventEngine.addListener(EVENTTYPE.TASK.TASK_END, cb));
|
|
103
149
|
|
|
104
|
-
for (
|
|
150
|
+
for (const outputID in outputs) {
|
|
105
151
|
// we store some necessary information as this data may have been changed after the await (see warning below)
|
|
106
152
|
outputInfo[outputID] = {
|
|
107
153
|
version: outputs[outputID].version,
|
|
108
154
|
contentFormat: outputs[outputID].content ? outputs[outputID].content!.map(c => c.format) : []
|
|
109
|
-
}
|
|
155
|
+
};
|
|
110
156
|
|
|
111
157
|
currentNodes[outputID] = {};
|
|
112
|
-
if(!this._loadedOutputNodes[outputID])
|
|
158
|
+
if (!this._loadedOutputNodes[outputID])
|
|
113
159
|
this._loadedOutputNodes[outputID] = {};
|
|
114
|
-
|
|
115
|
-
if(
|
|
160
|
+
|
|
161
|
+
if (this._reloadSdtf && outputs[outputID].content) {
|
|
162
|
+
const sdtfContents = outputs[outputID].content?.filter(c => c.format === 'sdtf');
|
|
163
|
+
if(sdtfContents && sdtfContents.length > 0)
|
|
164
|
+
delete this._loadedOutputNodes[outputID][outputInfo[outputID].version];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (outputsFreeze[outputID]) {
|
|
116
168
|
currentNodes[outputID][outputInfo[outputID].version] = this._lastOutputNodes[outputID][outputInfo[outputID].version];
|
|
117
169
|
// no loading necessary, progress done
|
|
118
170
|
progress[outputID] = 1;
|
|
119
|
-
} else if(outputs[outputID].delay) {
|
|
171
|
+
} else if (outputs[outputID].delay) {
|
|
120
172
|
maxDelay = Math.max(maxDelay, outputs[outputID].delay!);
|
|
121
|
-
} else if(!this._loadedOutputNodes[outputID][outputInfo[outputID].version]) {
|
|
173
|
+
} else if (!this._loadedOutputNodes[outputID][outputInfo[outputID].version]) {
|
|
122
174
|
currentNodes[outputID][outputInfo[outputID].version] = new SessionTreeNode(outputID);
|
|
123
175
|
currentNodes[outputID][outputInfo[outputID].version].data.push(new SessionOutputData(outputs[outputID]));
|
|
124
|
-
if(outputs[outputID].content) {
|
|
176
|
+
if (outputs[outputID].content) {
|
|
125
177
|
for (let i = 0, len = outputs[outputID].content!.length; i < len; i++) {
|
|
126
|
-
|
|
127
|
-
|
|
178
|
+
if (outputs[outputID].content![i].format === 'sdtf' && !this._sessionEngine.loadSdtf) continue;
|
|
179
|
+
if (this._dataEngine)
|
|
180
|
+
promises.push(this._dataEngine.loadContent(outputs[outputID].content![i], this._sessionEngine.jwtToken, outputID + '_' + outputInfo[outputID].version + '_' + i));
|
|
181
|
+
promisesNodes.push(currentNodes[outputID][outputInfo[outputID].version]);
|
|
128
182
|
}
|
|
129
183
|
}
|
|
130
184
|
} else {
|
|
@@ -134,7 +188,7 @@ export class OutputLoader {
|
|
|
134
188
|
}
|
|
135
189
|
}
|
|
136
190
|
|
|
137
|
-
if(maxDelay && throwDelay)
|
|
191
|
+
if (maxDelay && throwDelay)
|
|
138
192
|
throw new OutputDelayException(maxDelay);
|
|
139
193
|
|
|
140
194
|
/**
|
|
@@ -148,29 +202,29 @@ export class OutputLoader {
|
|
|
148
202
|
listenerTokens.forEach(t => this._eventEngine.removeListener(t));
|
|
149
203
|
|
|
150
204
|
// all promises are resolved, await in the next lines is just for structural purposes
|
|
151
|
-
for(let i = 0; i < promises.length; i++)
|
|
152
|
-
promisesNodes[i].addChild(await promises[i])
|
|
205
|
+
for (let i = 0; i < promises.length; i++)
|
|
206
|
+
promisesNodes[i].addChild(await promises[i]);
|
|
153
207
|
|
|
154
208
|
// here we assign all outputs just to the node and return it
|
|
155
|
-
for (
|
|
156
|
-
if(currentNodes[outputID][outputInfo[outputID].version])
|
|
209
|
+
for (const outputID in outputInfo)
|
|
210
|
+
if (currentNodes[outputID][outputInfo[outputID].version])
|
|
157
211
|
node.addChild(currentNodes[outputID][outputInfo[outputID].version]);
|
|
158
212
|
|
|
159
213
|
// save the nodes as the last available version
|
|
160
|
-
for (
|
|
161
|
-
if(!currentNodes[outputID][outputInfo[outputID].version]) continue;
|
|
214
|
+
for (const outputID in outputInfo) {
|
|
215
|
+
if (!currentNodes[outputID][outputInfo[outputID].version]) continue;
|
|
162
216
|
this._loadedOutputNodes[outputID] = {};
|
|
163
217
|
this._loadedOutputNodes[outputID][outputInfo[outputID].version] = currentNodes[outputID][outputInfo[outputID].version];
|
|
164
218
|
this._lastOutputNodes[outputID] = {};
|
|
165
219
|
this._lastOutputNodes[outputID][outputInfo[outputID].version] = currentNodes[outputID][outputInfo[outputID].version];
|
|
166
220
|
}
|
|
167
221
|
|
|
168
|
-
for (
|
|
169
|
-
if(!currentNodes[outputID][outputInfo[outputID].version]) continue;
|
|
170
|
-
if(currentNodes[outputID][outputInfo[outputID].version].children.length > 1) {
|
|
222
|
+
for (const outputID in outputInfo) {
|
|
223
|
+
if (!currentNodes[outputID][outputInfo[outputID].version]) continue;
|
|
224
|
+
if (currentNodes[outputID][outputInfo[outputID].version].children.length > 1) {
|
|
171
225
|
for (let i = 0, len = outputInfo[outputID].contentFormat!.length; i < len; i++) {
|
|
172
|
-
if(outputInfo[outputID].contentFormat[i] === 'sdtf') {
|
|
173
|
-
this.mergeContentNodes(currentNodes[outputID][outputInfo[outputID].version])
|
|
226
|
+
if (outputInfo[outputID].contentFormat[i] === 'sdtf' && this._sessionEngine.loadSdtf === true) {
|
|
227
|
+
this.mergeContentNodes(currentNodes[outputID][outputInfo[outputID].version]);
|
|
174
228
|
break;
|
|
175
229
|
}
|
|
176
230
|
}
|
|
@@ -182,15 +236,7 @@ export class OutputLoader {
|
|
|
182
236
|
return node;
|
|
183
237
|
}
|
|
184
238
|
|
|
185
|
-
|
|
186
|
-
const versions: { [key: string]: string } = {};
|
|
187
|
-
for(const o in this._lastOutputNodes)
|
|
188
|
-
versions[o] = Object.keys(this._lastOutputNodes[o])[0];
|
|
189
|
-
|
|
190
|
-
return versions;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// #endregion Public Methods (1)
|
|
239
|
+
// #endregion Public Methods (2)
|
|
194
240
|
|
|
195
241
|
// #region Private Methods (2)
|
|
196
242
|
|
|
@@ -200,7 +246,7 @@ export class OutputLoader {
|
|
|
200
246
|
if (node.data[i] instanceof GeometryData) {
|
|
201
247
|
const geometry = <GeometryData>node.data[i];
|
|
202
248
|
const currentMaterial = geometry.material;
|
|
203
|
-
if(currentMaterial === null || currentMaterial.materialOutput === true) {
|
|
249
|
+
if (currentMaterial === null || currentMaterial.materialOutput === true) {
|
|
204
250
|
geometry.material = material;
|
|
205
251
|
}
|
|
206
252
|
}
|
|
@@ -220,28 +266,15 @@ export class OutputLoader {
|
|
|
220
266
|
materials.push(material);
|
|
221
267
|
}
|
|
222
268
|
}
|
|
223
|
-
|
|
269
|
+
|
|
224
270
|
for (let k = 0; k < node.children.length; k++) {
|
|
225
271
|
const child = node.children[k];
|
|
226
|
-
if(!child) continue;
|
|
272
|
+
if (!child) continue;
|
|
227
273
|
materials.push(...getMaterialData(child));
|
|
228
274
|
}
|
|
229
275
|
|
|
230
276
|
return materials;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const getGeometryData = (node: ITreeNode, geometries: GeometryData[] = []): GeometryData[] => {
|
|
234
|
-
for (let k = 0; k < node.data.length; k++)
|
|
235
|
-
if (node.data[k] instanceof GeometryData)
|
|
236
|
-
geometries.push(<GeometryData>node.data[k]);
|
|
237
|
-
|
|
238
|
-
for (let k = 0; k < node.children.length; k++) {
|
|
239
|
-
const child = node.children[k];
|
|
240
|
-
if(!child) continue;
|
|
241
|
-
geometries.push(...getGeometryData(child));
|
|
242
|
-
}
|
|
243
|
-
return geometries;
|
|
244
|
-
}
|
|
277
|
+
};
|
|
245
278
|
|
|
246
279
|
for (let m = 0; m < node.children.length; m++) {
|
|
247
280
|
// per output node, we go through the material assignment process
|
|
@@ -251,13 +284,13 @@ export class OutputLoader {
|
|
|
251
284
|
// we go through all data properties, normally, there should ony one, but we just make sure
|
|
252
285
|
for (let i = 0; i < outputNode.data.length; i++) {
|
|
253
286
|
if (!(outputNode.data[i] instanceof SessionOutputData)) continue;
|
|
254
|
-
|
|
287
|
+
|
|
255
288
|
// the session output data contains information about this Output
|
|
256
289
|
// most importantly the SessionOutput property with the material and content in it
|
|
257
290
|
const sessionOutputData = <SessionOutputData>outputNode.data[i];
|
|
258
291
|
|
|
259
292
|
// case 1: we have a specific material id defined, let's use that
|
|
260
|
-
if(sessionOutputData.responseOutput.material) {
|
|
293
|
+
if (sessionOutputData.responseOutput.material) {
|
|
261
294
|
let materialNodes: ITreeNode[] = [];
|
|
262
295
|
// now we have id
|
|
263
296
|
// get material with it
|
|
@@ -270,7 +303,7 @@ export class OutputLoader {
|
|
|
270
303
|
|
|
271
304
|
const geometryNodes = outputNode.children;
|
|
272
305
|
|
|
273
|
-
if(materialNodes.length >= geometryNodes.length) {
|
|
306
|
+
if (materialNodes.length >= geometryNodes.length) {
|
|
274
307
|
for (let n = 0; n < geometryNodes.length; n++) {
|
|
275
308
|
addMaterialToGeometry(geometryNodes[n], getMaterialData(materialNodes[n])[0]);
|
|
276
309
|
}
|
|
@@ -280,25 +313,25 @@ export class OutputLoader {
|
|
|
280
313
|
addMaterialToGeometry(geometryNodes[n], getMaterialData(materialNodes[0])[0]);
|
|
281
314
|
}
|
|
282
315
|
}
|
|
283
|
-
}
|
|
316
|
+
}
|
|
284
317
|
// case 2: there is no specific material id defined, maybe in the content we can match geometries to ids
|
|
285
318
|
else {
|
|
286
319
|
// now we hope that in our content, there are exactly the amount of geometries and material, this will be interesting :)
|
|
287
320
|
|
|
288
321
|
const sessionOutputContent = sessionOutputData.responseOutput.content;
|
|
289
|
-
if(sessionOutputContent === undefined) continue;
|
|
322
|
+
if (sessionOutputContent === undefined) continue;
|
|
290
323
|
|
|
291
324
|
const materialNodes = [];
|
|
292
325
|
const geometryNodes = [];
|
|
293
|
-
for(let i = 0; i < sessionOutputContent.length; i++) {
|
|
294
|
-
if(sessionOutputContent[i].format === 'material') {
|
|
295
|
-
materialNodes.push(outputNode.children[i]);
|
|
326
|
+
for (let i = 0; i < sessionOutputContent.length; i++) {
|
|
327
|
+
if (sessionOutputContent[i].format === 'material') {
|
|
328
|
+
if (outputNode.children[i]) materialNodes.push(outputNode.children[i]);
|
|
296
329
|
} else {
|
|
297
|
-
geometryNodes.push(outputNode.children[i]);
|
|
330
|
+
if (outputNode.children[i]) geometryNodes.push(outputNode.children[i]);
|
|
298
331
|
}
|
|
299
332
|
}
|
|
300
333
|
|
|
301
|
-
if(materialNodes.length >= geometryNodes.length) {
|
|
334
|
+
if (materialNodes.length >= geometryNodes.length) {
|
|
302
335
|
for (let n = 0; n < geometryNodes.length; n++) {
|
|
303
336
|
addMaterialToGeometry(geometryNodes[n], getMaterialData(materialNodes[n])[0]);
|
|
304
337
|
}
|
|
@@ -314,40 +347,42 @@ export class OutputLoader {
|
|
|
314
347
|
}
|
|
315
348
|
|
|
316
349
|
private mergeContentNodes(node: ISessionTreeNode) {
|
|
317
|
-
if(!(node.children.length > 1)) return;
|
|
350
|
+
if (!(node.children.length > 1)) return;
|
|
318
351
|
|
|
319
352
|
const children = [];
|
|
320
|
-
while(node.children.length > 0) {
|
|
353
|
+
while (node.children.length > 0) {
|
|
321
354
|
children.push(...node.children[0].children);
|
|
322
355
|
node.removeChild(node.children[0]);
|
|
323
356
|
}
|
|
324
357
|
|
|
325
358
|
const mergeNodes = (node1: ITreeNode, node2: ITreeNode) => {
|
|
326
|
-
for(let i = 0; i < node1.data.length; i++)
|
|
359
|
+
for (let i = 0; i < node1.data.length; i++)
|
|
327
360
|
node2.data.push(node1.data[i]);
|
|
328
361
|
|
|
329
|
-
for(let i = 0; i < node1.children.length; i++) {
|
|
362
|
+
for (let i = 0; i < node1.children.length; i++) {
|
|
330
363
|
let childNode;
|
|
331
|
-
for(let j = 0; j < node2.children.length; j++) {
|
|
332
|
-
if(node1.children[i].name === node2.children[j].name) {
|
|
364
|
+
for (let j = 0; j < node2.children.length; j++) {
|
|
365
|
+
if (node1.children[i].name === node2.children[j].name) {
|
|
333
366
|
childNode = node2.children[j];
|
|
334
367
|
break;
|
|
335
368
|
}
|
|
336
369
|
}
|
|
337
|
-
if(!childNode) {
|
|
370
|
+
if (!childNode) {
|
|
338
371
|
childNode = new TreeNode(node1.children[i].name);
|
|
339
372
|
node2.addChild(childNode);
|
|
340
373
|
}
|
|
341
374
|
|
|
342
375
|
mergeNodes(node1.children[i], childNode);
|
|
343
376
|
}
|
|
344
|
-
}
|
|
377
|
+
};
|
|
345
378
|
|
|
346
379
|
const newChild = new TreeNode('content_array');
|
|
347
380
|
node.addChild(newChild);
|
|
348
|
-
for(let i = 0; i < children.length; i++)
|
|
349
|
-
mergeNodes(children[i], newChild)
|
|
381
|
+
for (let i = 0; i < children.length; i++)
|
|
382
|
+
mergeNodes(children[i], newChild);
|
|
350
383
|
}
|
|
351
384
|
|
|
352
385
|
// #endregion Private Methods (2)
|
|
353
|
-
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// #endregion Classes (1)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractTreeNodeData, ITreeNodeData } from '@shapediver/viewer.shared.node-tree'
|
|
1
|
+
import { AbstractTreeNodeData } from '@shapediver/viewer.shared.node-tree';
|
|
3
2
|
import { ISessionData } from '../interfaces/ISessionData';
|
|
3
|
+
import { ShapeDiverResponseDto } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
4
4
|
|
|
5
5
|
export class SessionData extends AbstractTreeNodeData implements ISessionData {
|
|
6
6
|
// #region Properties (1)
|
|
@@ -11,7 +11,7 @@ export class SessionData extends AbstractTreeNodeData implements ISessionData {
|
|
|
11
11
|
|
|
12
12
|
// #region Constructors (1)
|
|
13
13
|
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(
|
|
15
15
|
responseDto: ShapeDiverResponseDto,
|
|
16
16
|
id?: string,
|
|
17
17
|
version?: string
|
|
@@ -22,17 +22,17 @@ export class SessionData extends AbstractTreeNodeData implements ISessionData {
|
|
|
22
22
|
|
|
23
23
|
// #endregion Constructors (1)
|
|
24
24
|
|
|
25
|
-
// #region Public
|
|
25
|
+
// #region Public Getters And Setters (2)
|
|
26
26
|
|
|
27
27
|
public get responseDto(): ShapeDiverResponseDto {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
return this.#responseDto;
|
|
29
|
+
}
|
|
30
30
|
|
|
31
31
|
public set responseDto(value: ShapeDiverResponseDto) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
this.#responseDto = value;
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
// #endregion Public
|
|
35
|
+
// #endregion Public Getters And Setters (2)
|
|
36
36
|
|
|
37
37
|
// #region Public Methods (1)
|
|
38
38
|
|