@buerli.io/core 1.0.0 → 1.0.1-beta.2
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/README.md +19 -19
- package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
- package/build/cjs/geometry/index.js +17 -17
- package/build/cjs/graphic/filters.js +25 -25
- package/build/cjs/index.js +26 -26
- package/build/cjs/re-export.js +29 -29
- package/build/cjs/store/index.js +37 -37
- package/build/cjs/store/states/buerli.js +98 -98
- package/build/cjs/store/states/cad.js +47 -47
- package/build/cjs/store/states/drawing.js +49 -49
- package/build/cjs/store/states/geometry.js +157 -157
- package/build/cjs/store/states/graphic.js +115 -115
- package/build/cjs/store/states/interaction.js +55 -55
- package/build/cjs/store/states/message.js +25 -25
- package/build/cjs/store/states/plugin.js +115 -115
- package/build/cjs/store/states/selection.js +267 -267
- package/build/cjs/store/states/structure.js +250 -250
- package/build/cjs/store/store.js +9 -9
- package/build/cjs/store/subscribtion/selection.js +49 -49
- package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -13
- package/build/cjs/types/InteractionInfo.js +11 -11
- package/build/cjs/types/index.js +34 -34
- package/build/cjs/utils/Math.js +91 -91
- package/build/cjs/utils/Measure.js +576 -576
- package/build/cjs/utils/Timing.js +34 -34
- package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
- package/build/esm/geometry/index.js +1 -1
- package/build/esm/graphic/filters.js +12 -12
- package/build/esm/index.js +10 -10
- package/build/esm/re-export.js +23 -23
- package/build/esm/store/index.js +26 -26
- package/build/esm/store/states/buerli.js +92 -92
- package/build/esm/store/states/cad.js +42 -42
- package/build/esm/store/states/drawing.js +45 -45
- package/build/esm/store/states/geometry.js +129 -129
- package/build/esm/store/states/graphic.js +110 -110
- package/build/esm/store/states/interaction.js +50 -50
- package/build/esm/store/states/message.js +21 -21
- package/build/esm/store/states/plugin.js +109 -109
- package/build/esm/store/states/selection.js +261 -261
- package/build/esm/store/states/structure.js +219 -219
- package/build/esm/store/store.js +3 -3
- package/build/esm/store/subscribtion/selection.js +44 -44
- package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
- package/build/esm/types/InteractionInfo.js +6 -6
- package/build/esm/types/index.js +16 -16
- package/build/esm/utils/Math.js +65 -65
- package/build/esm/utils/Measure.js +550 -550
- package/build/esm/utils/Timing.js +31 -31
- package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
- package/build/types/geometry/index.d.ts +1 -1
- package/build/types/graphic/filters.d.ts +11 -11
- package/build/types/index.d.ts +38 -38
- package/build/types/re-export.d.ts +70 -70
- package/build/types/store/index.d.ts +16 -16
- package/build/types/store/states/buerli.d.ts +41 -41
- package/build/types/store/states/cad.d.ts +56 -56
- package/build/types/store/states/drawing.d.ts +45 -45
- package/build/types/store/states/geometry.d.ts +64 -64
- package/build/types/store/states/graphic.d.ts +21 -21
- package/build/types/store/states/interaction.d.ts +34 -34
- package/build/types/store/states/message.d.ts +30 -30
- package/build/types/store/states/plugin.d.ts +53 -53
- package/build/types/store/states/selection.d.ts +69 -69
- package/build/types/store/states/structure.d.ts +47 -47
- package/build/types/store/store.d.ts +2 -2
- package/build/types/store/subscribtion/selection.d.ts +7 -7
- package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
- package/build/types/types/InteractionInfo.d.ts +42 -42
- package/build/types/types/index.d.ts +7 -7
- package/build/types/utils/Math.d.ts +21 -21
- package/build/types/utils/Measure.d.ts +64 -64
- package/build/types/utils/Timing.d.ts +8 -8
- package/package.json +45 -45
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**!
|
|
3
|
-
* The Drawing manages all necessary data that belong to a model.
|
|
4
|
-
*
|
|
5
|
-
* On the one hand these are the structure and graphic data by which the
|
|
6
|
-
* CAD model is defined, on the other hand it administers additional data
|
|
7
|
-
* for the support with the client-sided development.
|
|
8
|
-
*
|
|
9
|
-
* @image /doc/assets/core/drawing.png
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createDrawingState = void 0;
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const cad_1 = require("./cad");
|
|
15
|
-
const geometry_1 = require("./geometry");
|
|
16
|
-
const graphic_1 = require("./graphic");
|
|
17
|
-
const interaction_1 = require("./interaction");
|
|
18
|
-
const plugin_1 = require("./plugin");
|
|
19
|
-
const selection_1 = require("./selection");
|
|
20
|
-
const structure_1 = require("./structure");
|
|
21
|
-
////////////////////////////////////////////////////
|
|
22
|
-
// DATA
|
|
23
|
-
////////////////////////////////////////////////////
|
|
24
|
-
const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
|
|
25
|
-
const drawingId = (0, uuid_1.v4)();
|
|
26
|
-
const initialData = () => ({
|
|
27
|
-
structure: (0, structure_1.structureData)(),
|
|
28
|
-
selection: (0, selection_1.selectionData)(),
|
|
29
|
-
interaction: (0, interaction_1.interactionData)(),
|
|
30
|
-
plugin: (0, plugin_1.pluginData)(),
|
|
31
|
-
geometry: (0, geometry_1.geometryData)(),
|
|
32
|
-
graphic: (0, graphic_1.graphicData)(),
|
|
33
|
-
cad: (0, cad_1.cadData)(),
|
|
34
|
-
});
|
|
35
|
-
return Object.assign(Object.assign({}, initialData()), { api: {
|
|
36
|
-
structure: (0, structure_1.structureApi)(set, get, buerliApi),
|
|
37
|
-
selection: (0, selection_1.selectionApi)(set, get, buerliApi),
|
|
38
|
-
plugin: (0, plugin_1.pluginApi)(set, get, buerliApi),
|
|
39
|
-
geometry: (0, geometry_1.geometryApi)(set, get, buerliApi),
|
|
40
|
-
graphic: (0, graphic_1.graphicApi)(set, get, buerliApi),
|
|
41
|
-
cad: (0, cad_1.cadApi)(set, get, buerliApi),
|
|
42
|
-
interaction: (0, interaction_1.interactionApi)(set, get, buerliApi),
|
|
43
|
-
reset: () => {
|
|
44
|
-
set(state => (Object.assign(Object.assign({}, state), initialData())));
|
|
45
|
-
buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
|
|
46
|
-
},
|
|
47
|
-
}, id: drawingId, name: name || `Drawing #${drawingNumber}` });
|
|
48
|
-
};
|
|
49
|
-
exports.createDrawingState = createDrawingState;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**!
|
|
3
|
+
* The Drawing manages all necessary data that belong to a model.
|
|
4
|
+
*
|
|
5
|
+
* On the one hand these are the structure and graphic data by which the
|
|
6
|
+
* CAD model is defined, on the other hand it administers additional data
|
|
7
|
+
* for the support with the client-sided development.
|
|
8
|
+
*
|
|
9
|
+
* @image /doc/assets/core/drawing.png
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createDrawingState = void 0;
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const cad_1 = require("./cad");
|
|
15
|
+
const geometry_1 = require("./geometry");
|
|
16
|
+
const graphic_1 = require("./graphic");
|
|
17
|
+
const interaction_1 = require("./interaction");
|
|
18
|
+
const plugin_1 = require("./plugin");
|
|
19
|
+
const selection_1 = require("./selection");
|
|
20
|
+
const structure_1 = require("./structure");
|
|
21
|
+
////////////////////////////////////////////////////
|
|
22
|
+
// DATA
|
|
23
|
+
////////////////////////////////////////////////////
|
|
24
|
+
const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
|
|
25
|
+
const drawingId = (0, uuid_1.v4)();
|
|
26
|
+
const initialData = () => ({
|
|
27
|
+
structure: (0, structure_1.structureData)(),
|
|
28
|
+
selection: (0, selection_1.selectionData)(),
|
|
29
|
+
interaction: (0, interaction_1.interactionData)(),
|
|
30
|
+
plugin: (0, plugin_1.pluginData)(),
|
|
31
|
+
geometry: (0, geometry_1.geometryData)(),
|
|
32
|
+
graphic: (0, graphic_1.graphicData)(),
|
|
33
|
+
cad: (0, cad_1.cadData)(),
|
|
34
|
+
});
|
|
35
|
+
return Object.assign(Object.assign({}, initialData()), { api: {
|
|
36
|
+
structure: (0, structure_1.structureApi)(set, get, buerliApi),
|
|
37
|
+
selection: (0, selection_1.selectionApi)(set, get, buerliApi),
|
|
38
|
+
plugin: (0, plugin_1.pluginApi)(set, get, buerliApi),
|
|
39
|
+
geometry: (0, geometry_1.geometryApi)(set, get, buerliApi),
|
|
40
|
+
graphic: (0, graphic_1.graphicApi)(set, get, buerliApi),
|
|
41
|
+
cad: (0, cad_1.cadApi)(set, get, buerliApi),
|
|
42
|
+
interaction: (0, interaction_1.interactionApi)(set, get, buerliApi),
|
|
43
|
+
reset: () => {
|
|
44
|
+
set(state => (Object.assign(Object.assign({}, state), initialData())));
|
|
45
|
+
buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
|
|
46
|
+
},
|
|
47
|
+
}, id: drawingId, name: name || `Drawing #${drawingNumber}` });
|
|
48
|
+
};
|
|
49
|
+
exports.createDrawingState = createDrawingState;
|
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.geometryApi = exports.geometryData = void 0;
|
|
27
|
-
const THREE = __importStar(require("three"));
|
|
28
|
-
const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
|
|
29
|
-
////////////////////////////////////////////////////
|
|
30
|
-
// DATA
|
|
31
|
-
////////////////////////////////////////////////////
|
|
32
|
-
const geometryData = () => ({
|
|
33
|
-
cache: {},
|
|
34
|
-
stamp: -1,
|
|
35
|
-
bounds: {
|
|
36
|
-
center: new THREE.Vector3(0, 0, 0),
|
|
37
|
-
radius: 200,
|
|
38
|
-
min: new THREE.Vector3(-100, -100, -100),
|
|
39
|
-
max: new THREE.Vector3(100, 100, 100),
|
|
40
|
-
},
|
|
41
|
-
config: { product: {} },
|
|
42
|
-
});
|
|
43
|
-
exports.geometryData = geometryData;
|
|
44
|
-
////////////////////////////////////////////////////
|
|
45
|
-
// API
|
|
46
|
-
////////////////////////////////////////////////////
|
|
47
|
-
const geometryApi = (set, get, buerliApi) => ({
|
|
48
|
-
/**
|
|
49
|
-
* Updates the @see geometry.bounds depending on all products of the model.
|
|
50
|
-
* The update will only happen, if at least one solid of one product is available.
|
|
51
|
-
*/
|
|
52
|
-
updateBounds: () => {
|
|
53
|
-
const { api, structure } = get();
|
|
54
|
-
if (structure.visibleContainers.length > 0) {
|
|
55
|
-
const bb = api.structure.calculateProductBounds(structure.root);
|
|
56
|
-
set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
createGeometryIfNotCached: (containerId, color) => {
|
|
60
|
-
const { graphic, geometry } = get();
|
|
61
|
-
let geom = geometry.cache[containerId];
|
|
62
|
-
if (!geom) {
|
|
63
|
-
const container = graphic.containers[containerId];
|
|
64
|
-
if (container) {
|
|
65
|
-
geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
|
|
66
|
-
set(state => {
|
|
67
|
-
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
|
|
68
|
-
return {
|
|
69
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return geom;
|
|
75
|
-
},
|
|
76
|
-
setGraphicColor: (containerId, graphicId, r, g, b) => {
|
|
77
|
-
// Provide values as a CSS color string, which will be gamma corrected by three.js
|
|
78
|
-
const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
|
|
79
|
-
set(state => {
|
|
80
|
-
// If container cache is empty return
|
|
81
|
-
if (!state.geometry.cache[containerId])
|
|
82
|
-
return state;
|
|
83
|
-
// Shallow clone meshes
|
|
84
|
-
const meshes = [...state.geometry.cache[containerId].meshes];
|
|
85
|
-
// Find graphic Object
|
|
86
|
-
const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
|
|
87
|
-
if (!graphic)
|
|
88
|
-
return state;
|
|
89
|
-
// Apply color
|
|
90
|
-
meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
|
|
91
|
-
return {
|
|
92
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, state.geometry.cache[containerId]), { meshes, dirtyStamp: Date.now() }) }) }),
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
setContainerColor: (containerId, r, g, b) => {
|
|
97
|
-
// Provide values as a CSS color string, which will be gamma corrected by three.js
|
|
98
|
-
const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
|
|
99
|
-
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
|
|
100
|
-
set(state => ({
|
|
101
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
102
|
-
}));
|
|
103
|
-
},
|
|
104
|
-
setOpacity: (containerId, opacity) => {
|
|
105
|
-
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
|
|
106
|
-
set(state => ({
|
|
107
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
108
|
-
}));
|
|
109
|
-
},
|
|
110
|
-
setConfig: (objId, config) => {
|
|
111
|
-
set(state => {
|
|
112
|
-
const productConfigs = Object.assign({}, state.geometry.config.product);
|
|
113
|
-
if (config) {
|
|
114
|
-
const newConfig = Object.assign({}, state.geometry.config.product[objId]);
|
|
115
|
-
if ('disabled' in config)
|
|
116
|
-
newConfig.disabled = config.disabled;
|
|
117
|
-
if ('edges' in config)
|
|
118
|
-
newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
|
|
119
|
-
if ('meshes' in config)
|
|
120
|
-
newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
|
|
121
|
-
if ('points' in config)
|
|
122
|
-
newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
|
|
123
|
-
productConfigs[objId] = newConfig;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
delete productConfigs[objId];
|
|
127
|
-
}
|
|
128
|
-
return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
findDecorated: () => {
|
|
132
|
-
const { geometry: api } = get().api;
|
|
133
|
-
return api.filter(elem => { var _a, _b, _c, _d, _e; return Boolean((_b = (_a = elem.rawGraphic) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.label) || Boolean((_e = (_d = (_c = elem.rawGraphic) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.material) === null || _e === void 0 ? void 0 : _e.color); });
|
|
134
|
-
},
|
|
135
|
-
filter: (cb, options) => {
|
|
136
|
-
const result = [];
|
|
137
|
-
const { cache } = get().geometry;
|
|
138
|
-
const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
|
|
139
|
-
for (const contId of contIds) {
|
|
140
|
-
if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
|
|
144
|
-
for (const id of ids) {
|
|
145
|
-
const elem = cache[contId].map[id];
|
|
146
|
-
if (cb(elem)) {
|
|
147
|
-
result.push(elem);
|
|
148
|
-
if (options === null || options === void 0 ? void 0 : options.onlyOne) {
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return result;
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
exports.geometryApi = geometryApi;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.geometryApi = exports.geometryData = void 0;
|
|
27
|
+
const THREE = __importStar(require("three"));
|
|
28
|
+
const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
|
|
29
|
+
////////////////////////////////////////////////////
|
|
30
|
+
// DATA
|
|
31
|
+
////////////////////////////////////////////////////
|
|
32
|
+
const geometryData = () => ({
|
|
33
|
+
cache: {},
|
|
34
|
+
stamp: -1,
|
|
35
|
+
bounds: {
|
|
36
|
+
center: new THREE.Vector3(0, 0, 0),
|
|
37
|
+
radius: 200,
|
|
38
|
+
min: new THREE.Vector3(-100, -100, -100),
|
|
39
|
+
max: new THREE.Vector3(100, 100, 100),
|
|
40
|
+
},
|
|
41
|
+
config: { product: {} },
|
|
42
|
+
});
|
|
43
|
+
exports.geometryData = geometryData;
|
|
44
|
+
////////////////////////////////////////////////////
|
|
45
|
+
// API
|
|
46
|
+
////////////////////////////////////////////////////
|
|
47
|
+
const geometryApi = (set, get, buerliApi) => ({
|
|
48
|
+
/**
|
|
49
|
+
* Updates the @see geometry.bounds depending on all products of the model.
|
|
50
|
+
* The update will only happen, if at least one solid of one product is available.
|
|
51
|
+
*/
|
|
52
|
+
updateBounds: () => {
|
|
53
|
+
const { api, structure } = get();
|
|
54
|
+
if (structure.visibleContainers.length > 0) {
|
|
55
|
+
const bb = api.structure.calculateProductBounds(structure.root);
|
|
56
|
+
set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
createGeometryIfNotCached: (containerId, color) => {
|
|
60
|
+
const { graphic, geometry } = get();
|
|
61
|
+
let geom = geometry.cache[containerId];
|
|
62
|
+
if (!geom) {
|
|
63
|
+
const container = graphic.containers[containerId];
|
|
64
|
+
if (container) {
|
|
65
|
+
geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
|
|
66
|
+
set(state => {
|
|
67
|
+
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
|
|
68
|
+
return {
|
|
69
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return geom;
|
|
75
|
+
},
|
|
76
|
+
setGraphicColor: (containerId, graphicId, r, g, b) => {
|
|
77
|
+
// Provide values as a CSS color string, which will be gamma corrected by three.js
|
|
78
|
+
const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
|
|
79
|
+
set(state => {
|
|
80
|
+
// If container cache is empty return
|
|
81
|
+
if (!state.geometry.cache[containerId])
|
|
82
|
+
return state;
|
|
83
|
+
// Shallow clone meshes
|
|
84
|
+
const meshes = [...state.geometry.cache[containerId].meshes];
|
|
85
|
+
// Find graphic Object
|
|
86
|
+
const graphic = meshes.find(mesh => mesh.graphicId === graphicId);
|
|
87
|
+
if (!graphic)
|
|
88
|
+
return state;
|
|
89
|
+
// Apply color
|
|
90
|
+
meshes[meshes.indexOf(graphic)] = Object.assign(Object.assign({}, graphic), { color });
|
|
91
|
+
return {
|
|
92
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, state.geometry.cache[containerId]), { meshes, dirtyStamp: Date.now() }) }) }),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
setContainerColor: (containerId, r, g, b) => {
|
|
97
|
+
// Provide values as a CSS color string, which will be gamma corrected by three.js
|
|
98
|
+
const color = new THREE.Color(`rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`);
|
|
99
|
+
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { color });
|
|
100
|
+
set(state => ({
|
|
101
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
102
|
+
}));
|
|
103
|
+
},
|
|
104
|
+
setOpacity: (containerId, opacity) => {
|
|
105
|
+
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
|
|
106
|
+
set(state => ({
|
|
107
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
108
|
+
}));
|
|
109
|
+
},
|
|
110
|
+
setConfig: (objId, config) => {
|
|
111
|
+
set(state => {
|
|
112
|
+
const productConfigs = Object.assign({}, state.geometry.config.product);
|
|
113
|
+
if (config) {
|
|
114
|
+
const newConfig = Object.assign({}, state.geometry.config.product[objId]);
|
|
115
|
+
if ('disabled' in config)
|
|
116
|
+
newConfig.disabled = config.disabled;
|
|
117
|
+
if ('edges' in config)
|
|
118
|
+
newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
|
|
119
|
+
if ('meshes' in config)
|
|
120
|
+
newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
|
|
121
|
+
if ('points' in config)
|
|
122
|
+
newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
|
|
123
|
+
productConfigs[objId] = newConfig;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
delete productConfigs[objId];
|
|
127
|
+
}
|
|
128
|
+
return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
findDecorated: () => {
|
|
132
|
+
const { geometry: api } = get().api;
|
|
133
|
+
return api.filter(elem => { var _a, _b, _c, _d, _e; return Boolean((_b = (_a = elem.rawGraphic) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.label) || Boolean((_e = (_d = (_c = elem.rawGraphic) === null || _c === void 0 ? void 0 : _c.properties) === null || _d === void 0 ? void 0 : _d.material) === null || _e === void 0 ? void 0 : _e.color); });
|
|
134
|
+
},
|
|
135
|
+
filter: (cb, options) => {
|
|
136
|
+
const result = [];
|
|
137
|
+
const { cache } = get().geometry;
|
|
138
|
+
const contIds = Object.getOwnPropertyNames(cache).map(n => Number(n));
|
|
139
|
+
for (const contId of contIds) {
|
|
140
|
+
if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const ids = Object.getOwnPropertyNames(cache[contId].map).map(id => Number(id));
|
|
144
|
+
for (const id of ids) {
|
|
145
|
+
const elem = cache[contId].map[id];
|
|
146
|
+
if (cb(elem)) {
|
|
147
|
+
result.push(elem);
|
|
148
|
+
if (options === null || options === void 0 ? void 0 : options.onlyOne) {
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
exports.geometryApi = geometryApi;
|