@shapediver/viewer.session-engine.session-engine 2.9.10 → 2.10.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 -5
- package/dist/implementation/OutputDelayException.js.map +1 -1
- package/dist/implementation/OutputLoader.js +26 -30
- package/dist/implementation/OutputLoader.js.map +1 -1
- package/dist/implementation/SessionData.js +2 -6
- package/dist/implementation/SessionData.js.map +1 -1
- package/dist/implementation/SessionEngine.d.ts +7 -4
- package/dist/implementation/SessionEngine.d.ts.map +1 -1
- package/dist/implementation/SessionEngine.js +180 -150
- package/dist/implementation/SessionEngine.js.map +1 -1
- package/dist/implementation/SessionOutputData.js +2 -6
- package/dist/implementation/SessionOutputData.js.map +1 -1
- package/dist/implementation/SessionTreeNode.js +2 -6
- package/dist/implementation/SessionTreeNode.js.map +1 -1
- package/dist/implementation/dto/Export.js +13 -17
- package/dist/implementation/dto/Export.js.map +1 -1
- package/dist/implementation/dto/FileParameter.js +7 -30
- package/dist/implementation/dto/FileParameter.js.map +1 -1
- package/dist/implementation/dto/Output.d.ts +1 -0
- package/dist/implementation/dto/Output.d.ts.map +1 -1
- package/dist/implementation/dto/Output.js +7 -9
- package/dist/implementation/dto/Output.js.map +1 -1
- package/dist/implementation/dto/Parameter.js +33 -56
- package/dist/implementation/dto/Parameter.js.map +1 -1
- package/dist/index.js +11 -20
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ISessionData.js +1 -2
- package/dist/interfaces/ISessionEngine.d.ts +4 -1
- package/dist/interfaces/ISessionEngine.d.ts.map +1 -1
- package/dist/interfaces/ISessionEngine.js +4 -7
- package/dist/interfaces/ISessionEngine.js.map +1 -1
- package/dist/interfaces/ISessionOutputData.js +1 -2
- package/dist/interfaces/ISessionTreeNode.js +1 -2
- package/dist/interfaces/dto/IExport.js +1 -2
- package/dist/interfaces/dto/IFileParameter.js +1 -2
- package/dist/interfaces/dto/IOutput.d.ts +1 -0
- package/dist/interfaces/dto/IOutput.d.ts.map +1 -1
- package/dist/interfaces/dto/IOutput.js +1 -2
- package/dist/interfaces/dto/IParameter.js +1 -2
- package/package.json +10 -10
- package/src/implementation/SessionEngine.ts +63 -18
- package/src/implementation/dto/Output.ts +2 -0
- package/src/interfaces/ISessionEngine.ts +4 -1
- package/src/interfaces/dto/IOutput.ts +1 -0
|
@@ -5,7 +5,7 @@ import { OutputLoader, OutputLoaderTaskEventInfo } from './OutputLoader'
|
|
|
5
5
|
import { SessionTreeNode } from './SessionTreeNode'
|
|
6
6
|
import { ISessionEngine, ISettingsSections, PARAMETER_TYPE } from '../interfaces/ISessionEngine'
|
|
7
7
|
import { SessionData } from './SessionData'
|
|
8
|
-
import { create, ShapeDiverError as ShapeDiverBackendError, ShapeDiverResponseErrorType, ShapeDiverRequestGltfUploadQueryConversion, ShapeDiverResponseDto, ShapeDiverResponseError, ShapeDiverResponseExport, ShapeDiverResponseExportDefinitionType, ShapeDiverResponseOutput, ShapeDiverResponseParameter, ShapeDiverSdk, ShapeDiverSdkConfigType, ShapeDiverResponseModelComputationStatus, ShapeDiverRequestError } from '@shapediver/sdk.geometry-api-sdk-v2'
|
|
8
|
+
import { create, ShapeDiverError as ShapeDiverBackendError, ShapeDiverResponseErrorType, ShapeDiverRequestGltfUploadQueryConversion, ShapeDiverResponseDto, ShapeDiverResponseError, ShapeDiverResponseExport, ShapeDiverResponseExportDefinitionType, ShapeDiverResponseOutput, ShapeDiverResponseParameter, ShapeDiverSdk, ShapeDiverSdkConfigType, ShapeDiverResponseModelComputationStatus, ShapeDiverRequestError, isGBResponseError } from '@shapediver/sdk.geometry-api-sdk-v2'
|
|
9
9
|
import { ISessionTreeNode } from '../interfaces/ISessionTreeNode'
|
|
10
10
|
import { ITree, ITreeNode, Tree, TreeNode } from '@shapediver/viewer.shared.node-tree'
|
|
11
11
|
import { ITaskEvent, TASK_TYPE } from '@shapediver/viewer.shared.types'
|
|
@@ -18,13 +18,14 @@ import { Parameter } from './dto/Parameter'
|
|
|
18
18
|
import { vec3 } from 'gl-matrix'
|
|
19
19
|
import { Export } from './dto/Export'
|
|
20
20
|
import { Output } from './dto/Output'
|
|
21
|
-
import { convert,
|
|
21
|
+
import { convert, ISettings, latestVersion, validate, versions } from '@shapediver/viewer.settings'
|
|
22
22
|
|
|
23
23
|
export class SessionEngine implements ISessionEngine {
|
|
24
24
|
// #region Properties (43)
|
|
25
25
|
|
|
26
26
|
private readonly _eventEngine = EventEngine.instance;
|
|
27
27
|
private readonly _exports: { [key: string]: IExport; } = {};
|
|
28
|
+
private readonly _guid?: string;
|
|
28
29
|
private readonly _httpClient: HttpClient = HttpClient.instance;
|
|
29
30
|
private readonly _id: string;
|
|
30
31
|
private readonly _logger: Logger = Logger.instance;
|
|
@@ -39,7 +40,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
39
40
|
private readonly _sessionEngineId = (UuidGenerator.instance).create();
|
|
40
41
|
private readonly _settingsEngine: SettingsEngine = new SettingsEngine();
|
|
41
42
|
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
42
|
-
private readonly _ticket
|
|
43
|
+
private readonly _ticket?: string;
|
|
43
44
|
private readonly _uuidGenerator = UuidGenerator.instance;
|
|
44
45
|
|
|
45
46
|
#customizationProcess!: string;
|
|
@@ -89,12 +90,13 @@ export class SessionEngine implements ISessionEngine {
|
|
|
89
90
|
// #region Constructors (1)
|
|
90
91
|
|
|
91
92
|
/**
|
|
92
|
-
* Can be use to initialize a session with the ticket and modelViewUrl and returns a scene graph node with the result.
|
|
93
|
+
* Can be use to initialize a session with the ticket/guid and modelViewUrl and returns a scene graph node with the result.
|
|
93
94
|
* Can be use to customize the session with updated parameters to get the updated scene graph node.
|
|
94
95
|
*/
|
|
95
|
-
constructor(properties: { id: string, ticket
|
|
96
|
+
constructor(properties: { id: string, ticket?: string, guid?: string, modelViewUrl: string, buildVersion: string, buildDate: string, jwtToken?: string, excludeViewports?: string[] }) {
|
|
96
97
|
this._id = properties.id;
|
|
97
98
|
this._node = new TreeNode(properties.id);
|
|
99
|
+
this._guid = properties.guid;
|
|
98
100
|
this._ticket = properties.ticket;
|
|
99
101
|
this._modelViewUrl = properties.modelViewUrl;
|
|
100
102
|
this._excludeViewports = properties.excludeViewports || [];
|
|
@@ -154,6 +156,10 @@ export class SessionEngine implements ISessionEngine {
|
|
|
154
156
|
return this._exports;
|
|
155
157
|
}
|
|
156
158
|
|
|
159
|
+
public get guid(): string | undefined {
|
|
160
|
+
return this._guid;
|
|
161
|
+
}
|
|
162
|
+
|
|
157
163
|
public get id(): string {
|
|
158
164
|
return this._id;
|
|
159
165
|
}
|
|
@@ -202,7 +208,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
202
208
|
return this._settingsEngine;
|
|
203
209
|
}
|
|
204
210
|
|
|
205
|
-
public get ticket(): string {
|
|
211
|
+
public get ticket(): string | undefined {
|
|
206
212
|
return this._ticket;
|
|
207
213
|
}
|
|
208
214
|
|
|
@@ -235,7 +241,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
235
241
|
if (sections.session.export === undefined)
|
|
236
242
|
sections.session.export = { displayname: false, order: false, hidden: false };
|
|
237
243
|
if (sections.viewport === undefined)
|
|
238
|
-
sections.viewport = { ar: false, scene: false, camera: false, light: false, environment: false, general: false };
|
|
244
|
+
sections.viewport = { ar: false, scene: false, camera: false, light: false, environment: false, general: false, postprocessing: false };
|
|
239
245
|
|
|
240
246
|
let config: object;
|
|
241
247
|
if ((<ShapeDiverResponseDto>response).viewer !== undefined) {
|
|
@@ -250,7 +256,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
250
256
|
throw new ShapeDiverViewerSettingsError('Session.applySettings: Was not able to validate config object.');
|
|
251
257
|
}
|
|
252
258
|
|
|
253
|
-
const settings = <
|
|
259
|
+
const settings = <ISettings>convert(config, latestVersion);
|
|
254
260
|
|
|
255
261
|
const exportMappingUid: { [key: string]: string | undefined } = {};
|
|
256
262
|
if (sections.session.export.displayname || sections.session.export.order || sections.session.export.hidden)
|
|
@@ -320,7 +326,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
320
326
|
currentSettings.environmentGeometry.groundPlaneShadowVisibility = settings.environmentGeometry.groundPlaneShadowVisibility;
|
|
321
327
|
|
|
322
328
|
currentSettings.rendering.shadows = settings.rendering.shadows;
|
|
323
|
-
currentSettings.rendering.
|
|
329
|
+
currentSettings.rendering.softShadows = settings.rendering.softShadows;
|
|
324
330
|
|
|
325
331
|
currentSettings.rendering.automaticColorAdjustment = settings.rendering.automaticColorAdjustment;
|
|
326
332
|
currentSettings.rendering.textureEncoding = settings.rendering.textureEncoding;
|
|
@@ -336,6 +342,10 @@ export class SessionEngine implements ISessionEngine {
|
|
|
336
342
|
currentSettings.general.pointSize = settings.general.pointSize;
|
|
337
343
|
}
|
|
338
344
|
|
|
345
|
+
// apply postprocessing settings
|
|
346
|
+
if (sections.viewport.postprocessing)
|
|
347
|
+
currentSettings.postprocessing = settings.postprocessing;
|
|
348
|
+
|
|
339
349
|
// apply environment settings
|
|
340
350
|
if (sections.viewport.environment) {
|
|
341
351
|
currentSettings.environment.clearAlpha = settings.environment.clearAlpha;
|
|
@@ -402,7 +412,8 @@ export class SessionEngine implements ISessionEngine {
|
|
|
402
412
|
this._logger.debugLow(`Session(${this.id}).customize: Customizing session.`);
|
|
403
413
|
|
|
404
414
|
for (let r in this._stateEngine.renderingEngines)
|
|
405
|
-
this.
|
|
415
|
+
if(!this.excludeViewports.includes(r))
|
|
416
|
+
this._stateEngine.renderingEngines[r].busy.push(customizationId);
|
|
406
417
|
|
|
407
418
|
const eventFileUpload: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.1, data: { sessionId: this.id }, status: 'Uploading file parameters' };
|
|
408
419
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventFileUpload);
|
|
@@ -537,8 +548,6 @@ export class SessionEngine implements ISessionEngine {
|
|
|
537
548
|
// set the session values to the current ones in all parameters
|
|
538
549
|
for (const parameterId in this.parameters)
|
|
539
550
|
(<any>this.parameters[parameterId].sessionValue) = parameterSet[parameterId].value;
|
|
540
|
-
|
|
541
|
-
if (this._updateCallback) this._updateCallback(newNode, oldNode);
|
|
542
551
|
|
|
543
552
|
// set the output content to what has been updated
|
|
544
553
|
for (const outputId in this.outputs)
|
|
@@ -566,6 +575,21 @@ export class SessionEngine implements ISessionEngine {
|
|
|
566
575
|
const eventEnd: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customized' };
|
|
567
576
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
568
577
|
|
|
578
|
+
// update the viewports
|
|
579
|
+
for (let r in this._stateEngine.renderingEngines)
|
|
580
|
+
if(!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
|
|
581
|
+
this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
|
|
582
|
+
|
|
583
|
+
// call the update callback function on the session
|
|
584
|
+
if (this._updateCallback) this._updateCallback(newNode, oldNode);
|
|
585
|
+
|
|
586
|
+
// call the update callback functions on the outputs
|
|
587
|
+
for (const outputId in this.outputs)
|
|
588
|
+
this.outputs[outputId].triggerUpdateCallback(
|
|
589
|
+
newNode.children.find(c => c.name === outputId)!,
|
|
590
|
+
oldNode.children.find(c => c.name === outputId)!
|
|
591
|
+
);
|
|
592
|
+
|
|
569
593
|
return this.node;
|
|
570
594
|
} catch (e) {
|
|
571
595
|
const eventCancel: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization failed' };
|
|
@@ -671,7 +695,14 @@ export class SessionEngine implements ISessionEngine {
|
|
|
671
695
|
for (const parameterNameOrId in parameterValues)
|
|
672
696
|
parameterSet[parameterNameOrId] = (' ' + parameterValues[parameterNameOrId]).slice(1);
|
|
673
697
|
|
|
674
|
-
|
|
698
|
+
if(this._ticket) {
|
|
699
|
+
this._responseDto = await this._sdk.session.init(this._ticket, parameterSet);
|
|
700
|
+
} else if(this._guid) {
|
|
701
|
+
this._responseDto = await this._sdk.session.initForModel(this._guid, parameterSet);
|
|
702
|
+
} else {
|
|
703
|
+
// we should never get here
|
|
704
|
+
throw new ShapeDiverViewerSessionError(`Session.init: Initialization of session failed. Neither a ticket nor a guid are available.`)
|
|
705
|
+
}
|
|
675
706
|
this._performanceEvaluator.endSection('sessionResponse');
|
|
676
707
|
|
|
677
708
|
this._viewerSettings = this._responseDto.viewer?.config;
|
|
@@ -863,7 +894,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
863
894
|
if (sections.session.export === undefined)
|
|
864
895
|
sections.session.export = { displayname: true, order: true, hidden: true };
|
|
865
896
|
if (sections.viewport === undefined)
|
|
866
|
-
sections.viewport = { ar: true, scene: true, camera: true, light: true, environment: true, general: true };
|
|
897
|
+
sections.viewport = { ar: true, scene: true, camera: true, light: true, environment: true, general: true, postprocessing: true };
|
|
867
898
|
|
|
868
899
|
return this.applySettings(this._responseDto, sections);
|
|
869
900
|
}
|
|
@@ -1072,7 +1103,8 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1072
1103
|
this._logger.debugLow(`Session(${this.id}).updateOutputs: Updating Outputs.`);
|
|
1073
1104
|
|
|
1074
1105
|
for (let r in this._stateEngine.renderingEngines)
|
|
1075
|
-
this.
|
|
1106
|
+
if(!this.excludeViewports.includes(r))
|
|
1107
|
+
this._stateEngine.renderingEngines[r].busy.push(customizationId);
|
|
1076
1108
|
|
|
1077
1109
|
const eventRequest: ITaskEvent = { type: eventType, id: eventId, progress: taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 0.1 + taskEventInfo.progressRange.min : 0.1, data: eventData, status: 'Loading outputs' };
|
|
1078
1110
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
|
|
@@ -1118,8 +1150,6 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1118
1150
|
|
|
1119
1151
|
this._logger.debug(`Session(${this.id}).updateOutputs: Updating outputs finished, updating geometry.`);
|
|
1120
1152
|
|
|
1121
|
-
if (this._updateCallback) this._updateCallback(newNode, oldNode);
|
|
1122
|
-
|
|
1123
1153
|
// set the output content to what has been updated
|
|
1124
1154
|
for (const outputId in this.outputs) {
|
|
1125
1155
|
this.outputs[outputId].updateOutput(
|
|
@@ -1146,6 +1176,21 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1146
1176
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
1147
1177
|
}
|
|
1148
1178
|
|
|
1179
|
+
// update the viewports
|
|
1180
|
+
for (let r in this._stateEngine.renderingEngines)
|
|
1181
|
+
if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
|
|
1182
|
+
this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
|
|
1183
|
+
|
|
1184
|
+
// call the update callback function on the session
|
|
1185
|
+
if (this._updateCallback) this._updateCallback(newNode, oldNode);
|
|
1186
|
+
|
|
1187
|
+
// call the update callback functions on the outputs
|
|
1188
|
+
for (const outputId in this.outputs)
|
|
1189
|
+
this.outputs[outputId].triggerUpdateCallback(
|
|
1190
|
+
newNode.children.find(c => c.name === outputId)!,
|
|
1191
|
+
oldNode.children.find(c => c.name === outputId)!
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1149
1194
|
return this.node;
|
|
1150
1195
|
}
|
|
1151
1196
|
|
|
@@ -1300,7 +1345,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1300
1345
|
}
|
|
1301
1346
|
|
|
1302
1347
|
private async handleError(e: ShapeDiverBackendError | ShapeDiverViewerError | Error | unknown, retry = false) {
|
|
1303
|
-
if (e
|
|
1348
|
+
if (isGBResponseError(e)) {
|
|
1304
1349
|
if (e.error === ShapeDiverResponseErrorType.SESSION_GONE_ERROR) {
|
|
1305
1350
|
// case 1: the session is no longer available
|
|
1306
1351
|
// we try to re-initialize the session 3 times, if that does not work, we close it
|
|
@@ -95,6 +95,8 @@ export interface ISettingsSections {
|
|
|
95
95
|
environment?: boolean
|
|
96
96
|
/** Option to update the general settings (default: false) */
|
|
97
97
|
general?: boolean
|
|
98
|
+
/** Option to update the postprocessing settings (default: false) */
|
|
99
|
+
postprocessing?: boolean
|
|
98
100
|
}
|
|
99
101
|
};
|
|
100
102
|
|
|
@@ -104,6 +106,7 @@ export interface ISessionEngine {
|
|
|
104
106
|
readonly jwtToken?: string;
|
|
105
107
|
canUploadGLTF: boolean;
|
|
106
108
|
exports: { [key: string]: IExport };
|
|
109
|
+
guid?: string;
|
|
107
110
|
id: string;
|
|
108
111
|
initialized: boolean;
|
|
109
112
|
modelViewUrl: string;
|
|
@@ -111,7 +114,7 @@ export interface ISessionEngine {
|
|
|
111
114
|
parameters: { [key: string]: IParameter<any> };
|
|
112
115
|
refreshJwtToken: (() => Promise<string>) | undefined;
|
|
113
116
|
settingsEngine: SettingsEngine;
|
|
114
|
-
ticket
|
|
117
|
+
ticket?: string;
|
|
115
118
|
updateCallback: ((newNode: ITreeNode, oldNode: ITreeNode) => void) | null;
|
|
116
119
|
|
|
117
120
|
// #endregion Properties (11)
|
|
@@ -37,6 +37,7 @@ export interface IOutput extends ShapeDiverResponseOutput {
|
|
|
37
37
|
|
|
38
38
|
// #region Public Methods (1)
|
|
39
39
|
|
|
40
|
+
triggerUpdateCallback(newNode?: ITreeNode, oldNode?: ITreeNode): void;
|
|
40
41
|
updateOutput(newNode?: ITreeNode, oldNode?: ITreeNode): void;
|
|
41
42
|
updateOutputContent(content: ShapeDiverResponseOutputContent[], preventUpdate?: boolean): Promise<ITreeNode | undefined>;
|
|
42
43
|
updateOutputDefinition(outputDef: ShapeDiverResponseOutput): void;
|