@shapediver/viewer.features.attribute-visualization 3.16.8 → 3.16.10
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/AttributeVisualizationEngine.d.ts +42 -42
- package/dist/implementation/AttributeVisualizationEngine.js +358 -358
- package/dist/implementation/AttributeVisualizationEngine.js.map +1 -1
- package/dist/implementation/AttributeVisualizationUtils.d.ts +11 -11
- package/dist/implementation/AttributeVisualizationUtils.d.ts.map +1 -1
- package/dist/implementation/AttributeVisualizationUtils.js +805 -805
- package/dist/implementation/AttributeVisualizationUtils.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +15 -15
- package/dist/interfaces/IAttribute.d.ts +20 -20
- package/dist/interfaces/IAttribute.d.ts.map +1 -1
- package/dist/interfaces/IAttribute.js +2 -2
- package/dist/interfaces/IAttributeVisualizationEngine.d.ts +39 -39
- package/dist/interfaces/IAttributeVisualizationEngine.js +2 -2
- package/dist/interfaces/IGradient.d.ts +5 -5
- package/dist/interfaces/IGradient.d.ts.map +1 -1
- package/dist/interfaces/IGradient.js +13 -13
- package/dist/interfaces/ILayer.d.ts +6 -6
- package/dist/interfaces/ILayer.js +2 -2
- package/package.json +7 -7
|
@@ -1,359 +1,359 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _AttributeVisualizationEngine_uuidGenerator, _AttributeVisualizationEngine_viewport, _AttributeVisualizationEngine_attributes, _AttributeVisualizationEngine_defaultMaterial, _AttributeVisualizationEngine_defaultLayer, _AttributeVisualizationEngine_layers, _AttributeVisualizationEngine_overview, _AttributeVisualizationEngine_listeners, _AttributeVisualizationEngine_visualizedMaterialType, _AttributeVisualizationEngine_layerMaterialType, _AttributeVisualizationEngine_nodesWithAttributeData, _AttributeVisualizationEngine_overviewCache, _AttributeVisualizationEngine_updateScheduled;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AttributeVisualizationEngine = void 0;
|
|
16
|
-
/* eslint-disable no-case-declarations */
|
|
17
|
-
const viewer_1 = require("@shapediver/viewer");
|
|
18
|
-
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
19
|
-
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
20
|
-
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
21
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
22
|
-
const AttributeVisualizationUtils_1 = require("./AttributeVisualizationUtils");
|
|
23
|
-
/** Shared identity matrix — never mutate this. */
|
|
24
|
-
const IDENTITY_MATRIX = gl_matrix_1.mat4.create();
|
|
25
|
-
class AttributeVisualizationEngine {
|
|
26
|
-
// #endregion Properties (7)
|
|
27
|
-
// #region Constructors (1)
|
|
28
|
-
constructor(viewport) {
|
|
29
|
-
// #region Properties (7)
|
|
30
|
-
_AttributeVisualizationEngine_uuidGenerator.set(this, viewer_shared_services_1.UuidGenerator.instance);
|
|
31
|
-
_AttributeVisualizationEngine_viewport.set(this, void 0);
|
|
32
|
-
_AttributeVisualizationEngine_attributes.set(this, []);
|
|
33
|
-
_AttributeVisualizationEngine_defaultMaterial.set(this, new viewer_shared_node_tree_1.MaterialUnlitData({
|
|
34
|
-
color: "#000000",
|
|
35
|
-
opacity: 1,
|
|
36
|
-
}));
|
|
37
|
-
_AttributeVisualizationEngine_defaultLayer.set(this, {
|
|
38
|
-
color: "#000000",
|
|
39
|
-
opacity: 1,
|
|
40
|
-
enabled: true,
|
|
41
|
-
});
|
|
42
|
-
_AttributeVisualizationEngine_layers.set(this, {});
|
|
43
|
-
_AttributeVisualizationEngine_overview.set(this, void 0);
|
|
44
|
-
_AttributeVisualizationEngine_listeners.set(this, {});
|
|
45
|
-
_AttributeVisualizationEngine_visualizedMaterialType.set(this, "unlit");
|
|
46
|
-
_AttributeVisualizationEngine_layerMaterialType.set(this, "unlit");
|
|
47
|
-
_AttributeVisualizationEngine_nodesWithAttributeData.set(this, []);
|
|
48
|
-
/** Pre-cached overview lookups keyed by "attributeKey:typeHint" */
|
|
49
|
-
_AttributeVisualizationEngine_overviewCache.set(this, new Map());
|
|
50
|
-
_AttributeVisualizationEngine_updateScheduled.set(this, false);
|
|
51
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_viewport, viewport, "f");
|
|
52
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_overview, __classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").createSDTFOverview(viewer_1.sceneTree.root), "f");
|
|
53
|
-
this.createLayers();
|
|
54
|
-
this.gatherNodesWithAttributeData();
|
|
55
|
-
this.buildOverviewCache();
|
|
56
|
-
this.constructAttributeVisualization();
|
|
57
|
-
const cb = () => {
|
|
58
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_overview, __classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").createSDTFOverview(viewer_1.sceneTree.root), "f");
|
|
59
|
-
const layers = __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f");
|
|
60
|
-
this.createLayers();
|
|
61
|
-
for (const l in layers) {
|
|
62
|
-
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[l])
|
|
63
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[l] = layers[l];
|
|
64
|
-
}
|
|
65
|
-
this.gatherNodesWithAttributeData();
|
|
66
|
-
this.buildOverviewCache();
|
|
67
|
-
this.constructAttributeVisualization();
|
|
68
|
-
for (const l in __classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f"))
|
|
69
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[l]();
|
|
70
|
-
};
|
|
71
|
-
(0, viewer_1.addListener)(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, cb);
|
|
72
|
-
(0, viewer_1.addListener)(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_SDTF_DELAYED_LOADED, cb);
|
|
73
|
-
}
|
|
74
|
-
// #endregion Constructors (1)
|
|
75
|
-
// #region Public Accessors (3)
|
|
76
|
-
gatherNodesWithAttributeData() {
|
|
77
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_nodesWithAttributeData, [], "f");
|
|
78
|
-
viewer_1.sceneTree.root.traverse((node) => {
|
|
79
|
-
const data = node.data;
|
|
80
|
-
for (let i = 0, len = data.length; i < len; i++) {
|
|
81
|
-
if (data[i] instanceof viewer_shared_node_tree_1.SDTFItemData) {
|
|
82
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f").push(node);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
get defaultMaterial() {
|
|
89
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f");
|
|
90
|
-
}
|
|
91
|
-
get defaultLayer() {
|
|
92
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f");
|
|
93
|
-
}
|
|
94
|
-
get layers() {
|
|
95
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f");
|
|
96
|
-
}
|
|
97
|
-
get layerMaterialType() {
|
|
98
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f");
|
|
99
|
-
}
|
|
100
|
-
get visualizedMaterialType() {
|
|
101
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f");
|
|
102
|
-
}
|
|
103
|
-
get overview() {
|
|
104
|
-
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f");
|
|
105
|
-
}
|
|
106
|
-
// #endregion Public Accessors (3)
|
|
107
|
-
// #region Public Methods (3)
|
|
108
|
-
updateAttributes(attributes) {
|
|
109
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_attributes, attributes, "f");
|
|
110
|
-
this.buildOverviewCache();
|
|
111
|
-
this.scheduleUpdate();
|
|
112
|
-
}
|
|
113
|
-
updateDefaultLayer(layer) {
|
|
114
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_defaultLayer, layer, "f");
|
|
115
|
-
this.scheduleUpdate();
|
|
116
|
-
}
|
|
117
|
-
updateDefaultMaterial(material) {
|
|
118
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_defaultMaterial, material, "f");
|
|
119
|
-
this.scheduleUpdate();
|
|
120
|
-
}
|
|
121
|
-
updateLayerMaterialType(type) {
|
|
122
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layerMaterialType, type, "f");
|
|
123
|
-
this.createLayers();
|
|
124
|
-
this.scheduleUpdate();
|
|
125
|
-
}
|
|
126
|
-
updateVisualizedMaterialType(type) {
|
|
127
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_visualizedMaterialType, type, "f");
|
|
128
|
-
this.createLayers();
|
|
129
|
-
this.scheduleUpdate();
|
|
130
|
-
}
|
|
131
|
-
updateLayers(layers) {
|
|
132
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layers, layers, "f");
|
|
133
|
-
this.scheduleUpdate();
|
|
134
|
-
}
|
|
135
|
-
addListener(cb) {
|
|
136
|
-
const token = __classPrivateFieldGet(this, _AttributeVisualizationEngine_uuidGenerator, "f").create();
|
|
137
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token] = cb;
|
|
138
|
-
return token;
|
|
139
|
-
}
|
|
140
|
-
removeListener(token) {
|
|
141
|
-
if (!__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token])
|
|
142
|
-
return false;
|
|
143
|
-
delete __classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token];
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
// #endregion Public Methods (3)
|
|
147
|
-
// #region Private Methods
|
|
148
|
-
/**
|
|
149
|
-
* Coalesce multiple rapid update calls into a single
|
|
150
|
-
* constructAttributeVisualization + invalidation pass using microtask scheduling.
|
|
151
|
-
*/
|
|
152
|
-
scheduleUpdate() {
|
|
153
|
-
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_updateScheduled, "f"))
|
|
154
|
-
return;
|
|
155
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_updateScheduled, true, "f");
|
|
156
|
-
queueMicrotask(() => {
|
|
157
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_updateScheduled, false, "f");
|
|
158
|
-
this.constructAttributeVisualization();
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Pre-build a lookup map from "key:typeHint" -> ISDTFAttributeOverview
|
|
163
|
-
* so the hot-path callback avoids Array.filter() per geometry item.
|
|
164
|
-
*/
|
|
165
|
-
buildOverviewCache() {
|
|
166
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").clear();
|
|
167
|
-
for (const a of __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f")) {
|
|
168
|
-
const overviewEntries = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")[a.key];
|
|
169
|
-
if (!overviewEntries)
|
|
170
|
-
continue;
|
|
171
|
-
for (let j = 0; j < overviewEntries.length; j++) {
|
|
172
|
-
if (overviewEntries[j].typeHint === a.type) {
|
|
173
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").set(a.key + ":" + a.type, overviewEntries[j]);
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
createMaterial(type, color, opacity) {
|
|
180
|
-
return type === "unlit"
|
|
181
|
-
? new viewer_shared_node_tree_1.MaterialUnlitData({ color, opacity })
|
|
182
|
-
: new viewer_shared_node_tree_1.MaterialStandardData({ color, opacity });
|
|
183
|
-
}
|
|
184
|
-
constructAttributeVisualization() {
|
|
185
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").visualizeAttributes = (_overview, itemData) => {
|
|
186
|
-
// early out if there are not attributes in this itemData
|
|
187
|
-
if (!itemData || !itemData.attributes) {
|
|
188
|
-
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length === 0) {
|
|
189
|
-
return {
|
|
190
|
-
matrix: IDENTITY_MATRIX,
|
|
191
|
-
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").color, __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").enabled
|
|
192
|
-
? __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").opacity
|
|
193
|
-
: 0),
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
return {
|
|
198
|
-
matrix: IDENTITY_MATRIX,
|
|
199
|
-
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f").color, __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").enabled
|
|
200
|
-
? __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").opacity *
|
|
201
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f").opacity
|
|
202
|
-
: 0),
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// search for the responsible layer property, if none is found, default layer is assigned
|
|
207
|
-
let layer = this.defaultLayer;
|
|
208
|
-
if (itemData.attributes["layer"] &&
|
|
209
|
-
viewer_shared_types_1.SdtfPrimitiveTypeGuard.isStringType(itemData.attributes["layer"].typeHint)) {
|
|
210
|
-
const layerAttributes = itemData.attributes["layer"];
|
|
211
|
-
layer = __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[layerAttributes.value];
|
|
212
|
-
}
|
|
213
|
-
// early out, layer is not enabled
|
|
214
|
-
if (layer.enabled === false) {
|
|
215
|
-
const mat = this.createMaterialCopy(__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
216
|
-
mat.opacity = 0;
|
|
217
|
-
return {
|
|
218
|
-
matrix: IDENTITY_MATRIX,
|
|
219
|
-
material: mat,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length === 0) {
|
|
223
|
-
// no attributes are specified, we go into layer visualization mode
|
|
224
|
-
return {
|
|
225
|
-
matrix: IDENTITY_MATRIX,
|
|
226
|
-
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), layer.color, layer.opacity),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
// attributes are specified, we go into attribute visualization mode
|
|
231
|
-
const material = __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f") === "unlit"
|
|
232
|
-
? new viewer_shared_node_tree_1.MaterialUnlitData()
|
|
233
|
-
: new viewer_shared_node_tree_1.MaterialStandardData();
|
|
234
|
-
for (let i = 0; i < __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length; i++) {
|
|
235
|
-
const a = __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f")[i];
|
|
236
|
-
if (itemData.attributes[a.key] &&
|
|
237
|
-
itemData.attributes[a.key].typeHint === a.type) {
|
|
238
|
-
const itemDataAttribute = itemData.attributes[a.key];
|
|
239
|
-
const itemDataAttributeOverview = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").get(a.key + ":" + a.type);
|
|
240
|
-
switch (true) {
|
|
241
|
-
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isColorType(a.type):
|
|
242
|
-
// multiply each color values with 255 to convert them to the range [0, 255]
|
|
243
|
-
const convertedValue = itemDataAttribute.value.map((v) => v * 255);
|
|
244
|
-
material.color = convertedValue;
|
|
245
|
-
material.opacity *= layer.opacity;
|
|
246
|
-
return {
|
|
247
|
-
matrix: IDENTITY_MATRIX,
|
|
248
|
-
material,
|
|
249
|
-
};
|
|
250
|
-
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isNumberType(a.type):
|
|
251
|
-
const numberAttribute = a;
|
|
252
|
-
const numberVisualizationData = AttributeVisualizationUtils_1.AttributeVisualizationUtils.numberVisualization(itemDataAttribute.value, (numberAttribute.min !== undefined
|
|
253
|
-
? numberAttribute.min
|
|
254
|
-
: itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.min), (numberAttribute.max !== undefined
|
|
255
|
-
? numberAttribute.max
|
|
256
|
-
: itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.max), numberAttribute.visualization, __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
257
|
-
if (!numberVisualizationData) {
|
|
258
|
-
return {
|
|
259
|
-
matrix: IDENTITY_MATRIX,
|
|
260
|
-
material,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
numberVisualizationData.material.opacity *=
|
|
265
|
-
layer.opacity;
|
|
266
|
-
return numberVisualizationData;
|
|
267
|
-
}
|
|
268
|
-
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isStringType(a.type):
|
|
269
|
-
const stringAttribute = a;
|
|
270
|
-
const stringVisualizationData = AttributeVisualizationUtils_1.AttributeVisualizationUtils.stringVisualization(itemDataAttribute.value, stringAttribute.values ||
|
|
271
|
-
(itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.values), stringAttribute.visualization, __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
272
|
-
if (!stringVisualizationData) {
|
|
273
|
-
return {
|
|
274
|
-
matrix: IDENTITY_MATRIX,
|
|
275
|
-
material,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
stringVisualizationData.material.opacity *=
|
|
280
|
-
layer.opacity;
|
|
281
|
-
return stringVisualizationData;
|
|
282
|
-
}
|
|
283
|
-
default:
|
|
284
|
-
const defaultAttribute = a;
|
|
285
|
-
material.color = defaultAttribute.color;
|
|
286
|
-
material.opacity *= layer.opacity;
|
|
287
|
-
return {
|
|
288
|
-
matrix: IDENTITY_MATRIX,
|
|
289
|
-
material,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
// no attributes were found, return the default material adjusted by the layer opacity
|
|
295
|
-
const mat = this.createMaterialCopy(__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
296
|
-
mat.opacity *= layer.opacity;
|
|
297
|
-
return {
|
|
298
|
-
matrix: IDENTITY_MATRIX,
|
|
299
|
-
material: mat,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
// Use the viewport's updateNode helper to directly re-convert each
|
|
304
|
-
// affected node, which re-runs injectAttributeData (and our visualizeAttributes
|
|
305
|
-
// callback) without the overhead of version-stomping the entire tree.
|
|
306
|
-
for (let i = 0; i < __classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f").length; i++) {
|
|
307
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").updateNode(__classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f")[i]);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
createMaterialCopy(material) {
|
|
311
|
-
if (material instanceof viewer_shared_node_tree_1.MaterialGemData) {
|
|
312
|
-
const newMaterial = new viewer_shared_node_tree_1.MaterialGemData();
|
|
313
|
-
newMaterial.copy(material);
|
|
314
|
-
return newMaterial;
|
|
315
|
-
}
|
|
316
|
-
else if (material instanceof viewer_shared_node_tree_1.MaterialShadowData) {
|
|
317
|
-
const newMaterial = new viewer_shared_node_tree_1.MaterialShadowData();
|
|
318
|
-
newMaterial.copy(material);
|
|
319
|
-
return newMaterial;
|
|
320
|
-
}
|
|
321
|
-
else if (material instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
|
|
322
|
-
const newMaterial = new viewer_shared_node_tree_1.MaterialSpecularGlossinessData();
|
|
323
|
-
newMaterial.copy(material);
|
|
324
|
-
return newMaterial;
|
|
325
|
-
}
|
|
326
|
-
else if (material instanceof viewer_shared_node_tree_1.MaterialStandardData) {
|
|
327
|
-
const newMaterial = new viewer_shared_node_tree_1.MaterialStandardData();
|
|
328
|
-
newMaterial.copy(material);
|
|
329
|
-
return newMaterial;
|
|
330
|
-
}
|
|
331
|
-
else if (material instanceof viewer_shared_node_tree_1.MaterialUnlitData) {
|
|
332
|
-
const newMaterial = new viewer_shared_node_tree_1.MaterialUnlitData();
|
|
333
|
-
newMaterial.copy(material);
|
|
334
|
-
return newMaterial;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
return new viewer_shared_node_tree_1.MaterialStandardData();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
createLayers() {
|
|
341
|
-
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layers, {}, "f");
|
|
342
|
-
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")["layer"]) {
|
|
343
|
-
const layerStringAttributeOverview = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")["layer"].find((a) => a.typeHint === "string");
|
|
344
|
-
if (layerStringAttributeOverview &&
|
|
345
|
-
layerStringAttributeOverview.values) {
|
|
346
|
-
for (let i = 0; i < layerStringAttributeOverview.values.length; i++) {
|
|
347
|
-
__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[layerStringAttributeOverview.values[i]] = {
|
|
348
|
-
enabled: true,
|
|
349
|
-
opacity: 1,
|
|
350
|
-
color: this.defaultMaterial.color,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
exports.AttributeVisualizationEngine = AttributeVisualizationEngine;
|
|
358
|
-
_AttributeVisualizationEngine_uuidGenerator = new WeakMap(), _AttributeVisualizationEngine_viewport = new WeakMap(), _AttributeVisualizationEngine_attributes = new WeakMap(), _AttributeVisualizationEngine_defaultMaterial = new WeakMap(), _AttributeVisualizationEngine_defaultLayer = new WeakMap(), _AttributeVisualizationEngine_layers = new WeakMap(), _AttributeVisualizationEngine_overview = new WeakMap(), _AttributeVisualizationEngine_listeners = new WeakMap(), _AttributeVisualizationEngine_visualizedMaterialType = new WeakMap(), _AttributeVisualizationEngine_layerMaterialType = new WeakMap(), _AttributeVisualizationEngine_nodesWithAttributeData = new WeakMap(), _AttributeVisualizationEngine_overviewCache = new WeakMap(), _AttributeVisualizationEngine_updateScheduled = new WeakMap();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _AttributeVisualizationEngine_uuidGenerator, _AttributeVisualizationEngine_viewport, _AttributeVisualizationEngine_attributes, _AttributeVisualizationEngine_defaultMaterial, _AttributeVisualizationEngine_defaultLayer, _AttributeVisualizationEngine_layers, _AttributeVisualizationEngine_overview, _AttributeVisualizationEngine_listeners, _AttributeVisualizationEngine_visualizedMaterialType, _AttributeVisualizationEngine_layerMaterialType, _AttributeVisualizationEngine_nodesWithAttributeData, _AttributeVisualizationEngine_overviewCache, _AttributeVisualizationEngine_updateScheduled;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AttributeVisualizationEngine = void 0;
|
|
16
|
+
/* eslint-disable no-case-declarations */
|
|
17
|
+
const viewer_1 = require("@shapediver/viewer");
|
|
18
|
+
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
19
|
+
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
20
|
+
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
21
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
22
|
+
const AttributeVisualizationUtils_1 = require("./AttributeVisualizationUtils");
|
|
23
|
+
/** Shared identity matrix — never mutate this. */
|
|
24
|
+
const IDENTITY_MATRIX = gl_matrix_1.mat4.create();
|
|
25
|
+
class AttributeVisualizationEngine {
|
|
26
|
+
// #endregion Properties (7)
|
|
27
|
+
// #region Constructors (1)
|
|
28
|
+
constructor(viewport) {
|
|
29
|
+
// #region Properties (7)
|
|
30
|
+
_AttributeVisualizationEngine_uuidGenerator.set(this, viewer_shared_services_1.UuidGenerator.instance);
|
|
31
|
+
_AttributeVisualizationEngine_viewport.set(this, void 0);
|
|
32
|
+
_AttributeVisualizationEngine_attributes.set(this, []);
|
|
33
|
+
_AttributeVisualizationEngine_defaultMaterial.set(this, new viewer_shared_node_tree_1.MaterialUnlitData({
|
|
34
|
+
color: "#000000",
|
|
35
|
+
opacity: 1,
|
|
36
|
+
}));
|
|
37
|
+
_AttributeVisualizationEngine_defaultLayer.set(this, {
|
|
38
|
+
color: "#000000",
|
|
39
|
+
opacity: 1,
|
|
40
|
+
enabled: true,
|
|
41
|
+
});
|
|
42
|
+
_AttributeVisualizationEngine_layers.set(this, {});
|
|
43
|
+
_AttributeVisualizationEngine_overview.set(this, void 0);
|
|
44
|
+
_AttributeVisualizationEngine_listeners.set(this, {});
|
|
45
|
+
_AttributeVisualizationEngine_visualizedMaterialType.set(this, "unlit");
|
|
46
|
+
_AttributeVisualizationEngine_layerMaterialType.set(this, "unlit");
|
|
47
|
+
_AttributeVisualizationEngine_nodesWithAttributeData.set(this, []);
|
|
48
|
+
/** Pre-cached overview lookups keyed by "attributeKey:typeHint" */
|
|
49
|
+
_AttributeVisualizationEngine_overviewCache.set(this, new Map());
|
|
50
|
+
_AttributeVisualizationEngine_updateScheduled.set(this, false);
|
|
51
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_viewport, viewport, "f");
|
|
52
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_overview, __classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").createSDTFOverview(viewer_1.sceneTree.root), "f");
|
|
53
|
+
this.createLayers();
|
|
54
|
+
this.gatherNodesWithAttributeData();
|
|
55
|
+
this.buildOverviewCache();
|
|
56
|
+
this.constructAttributeVisualization();
|
|
57
|
+
const cb = () => {
|
|
58
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_overview, __classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").createSDTFOverview(viewer_1.sceneTree.root), "f");
|
|
59
|
+
const layers = __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f");
|
|
60
|
+
this.createLayers();
|
|
61
|
+
for (const l in layers) {
|
|
62
|
+
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[l])
|
|
63
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[l] = layers[l];
|
|
64
|
+
}
|
|
65
|
+
this.gatherNodesWithAttributeData();
|
|
66
|
+
this.buildOverviewCache();
|
|
67
|
+
this.constructAttributeVisualization();
|
|
68
|
+
for (const l in __classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f"))
|
|
69
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[l]();
|
|
70
|
+
};
|
|
71
|
+
(0, viewer_1.addListener)(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, cb);
|
|
72
|
+
(0, viewer_1.addListener)(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_SDTF_DELAYED_LOADED, cb);
|
|
73
|
+
}
|
|
74
|
+
// #endregion Constructors (1)
|
|
75
|
+
// #region Public Accessors (3)
|
|
76
|
+
gatherNodesWithAttributeData() {
|
|
77
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_nodesWithAttributeData, [], "f");
|
|
78
|
+
viewer_1.sceneTree.root.traverse((node) => {
|
|
79
|
+
const data = node.data;
|
|
80
|
+
for (let i = 0, len = data.length; i < len; i++) {
|
|
81
|
+
if (data[i] instanceof viewer_shared_node_tree_1.SDTFItemData) {
|
|
82
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f").push(node);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
get defaultMaterial() {
|
|
89
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f");
|
|
90
|
+
}
|
|
91
|
+
get defaultLayer() {
|
|
92
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f");
|
|
93
|
+
}
|
|
94
|
+
get layers() {
|
|
95
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f");
|
|
96
|
+
}
|
|
97
|
+
get layerMaterialType() {
|
|
98
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f");
|
|
99
|
+
}
|
|
100
|
+
get visualizedMaterialType() {
|
|
101
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f");
|
|
102
|
+
}
|
|
103
|
+
get overview() {
|
|
104
|
+
return __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f");
|
|
105
|
+
}
|
|
106
|
+
// #endregion Public Accessors (3)
|
|
107
|
+
// #region Public Methods (3)
|
|
108
|
+
updateAttributes(attributes) {
|
|
109
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_attributes, attributes, "f");
|
|
110
|
+
this.buildOverviewCache();
|
|
111
|
+
this.scheduleUpdate();
|
|
112
|
+
}
|
|
113
|
+
updateDefaultLayer(layer) {
|
|
114
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_defaultLayer, layer, "f");
|
|
115
|
+
this.scheduleUpdate();
|
|
116
|
+
}
|
|
117
|
+
updateDefaultMaterial(material) {
|
|
118
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_defaultMaterial, material, "f");
|
|
119
|
+
this.scheduleUpdate();
|
|
120
|
+
}
|
|
121
|
+
updateLayerMaterialType(type) {
|
|
122
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layerMaterialType, type, "f");
|
|
123
|
+
this.createLayers();
|
|
124
|
+
this.scheduleUpdate();
|
|
125
|
+
}
|
|
126
|
+
updateVisualizedMaterialType(type) {
|
|
127
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_visualizedMaterialType, type, "f");
|
|
128
|
+
this.createLayers();
|
|
129
|
+
this.scheduleUpdate();
|
|
130
|
+
}
|
|
131
|
+
updateLayers(layers) {
|
|
132
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layers, layers, "f");
|
|
133
|
+
this.scheduleUpdate();
|
|
134
|
+
}
|
|
135
|
+
addListener(cb) {
|
|
136
|
+
const token = __classPrivateFieldGet(this, _AttributeVisualizationEngine_uuidGenerator, "f").create();
|
|
137
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token] = cb;
|
|
138
|
+
return token;
|
|
139
|
+
}
|
|
140
|
+
removeListener(token) {
|
|
141
|
+
if (!__classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token])
|
|
142
|
+
return false;
|
|
143
|
+
delete __classPrivateFieldGet(this, _AttributeVisualizationEngine_listeners, "f")[token];
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
// #endregion Public Methods (3)
|
|
147
|
+
// #region Private Methods
|
|
148
|
+
/**
|
|
149
|
+
* Coalesce multiple rapid update calls into a single
|
|
150
|
+
* constructAttributeVisualization + invalidation pass using microtask scheduling.
|
|
151
|
+
*/
|
|
152
|
+
scheduleUpdate() {
|
|
153
|
+
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_updateScheduled, "f"))
|
|
154
|
+
return;
|
|
155
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_updateScheduled, true, "f");
|
|
156
|
+
queueMicrotask(() => {
|
|
157
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_updateScheduled, false, "f");
|
|
158
|
+
this.constructAttributeVisualization();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Pre-build a lookup map from "key:typeHint" -> ISDTFAttributeOverview
|
|
163
|
+
* so the hot-path callback avoids Array.filter() per geometry item.
|
|
164
|
+
*/
|
|
165
|
+
buildOverviewCache() {
|
|
166
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").clear();
|
|
167
|
+
for (const a of __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f")) {
|
|
168
|
+
const overviewEntries = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")[a.key];
|
|
169
|
+
if (!overviewEntries)
|
|
170
|
+
continue;
|
|
171
|
+
for (let j = 0; j < overviewEntries.length; j++) {
|
|
172
|
+
if (overviewEntries[j].typeHint === a.type) {
|
|
173
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").set(a.key + ":" + a.type, overviewEntries[j]);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
createMaterial(type, color, opacity) {
|
|
180
|
+
return type === "unlit"
|
|
181
|
+
? new viewer_shared_node_tree_1.MaterialUnlitData({ color, opacity })
|
|
182
|
+
: new viewer_shared_node_tree_1.MaterialStandardData({ color, opacity });
|
|
183
|
+
}
|
|
184
|
+
constructAttributeVisualization() {
|
|
185
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").visualizeAttributes = (_overview, itemData) => {
|
|
186
|
+
// early out if there are not attributes in this itemData
|
|
187
|
+
if (!itemData || !itemData.attributes) {
|
|
188
|
+
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length === 0) {
|
|
189
|
+
return {
|
|
190
|
+
matrix: IDENTITY_MATRIX,
|
|
191
|
+
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").color, __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").enabled
|
|
192
|
+
? __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").opacity
|
|
193
|
+
: 0),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return {
|
|
198
|
+
matrix: IDENTITY_MATRIX,
|
|
199
|
+
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f").color, __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").enabled
|
|
200
|
+
? __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultLayer, "f").opacity *
|
|
201
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f").opacity
|
|
202
|
+
: 0),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// search for the responsible layer property, if none is found, default layer is assigned
|
|
207
|
+
let layer = this.defaultLayer;
|
|
208
|
+
if (itemData.attributes["layer"] &&
|
|
209
|
+
viewer_shared_types_1.SdtfPrimitiveTypeGuard.isStringType(itemData.attributes["layer"].typeHint)) {
|
|
210
|
+
const layerAttributes = itemData.attributes["layer"];
|
|
211
|
+
layer = __classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[layerAttributes.value];
|
|
212
|
+
}
|
|
213
|
+
// early out, layer is not enabled
|
|
214
|
+
if (layer.enabled === false) {
|
|
215
|
+
const mat = this.createMaterialCopy(__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
216
|
+
mat.opacity = 0;
|
|
217
|
+
return {
|
|
218
|
+
matrix: IDENTITY_MATRIX,
|
|
219
|
+
material: mat,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length === 0) {
|
|
223
|
+
// no attributes are specified, we go into layer visualization mode
|
|
224
|
+
return {
|
|
225
|
+
matrix: IDENTITY_MATRIX,
|
|
226
|
+
material: this.createMaterial(__classPrivateFieldGet(this, _AttributeVisualizationEngine_layerMaterialType, "f"), layer.color, layer.opacity),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// attributes are specified, we go into attribute visualization mode
|
|
231
|
+
const material = __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f") === "unlit"
|
|
232
|
+
? new viewer_shared_node_tree_1.MaterialUnlitData()
|
|
233
|
+
: new viewer_shared_node_tree_1.MaterialStandardData();
|
|
234
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f").length; i++) {
|
|
235
|
+
const a = __classPrivateFieldGet(this, _AttributeVisualizationEngine_attributes, "f")[i];
|
|
236
|
+
if (itemData.attributes[a.key] &&
|
|
237
|
+
itemData.attributes[a.key].typeHint === a.type) {
|
|
238
|
+
const itemDataAttribute = itemData.attributes[a.key];
|
|
239
|
+
const itemDataAttributeOverview = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overviewCache, "f").get(a.key + ":" + a.type);
|
|
240
|
+
switch (true) {
|
|
241
|
+
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isColorType(a.type):
|
|
242
|
+
// multiply each color values with 255 to convert them to the range [0, 255]
|
|
243
|
+
const convertedValue = itemDataAttribute.value.map((v) => v * 255);
|
|
244
|
+
material.color = convertedValue;
|
|
245
|
+
material.opacity *= layer.opacity;
|
|
246
|
+
return {
|
|
247
|
+
matrix: IDENTITY_MATRIX,
|
|
248
|
+
material,
|
|
249
|
+
};
|
|
250
|
+
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isNumberType(a.type):
|
|
251
|
+
const numberAttribute = a;
|
|
252
|
+
const numberVisualizationData = AttributeVisualizationUtils_1.AttributeVisualizationUtils.numberVisualization(itemDataAttribute.value, (numberAttribute.min !== undefined
|
|
253
|
+
? numberAttribute.min
|
|
254
|
+
: itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.min), (numberAttribute.max !== undefined
|
|
255
|
+
? numberAttribute.max
|
|
256
|
+
: itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.max), numberAttribute.visualization, __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
257
|
+
if (!numberVisualizationData) {
|
|
258
|
+
return {
|
|
259
|
+
matrix: IDENTITY_MATRIX,
|
|
260
|
+
material,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
numberVisualizationData.material.opacity *=
|
|
265
|
+
layer.opacity;
|
|
266
|
+
return numberVisualizationData;
|
|
267
|
+
}
|
|
268
|
+
case viewer_shared_types_1.SdtfPrimitiveTypeGuard.isStringType(a.type):
|
|
269
|
+
const stringAttribute = a;
|
|
270
|
+
const stringVisualizationData = AttributeVisualizationUtils_1.AttributeVisualizationUtils.stringVisualization(itemDataAttribute.value, stringAttribute.values ||
|
|
271
|
+
(itemDataAttributeOverview === null || itemDataAttributeOverview === void 0 ? void 0 : itemDataAttributeOverview.values), stringAttribute.visualization, __classPrivateFieldGet(this, _AttributeVisualizationEngine_visualizedMaterialType, "f"), __classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
272
|
+
if (!stringVisualizationData) {
|
|
273
|
+
return {
|
|
274
|
+
matrix: IDENTITY_MATRIX,
|
|
275
|
+
material,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
stringVisualizationData.material.opacity *=
|
|
280
|
+
layer.opacity;
|
|
281
|
+
return stringVisualizationData;
|
|
282
|
+
}
|
|
283
|
+
default:
|
|
284
|
+
const defaultAttribute = a;
|
|
285
|
+
material.color = defaultAttribute.color;
|
|
286
|
+
material.opacity *= layer.opacity;
|
|
287
|
+
return {
|
|
288
|
+
matrix: IDENTITY_MATRIX,
|
|
289
|
+
material,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// no attributes were found, return the default material adjusted by the layer opacity
|
|
295
|
+
const mat = this.createMaterialCopy(__classPrivateFieldGet(this, _AttributeVisualizationEngine_defaultMaterial, "f"));
|
|
296
|
+
mat.opacity *= layer.opacity;
|
|
297
|
+
return {
|
|
298
|
+
matrix: IDENTITY_MATRIX,
|
|
299
|
+
material: mat,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
// Use the viewport's updateNode helper to directly re-convert each
|
|
304
|
+
// affected node, which re-runs injectAttributeData (and our visualizeAttributes
|
|
305
|
+
// callback) without the overhead of version-stomping the entire tree.
|
|
306
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f").length; i++) {
|
|
307
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_viewport, "f").updateNode(__classPrivateFieldGet(this, _AttributeVisualizationEngine_nodesWithAttributeData, "f")[i]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
createMaterialCopy(material) {
|
|
311
|
+
if (material instanceof viewer_shared_node_tree_1.MaterialGemData) {
|
|
312
|
+
const newMaterial = new viewer_shared_node_tree_1.MaterialGemData();
|
|
313
|
+
newMaterial.copy(material);
|
|
314
|
+
return newMaterial;
|
|
315
|
+
}
|
|
316
|
+
else if (material instanceof viewer_shared_node_tree_1.MaterialShadowData) {
|
|
317
|
+
const newMaterial = new viewer_shared_node_tree_1.MaterialShadowData();
|
|
318
|
+
newMaterial.copy(material);
|
|
319
|
+
return newMaterial;
|
|
320
|
+
}
|
|
321
|
+
else if (material instanceof viewer_shared_node_tree_1.MaterialSpecularGlossinessData) {
|
|
322
|
+
const newMaterial = new viewer_shared_node_tree_1.MaterialSpecularGlossinessData();
|
|
323
|
+
newMaterial.copy(material);
|
|
324
|
+
return newMaterial;
|
|
325
|
+
}
|
|
326
|
+
else if (material instanceof viewer_shared_node_tree_1.MaterialStandardData) {
|
|
327
|
+
const newMaterial = new viewer_shared_node_tree_1.MaterialStandardData();
|
|
328
|
+
newMaterial.copy(material);
|
|
329
|
+
return newMaterial;
|
|
330
|
+
}
|
|
331
|
+
else if (material instanceof viewer_shared_node_tree_1.MaterialUnlitData) {
|
|
332
|
+
const newMaterial = new viewer_shared_node_tree_1.MaterialUnlitData();
|
|
333
|
+
newMaterial.copy(material);
|
|
334
|
+
return newMaterial;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
return new viewer_shared_node_tree_1.MaterialStandardData();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
createLayers() {
|
|
341
|
+
__classPrivateFieldSet(this, _AttributeVisualizationEngine_layers, {}, "f");
|
|
342
|
+
if (__classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")["layer"]) {
|
|
343
|
+
const layerStringAttributeOverview = __classPrivateFieldGet(this, _AttributeVisualizationEngine_overview, "f")["layer"].find((a) => a.typeHint === "string");
|
|
344
|
+
if (layerStringAttributeOverview &&
|
|
345
|
+
layerStringAttributeOverview.values) {
|
|
346
|
+
for (let i = 0; i < layerStringAttributeOverview.values.length; i++) {
|
|
347
|
+
__classPrivateFieldGet(this, _AttributeVisualizationEngine_layers, "f")[layerStringAttributeOverview.values[i]] = {
|
|
348
|
+
enabled: true,
|
|
349
|
+
opacity: 1,
|
|
350
|
+
color: this.defaultMaterial.color,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
exports.AttributeVisualizationEngine = AttributeVisualizationEngine;
|
|
358
|
+
_AttributeVisualizationEngine_uuidGenerator = new WeakMap(), _AttributeVisualizationEngine_viewport = new WeakMap(), _AttributeVisualizationEngine_attributes = new WeakMap(), _AttributeVisualizationEngine_defaultMaterial = new WeakMap(), _AttributeVisualizationEngine_defaultLayer = new WeakMap(), _AttributeVisualizationEngine_layers = new WeakMap(), _AttributeVisualizationEngine_overview = new WeakMap(), _AttributeVisualizationEngine_listeners = new WeakMap(), _AttributeVisualizationEngine_visualizedMaterialType = new WeakMap(), _AttributeVisualizationEngine_layerMaterialType = new WeakMap(), _AttributeVisualizationEngine_nodesWithAttributeData = new WeakMap(), _AttributeVisualizationEngine_overviewCache = new WeakMap(), _AttributeVisualizationEngine_updateScheduled = new WeakMap();
|
|
359
359
|
//# sourceMappingURL=AttributeVisualizationEngine.js.map
|