@shapediver/viewer.data-engine.sdtf-engine 1.15.1 → 1.15.4
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/SDTFEngine.d.ts +60 -5
- package/dist/SDTFEngine.d.ts.map +1 -1
- package/dist/SDTFEngine.js +166 -137
- package/dist/SDTFEngine.js.map +1 -1
- package/package.json +8 -7
package/dist/SDTFEngine.d.ts
CHANGED
|
@@ -1,22 +1,77 @@
|
|
|
1
1
|
import { TreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
2
2
|
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
3
3
|
export declare class SDTFEngine {
|
|
4
|
-
private readonly BINARY_EXTENSION_HEADER_LENGTH;
|
|
5
|
-
private readonly _httpClient;
|
|
6
4
|
private readonly _logger;
|
|
7
|
-
private
|
|
8
|
-
private _content;
|
|
5
|
+
private _parsedFile;
|
|
9
6
|
constructor();
|
|
10
7
|
/**
|
|
11
|
-
* Load the
|
|
8
|
+
* Load the sdtf content into a scene graph node.
|
|
12
9
|
*
|
|
13
10
|
* @param content the geometry content
|
|
14
11
|
* @returns the scene graph node
|
|
15
12
|
*/
|
|
16
13
|
loadContent(content: ShapeDiverResponseOutputContent): Promise<TreeNode>;
|
|
14
|
+
/**
|
|
15
|
+
* Create an overview of the SDTF file.
|
|
16
|
+
* This overview is used for the data visualization.
|
|
17
|
+
* It is structured as a dictionary with the name as the key and an array of Objects as the value.
|
|
18
|
+
* The array of objects contains the different types that can be found in the SDTF file under the same name.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* {
|
|
22
|
+
* "color": [
|
|
23
|
+
* {
|
|
24
|
+
* typeHint: 'string',
|
|
25
|
+
* count: 2,
|
|
26
|
+
* values: ["red", "blue"]
|
|
27
|
+
* },
|
|
28
|
+
* {
|
|
29
|
+
* typeHint: 'numberArray',
|
|
30
|
+
* count: 2,
|
|
31
|
+
* values: [[1,0,0,1], [0,0,1,1]]
|
|
32
|
+
* },
|
|
33
|
+
* ]
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* The overview contains the following information:
|
|
37
|
+
* - name of the attribute + type of the attribute
|
|
38
|
+
* - the count
|
|
39
|
+
* - for numerical attributes, the min and max values
|
|
40
|
+
* - for string attributes, the unique values
|
|
41
|
+
*
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
private createSDTFOverview;
|
|
45
|
+
/**
|
|
46
|
+
* Load the attributes into a SDTFAttributesData data item.
|
|
47
|
+
*
|
|
48
|
+
* @param attributes
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
17
51
|
private loadAttributes;
|
|
52
|
+
/**
|
|
53
|
+
* Load the chunk into a scene graph node.
|
|
54
|
+
*
|
|
55
|
+
* @param chunk
|
|
56
|
+
* @param chunkId
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
18
59
|
private loadChunk;
|
|
60
|
+
/**
|
|
61
|
+
* Load the item into a scene graph node.
|
|
62
|
+
*
|
|
63
|
+
* @param item
|
|
64
|
+
* @param itemId
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
19
67
|
private loadItem;
|
|
68
|
+
/**
|
|
69
|
+
* Load the node into a scene graph node.
|
|
70
|
+
*
|
|
71
|
+
* @param node
|
|
72
|
+
* @param nodeId
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
20
75
|
private loadNode;
|
|
21
76
|
}
|
|
22
77
|
//# sourceMappingURL=SDTFEngine.d.ts.map
|
package/dist/SDTFEngine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SDTFEngine.d.ts","sourceRoot":"","sources":["../src/SDTFEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SDTFEngine.d.ts","sourceRoot":"","sources":["../src/SDTFEngine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAA;AAS9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAA;AAErF,qBACa,UAAU;IAGnB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IAErE,OAAO,CAAC,WAAW,CAAsB;;IAYzC;;;;;OAKG;IACU,WAAW,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkCrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;YACW,kBAAkB;IA2EhC;;;;;OAKG;YACW,cAAc;IAa5B;;;;;;OAMG;YACW,SAAS;IA2BvB;;;;;;OAMG;YACW,QAAQ;IAkBtB;;;;;;OAMG;YACW,QAAQ;CA4BzB"}
|
package/dist/SDTFEngine.js
CHANGED
|
@@ -19,218 +19,247 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.SDTFEngine = void 0;
|
|
22
|
+
const sdk_sdtf_v1_1 = require("@shapediver/sdk.sdtf-v1");
|
|
23
|
+
const sdk_sdtf_primitives_1 = require("@shapediver/sdk.sdtf-primitives");
|
|
22
24
|
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
23
25
|
const tsyringe_1 = require("tsyringe");
|
|
24
26
|
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
25
27
|
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
26
28
|
let SDTFEngine = class SDTFEngine {
|
|
27
|
-
// #endregion Properties (
|
|
29
|
+
// #endregion Properties (2)
|
|
28
30
|
// #region Constructors (1)
|
|
29
31
|
constructor() {
|
|
30
|
-
// #region Properties (
|
|
31
|
-
this.BINARY_EXTENSION_HEADER_LENGTH = 20;
|
|
32
|
-
this._httpClient = tsyringe_1.container.resolve(viewer_shared_services_1.HttpClient);
|
|
32
|
+
// #region Properties (2)
|
|
33
33
|
this._logger = tsyringe_1.container.resolve(viewer_shared_services_1.Logger);
|
|
34
34
|
}
|
|
35
35
|
// #endregion Constructors (1)
|
|
36
36
|
// #region Public Methods (1)
|
|
37
37
|
/**
|
|
38
|
-
* Load the
|
|
38
|
+
* Load the sdtf content into a scene graph node.
|
|
39
39
|
*
|
|
40
40
|
* @param content the geometry content
|
|
41
41
|
* @returns the scene graph node
|
|
42
42
|
*/
|
|
43
43
|
loadContent(content) {
|
|
44
|
-
var _a, _b;
|
|
45
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
45
|
const node = new viewer_shared_node_tree_1.TreeNode('sdtf');
|
|
46
|
+
// We have to be safe and check if the content is a valid SDTF file
|
|
47
47
|
if (!content || (content && !content.href)) {
|
|
48
48
|
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('SDTFEngine.loadContent: Invalid content was provided to geometry engine.');
|
|
49
49
|
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.loadContent`, error);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
// create the sdtf sdk
|
|
52
|
+
const sdk = yield sdk_sdtf_v1_1.create();
|
|
53
|
+
// crete the sdtf parser
|
|
54
|
+
const parser = sdk.createParser();
|
|
55
|
+
// parse the file
|
|
56
|
+
this._parsedFile = yield parser.readFromUrl(content.href);
|
|
52
57
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
// crete the overview and save it in the node data
|
|
59
|
+
node.data.push(yield this.createSDTFOverview());
|
|
60
|
+
// add the loaded chunks to the node
|
|
61
|
+
for (let i = 0; i < this._parsedFile.chunks.length; i++)
|
|
62
|
+
node.children.push(yield this.loadChunk(this._parsedFile.chunks[i], i));
|
|
63
|
+
return node;
|
|
56
64
|
}
|
|
57
65
|
catch (e) {
|
|
58
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.
|
|
59
|
-
}
|
|
60
|
-
if (!(axiosResponse.headers['content-type'] && axiosResponse.headers['content-type'] === 'model/vnd.sdtf')) {
|
|
61
|
-
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('SDTFEngine.loadContent: Non-binary SDTF encoding not implemented.');
|
|
62
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.loadContent`, error);
|
|
63
|
-
}
|
|
64
|
-
let arrayBuffer;
|
|
65
|
-
if (axiosResponse.data instanceof ArrayBuffer) {
|
|
66
|
-
arrayBuffer = axiosResponse.data;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
arrayBuffer = axiosResponse.data.buffer;
|
|
70
|
-
}
|
|
71
|
-
const headerDataView = new DataView(arrayBuffer, 0, this.BINARY_EXTENSION_HEADER_LENGTH);
|
|
72
|
-
const magic = String.fromCharCode(headerDataView.getUint8(0)) + String.fromCharCode(headerDataView.getUint8(1)) + String.fromCharCode(headerDataView.getUint8(2)) + String.fromCharCode(headerDataView.getUint8(3));
|
|
73
|
-
if (magic !== 'sdtf') {
|
|
74
|
-
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('SDTFEngine.loadContent: Invalid data: sdtf magic wrong.');
|
|
75
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.loadContent`, error);
|
|
76
|
-
}
|
|
77
|
-
const version = headerDataView.getUint32(4, true);
|
|
78
|
-
if (version !== 1) {
|
|
79
|
-
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(`SDTFEngine.loadContent: Invalid version: sdtf loader does not support version ${version}.`);
|
|
80
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.loadContent`, error);
|
|
81
|
-
}
|
|
82
|
-
const totalLength = headerDataView.getUint32(8, true);
|
|
83
|
-
const contentLength = headerDataView.getUint32(12, true);
|
|
84
|
-
const contentFormat = headerDataView.getUint32(16, true);
|
|
85
|
-
if (contentFormat !== 0) {
|
|
86
|
-
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError(`SDTFEngine.loadContent: Content format is not Json (0), content invalid.`);
|
|
87
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.loadContent`, error);
|
|
66
|
+
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.load`, e);
|
|
88
67
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// #endregion Public Methods (1)
|
|
71
|
+
// #region Private Methods (5)
|
|
72
|
+
/**
|
|
73
|
+
* Create an overview of the SDTF file.
|
|
74
|
+
* This overview is used for the data visualization.
|
|
75
|
+
* It is structured as a dictionary with the name as the key and an array of Objects as the value.
|
|
76
|
+
* The array of objects contains the different types that can be found in the SDTF file under the same name.
|
|
77
|
+
*
|
|
78
|
+
* Example:
|
|
79
|
+
* {
|
|
80
|
+
* "color": [
|
|
81
|
+
* {
|
|
82
|
+
* typeHint: 'string',
|
|
83
|
+
* count: 2,
|
|
84
|
+
* values: ["red", "blue"]
|
|
85
|
+
* },
|
|
86
|
+
* {
|
|
87
|
+
* typeHint: 'numberArray',
|
|
88
|
+
* count: 2,
|
|
89
|
+
* values: [[1,0,0,1], [0,0,1,1]]
|
|
90
|
+
* },
|
|
91
|
+
* ]
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* The overview contains the following information:
|
|
95
|
+
* - name of the attribute + type of the attribute
|
|
96
|
+
* - the count
|
|
97
|
+
* - for numerical attributes, the min and max values
|
|
98
|
+
* - for string attributes, the unique values
|
|
99
|
+
*
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
createSDTFOverview() {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const overview = {};
|
|
106
|
+
// go through all attributes
|
|
107
|
+
for (let i = 0; i < this._parsedFile.attributes.length; i++) {
|
|
108
|
+
const attributes = this._parsedFile.attributes[i];
|
|
109
|
+
// go through all entries
|
|
110
|
+
for (let key in attributes.entries) {
|
|
111
|
+
const dataToCopy = attributes.entries[key];
|
|
112
|
+
const value = yield dataToCopy.getContent();
|
|
113
|
+
// create the type hint to use
|
|
114
|
+
const dataTypehint = dataToCopy.typeHint === undefined ? 'undefined' : dataToCopy.typeHint.name;
|
|
115
|
+
// check if the attribute is already in the overview
|
|
116
|
+
const existingEntries = overview[key] ? overview[key].filter(o => o.typeHint === dataTypehint) : [];
|
|
117
|
+
if (overview[key] && existingEntries.length > 0) {
|
|
118
|
+
// update the existing entry
|
|
119
|
+
const entry = existingEntries[0];
|
|
120
|
+
// update the count
|
|
121
|
+
entry.count++;
|
|
122
|
+
// update the values
|
|
123
|
+
if (sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isStringType(dataTypehint)) {
|
|
124
|
+
if (!((_a = entry.values) === null || _a === void 0 ? void 0 : _a.includes(value)))
|
|
125
|
+
(_b = entry.values) === null || _b === void 0 ? void 0 : _b.push(value);
|
|
126
|
+
}
|
|
127
|
+
// update the min and max
|
|
128
|
+
if (sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isNumberType(dataTypehint)) {
|
|
129
|
+
entry.min = Math.min(value, entry.min);
|
|
130
|
+
entry.max = Math.max(value, entry.max);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// create a new entry, if the name already exists, but the type does not
|
|
135
|
+
if (overview[key]) {
|
|
136
|
+
overview[key].push({
|
|
137
|
+
typeHint: dataTypehint,
|
|
138
|
+
count: 1,
|
|
139
|
+
});
|
|
114
140
|
}
|
|
141
|
+
// create completely new entry
|
|
115
142
|
else {
|
|
116
|
-
|
|
117
|
-
overview[key].push({
|
|
143
|
+
overview[key] = [{
|
|
118
144
|
typeHint: dataTypehint,
|
|
119
145
|
count: 1,
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
if (dataTypehint === viewer_shared_types_1.PRIMITIVETYPEHINT.DOUBLE ||
|
|
132
|
-
dataTypehint === viewer_shared_types_1.PRIMITIVETYPEHINT.FLOAT ||
|
|
133
|
-
dataTypehint === viewer_shared_types_1.PRIMITIVETYPEHINT.DECIMAL ||
|
|
134
|
-
dataTypehint === viewer_shared_types_1.PRIMITIVETYPEHINT.INT) {
|
|
135
|
-
overview[key][overview[key].length - 1].min = dataToCopy.value;
|
|
136
|
-
overview[key][overview[key].length - 1].max = dataToCopy.value;
|
|
137
|
-
}
|
|
146
|
+
}];
|
|
147
|
+
}
|
|
148
|
+
// update the values
|
|
149
|
+
if (sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isStringType(dataTypehint)) {
|
|
150
|
+
overview[key][overview[key].length - 1].values = [value];
|
|
151
|
+
}
|
|
152
|
+
// update the min and max
|
|
153
|
+
if (sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isNumberType(dataTypehint)) {
|
|
154
|
+
overview[key][overview[key].length - 1].min = value;
|
|
155
|
+
overview[key][overview[key].length - 1].max = value;
|
|
138
156
|
}
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
|
-
node.data.push(new viewer_shared_types_1.SDTFAttributeOverview(overview));
|
|
142
|
-
for (let i = 0; i < this._content.chunks.length; i++) {
|
|
143
|
-
node.children.push(yield this.loadChunk(i));
|
|
144
|
-
}
|
|
145
|
-
return node;
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
throw this._logger.handleError(viewer_shared_services_1.LOGGINGTOPIC.DATA_PROCESSING, `SDTFEngine.load`, e);
|
|
149
159
|
}
|
|
160
|
+
return new viewer_shared_types_1.SDTFAttributeOverview(overview);
|
|
150
161
|
});
|
|
151
162
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Load the attributes into a SDTFAttributesData data item.
|
|
165
|
+
*
|
|
166
|
+
* @param attributes
|
|
167
|
+
* @returns
|
|
168
|
+
*/
|
|
169
|
+
loadAttributes(attributes) {
|
|
170
|
+
var _a, _b, _c, _d;
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const data = new viewer_shared_types_1.SDTFAttributesData();
|
|
173
|
+
// go through all attributes entries and save them in data items
|
|
174
|
+
for (let key in attributes.entries) {
|
|
175
|
+
if (sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isBooleanType((_a = attributes.entries[key].typeHint) === null || _a === void 0 ? void 0 : _a.name) || sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isColorType((_b = attributes.entries[key].typeHint) === null || _b === void 0 ? void 0 : _b.name) || sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isNumberType((_c = attributes.entries[key].typeHint) === null || _c === void 0 ? void 0 : _c.name) || sdk_sdtf_primitives_1.SdtfPrimitiveTypeGuard.isStringType((_d = attributes.entries[key].typeHint) === null || _d === void 0 ? void 0 : _d.name)) {
|
|
176
|
+
// create the data item and save it in the dictionary
|
|
177
|
+
const typeHint = attributes.entries[key].typeHint === undefined ? 'undefined' : attributes.entries[key].typeHint.name;
|
|
178
|
+
data.attributes[key] = new viewer_shared_types_1.SDTFAttributeData(typeHint, yield attributes.entries[key].getContent());
|
|
179
|
+
}
|
|
167
180
|
}
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
return data;
|
|
182
|
+
});
|
|
170
183
|
}
|
|
171
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Load the chunk into a scene graph node.
|
|
186
|
+
*
|
|
187
|
+
* @param chunk
|
|
188
|
+
* @param chunkId
|
|
189
|
+
* @returns
|
|
190
|
+
*/
|
|
191
|
+
loadChunk(chunk, chunkId) {
|
|
172
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
if (!this._content.chunks)
|
|
174
|
-
throw new Error('Chunks not available.');
|
|
175
|
-
if (!this._content.chunks[chunkId])
|
|
176
|
-
throw new Error('Chunks not available.');
|
|
177
|
-
const chunk = this._content.chunks[chunkId];
|
|
178
193
|
const chunkDef = new viewer_shared_node_tree_1.TreeNode(chunk.name || 'chunk_' + chunkId);
|
|
194
|
+
// if there are attributes, add them to the chunk as data
|
|
179
195
|
if (chunk.attributes !== undefined) {
|
|
180
|
-
chunkDef.data.push(this.loadAttributes(chunk.attributes));
|
|
196
|
+
chunkDef.data.push(yield this.loadAttributes(chunk.attributes));
|
|
181
197
|
}
|
|
198
|
+
// if there are items, add them to the chunk as children
|
|
182
199
|
if (chunk.items !== undefined && chunk.items.length > 0) {
|
|
183
200
|
for (let i = 0, len = chunk.items.length; i < len; i++) {
|
|
184
|
-
// got through all
|
|
201
|
+
// got through all items
|
|
185
202
|
chunkDef.addChild(yield this.loadItem(chunk.items[i], i));
|
|
186
203
|
}
|
|
187
204
|
}
|
|
205
|
+
// if there are nodes, add them to the chunk as children
|
|
188
206
|
if (chunk.nodes !== undefined && chunk.nodes.length > 0) {
|
|
189
207
|
for (let i = 0, len = chunk.nodes.length; i < len; i++) {
|
|
190
208
|
// got through all children
|
|
191
|
-
chunkDef.addChild(yield this.loadNode(chunk.nodes[i]));
|
|
209
|
+
chunkDef.addChild(yield this.loadNode(chunk.nodes[i], i));
|
|
192
210
|
}
|
|
193
211
|
}
|
|
194
212
|
return chunkDef;
|
|
195
213
|
});
|
|
196
214
|
}
|
|
197
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Load the item into a scene graph node.
|
|
217
|
+
*
|
|
218
|
+
* @param item
|
|
219
|
+
* @param itemId
|
|
220
|
+
* @returns
|
|
221
|
+
*/
|
|
222
|
+
loadItem(item, itemId) {
|
|
198
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (!this._content.items[itemId])
|
|
202
|
-
throw new Error('Item not available.');
|
|
203
|
-
const item = this._content.items[itemId];
|
|
204
|
-
const itemDef = new viewer_shared_node_tree_1.TreeNode(index + '');
|
|
224
|
+
const itemDef = new viewer_shared_node_tree_1.TreeNode(itemId + '');
|
|
225
|
+
// if there are attributes, add them to the item
|
|
205
226
|
let attributes;
|
|
206
227
|
if (item.attributes !== undefined)
|
|
207
|
-
attributes = this.loadAttributes(item.attributes);
|
|
208
|
-
|
|
228
|
+
attributes = yield this.loadAttributes(item.attributes);
|
|
229
|
+
// create the typehint
|
|
230
|
+
const typeHint = item.typeHint === undefined ? 'undefined' : item.typeHint.name;
|
|
231
|
+
// create the data and save it in the item node
|
|
232
|
+
const itemData = new viewer_shared_types_1.SDTFItemData(typeHint, yield item.getContent(), attributes === null || attributes === void 0 ? void 0 : attributes.attributes);
|
|
209
233
|
itemDef.data.push(itemData);
|
|
210
234
|
return itemDef;
|
|
211
235
|
});
|
|
212
236
|
}
|
|
213
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Load the node into a scene graph node.
|
|
239
|
+
*
|
|
240
|
+
* @param node
|
|
241
|
+
* @param nodeId
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
loadNode(node, nodeId) {
|
|
214
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
if (!this._content.nodes)
|
|
216
|
-
throw new Error('Node not available.');
|
|
217
|
-
if (!this._content.nodes[nodeId])
|
|
218
|
-
throw new Error('Node not available.');
|
|
219
|
-
const node = this._content.nodes[nodeId];
|
|
220
246
|
const nodeDef = new viewer_shared_node_tree_1.TreeNode(node.name || 'node_' + nodeId);
|
|
247
|
+
// if there are attributes, add them to the node as data
|
|
221
248
|
if (node.attributes !== undefined) {
|
|
222
|
-
nodeDef.data.push(this.loadAttributes(node.attributes));
|
|
249
|
+
nodeDef.data.push(yield this.loadAttributes(node.attributes));
|
|
223
250
|
}
|
|
251
|
+
// if there are items, add them to the node as children
|
|
224
252
|
if (node.items !== undefined && node.items.length > 0) {
|
|
225
253
|
for (let i = 0, len = node.items.length; i < len; i++) {
|
|
226
|
-
// got through all
|
|
254
|
+
// got through all items
|
|
227
255
|
nodeDef.addChild(yield this.loadItem(node.items[i], i));
|
|
228
256
|
}
|
|
229
257
|
}
|
|
258
|
+
// if there are nodes, add them to the node as children
|
|
230
259
|
if (node.nodes !== undefined && node.nodes.length > 0) {
|
|
231
260
|
for (let i = 0, len = node.nodes.length; i < len; i++) {
|
|
232
261
|
// got through all children
|
|
233
|
-
nodeDef.addChild(yield this.loadNode(node.nodes[i]));
|
|
262
|
+
nodeDef.addChild(yield this.loadNode(node.nodes[i], i));
|
|
234
263
|
}
|
|
235
264
|
}
|
|
236
265
|
return nodeDef;
|
package/dist/SDTFEngine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SDTFEngine.js","sourceRoot":"","sources":["../src/SDTFEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,iFAA8D;AAC9D,uCAA+C;AAC/C,+
|
|
1
|
+
{"version":3,"file":"SDTFEngine.js","sourceRoot":"","sources":["../src/SDTFEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,yDAA8K;AAC9K,yEAAyE;AACzE,iFAA8D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C,MAAM,GAAG,CAAC,EAAE;gBACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;oBACnD,wBAAwB;oBACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;iBAC3D;aACJ;YAED,uDAAuD;YACvD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;oBACnD,2BAA2B;oBAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;iBAC3D;aACJ;YAED,OAAO,OAAO,CAAC;QACnB,CAAC;KAAA;CAGJ,CAAA;AAnRY,UAAU;IADtB,oBAAS,EAAE;;GACC,UAAU,CAmRtB;AAnRY,gCAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.data-engine.sdtf-engine",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -37,14 +37,15 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@shapediver/sdk.geometry-api-sdk-v2": "^1.0.23",
|
|
40
|
-
"@shapediver/
|
|
41
|
-
"@shapediver/viewer.shared
|
|
42
|
-
"@shapediver/viewer.shared.
|
|
43
|
-
"@shapediver/viewer.shared.
|
|
44
|
-
"@shapediver/viewer.shared.
|
|
40
|
+
"@shapediver/sdk.sdtf-v1": "1.0.0",
|
|
41
|
+
"@shapediver/viewer.data-engine.shared-types": "1.15.4",
|
|
42
|
+
"@shapediver/viewer.shared.build-data": "1.15.4",
|
|
43
|
+
"@shapediver/viewer.shared.node-tree": "1.15.4",
|
|
44
|
+
"@shapediver/viewer.shared.services": "1.15.4",
|
|
45
|
+
"@shapediver/viewer.shared.types": "1.15.4",
|
|
45
46
|
"axios": "^0.21.1",
|
|
46
47
|
"gl-matrix": "3.3.0",
|
|
47
48
|
"tsyringe": "^4.5.0"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "67301c95b2ec6d84d1da059ec116e5cf201010d0"
|
|
50
51
|
}
|