ducjs 4.0.4 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/duc_locator_wasm.d.ts +48 -0
- package/dist/duc_locator_wasm.js +296 -0
- package/dist/duc_locator_wasm_bg.wasm +0 -0
- package/dist/duc_locator_wasm_bg.wasm.d.ts +13 -0
- package/dist/ducjs_wasi.wasm +0 -0
- package/dist/ducjs_wasm.d.ts +14 -2
- package/dist/ducjs_wasm.js +96 -8
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/ducjs_wasm_bg.wasm.d.ts +6 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/locator-runtime.d.ts +4 -0
- package/dist/locator-runtime.js +7 -0
- package/dist/restore/index.d.ts +1 -0
- package/dist/restore/index.js +1 -0
- package/dist/restore/restoreDataState.d.ts +13 -24
- package/dist/restore/restoreDataState.js +49 -83
- package/dist/restore/restoreElements.d.ts +10 -15
- package/dist/restore/restoreElements.js +128 -125
- package/dist/restore/updateModelCode.d.ts +11 -0
- package/dist/restore/updateModelCode.js +63 -0
- package/dist/thumbnails/bounds.d.ts +21 -0
- package/dist/thumbnails/bounds.js +84 -0
- package/dist/thumbnails/browserRunner.d.ts +60 -0
- package/dist/thumbnails/browserRunner.js +446 -0
- package/dist/thumbnails/cameraPresets.d.ts +47 -0
- package/dist/thumbnails/cameraPresets.js +222 -0
- package/dist/thumbnails/cli.d.ts +2 -0
- package/dist/thumbnails/cli.js +102 -0
- package/dist/thumbnails/index.d.ts +11 -0
- package/dist/thumbnails/index.js +11 -0
- package/dist/thumbnails/lib/clientBundle.min.js +10427 -0
- package/dist/thumbnails/lib/clientEntry.d.ts +3 -0
- package/dist/thumbnails/lib/clientEntry.js +8 -0
- package/dist/thumbnails/lib/clippingUtils.d.ts +10 -0
- package/dist/thumbnails/lib/clippingUtils.js +3 -0
- package/dist/thumbnails/lib/defaultModelColor.d.ts +3 -0
- package/dist/thumbnails/lib/defaultModelColor.js +22 -0
- package/dist/thumbnails/lib/index.d.ts +12 -0
- package/dist/thumbnails/lib/index.js +12 -0
- package/dist/thumbnails/lib/mapViewerStateToOptions.d.ts +34 -0
- package/dist/thumbnails/lib/mapViewerStateToOptions.js +69 -0
- package/dist/thumbnails/lib/offscreen-dxf-thumbnail.d.ts +16 -0
- package/dist/thumbnails/lib/offscreen-dxf-thumbnail.js +173 -0
- package/dist/thumbnails/lib/offscreen-model-thumbnail.d.ts +16 -0
- package/dist/thumbnails/lib/offscreen-model-thumbnail.js +209 -0
- package/dist/thumbnails/lib/parametricClip.d.ts +18 -0
- package/dist/thumbnails/lib/parametricClip.js +177 -0
- package/dist/thumbnails/lib/parametricShapes.d.ts +1 -0
- package/dist/thumbnails/lib/parametricShapes.js +75 -0
- package/dist/thumbnails/lib/parametricViewerState.d.ts +26 -0
- package/dist/thumbnails/lib/parametricViewerState.js +198 -0
- package/dist/thumbnails/lib/thumbnail-camera-fit.d.ts +6 -0
- package/dist/thumbnails/lib/thumbnail-camera-fit.js +292 -0
- package/dist/thumbnails/lib/thumbnail-capture.d.ts +23 -0
- package/dist/thumbnails/lib/thumbnail-capture.js +161 -0
- package/dist/thumbnails/lib/thumbnail-visibility.d.ts +12 -0
- package/dist/thumbnails/lib/thumbnail-visibility.js +97 -0
- package/dist/thumbnails/lib/viewerGrid.d.ts +13 -0
- package/dist/thumbnails/lib/viewerGrid.js +57 -0
- package/dist/thumbnails/modelCache.d.ts +56 -0
- package/dist/thumbnails/modelCache.js +165 -0
- package/dist/thumbnails/modelOutputArtifact.d.ts +19 -0
- package/dist/thumbnails/modelOutputArtifact.js +87 -0
- package/dist/thumbnails/render.d.ts +45 -0
- package/dist/thumbnails/render.js +162 -0
- package/dist/thumbnails/templates.d.ts +16 -0
- package/dist/thumbnails/templates.js +786 -0
- package/dist/thumbnails/tessellator.d.ts +33 -0
- package/dist/thumbnails/tessellator.js +349 -0
- package/dist/thumbnails/types.d.ts +233 -0
- package/dist/thumbnails/types.js +1 -0
- package/dist/thumbnails/worker.d.ts +10 -0
- package/dist/thumbnails/worker.js +119 -0
- package/dist/transform.d.ts +1 -1
- package/dist/transform.js +20 -22
- package/dist/types/elements/index.d.ts +22 -28
- package/dist/types/elements/index.js +0 -1
- package/dist/types/geometry.types.d.ts +5 -5
- package/dist/types/index.d.ts +13 -59
- package/dist/types/index.js +0 -1
- package/dist/types/issues.types.d.ts +1 -2
- package/dist/utils/bounds.d.ts +10 -11
- package/dist/utils/bounds.js +105 -84
- package/dist/utils/constants.d.ts +5 -7
- package/dist/utils/constants.js +10 -15
- package/dist/utils/elements/freedrawElement.js +6 -3
- package/dist/utils/elements/index.d.ts +2 -6
- package/dist/utils/elements/index.js +4 -9
- package/dist/utils/elements/linearElement.d.ts +12 -14
- package/dist/utils/elements/linearElement.js +81 -66
- package/dist/utils/elements/newElement.d.ts +37 -22
- package/dist/utils/elements/newElement.js +70 -64
- package/dist/utils/elements/textElement.d.ts +34 -35
- package/dist/utils/elements/textElement.js +79 -83
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/locator.d.ts +43 -0
- package/dist/utils/locator.js +112 -0
- package/dist/utils/math/bbox.d.ts +1 -2
- package/dist/utils/math/geometry.js +5 -4
- package/dist/utils/math/index.d.ts +13 -17
- package/dist/utils/math/index.js +53 -41
- package/dist/utils/math/random.js +7 -2
- package/dist/utils/normalize.d.ts +5 -5
- package/dist/utils/normalize.js +15 -10
- package/dist/utils/shape.d.ts +3 -4
- package/dist/utils/shape.js +64 -48
- package/dist/utils/state/index.d.ts +3 -4
- package/dist/utils/state/index.js +8 -23
- package/dist/wasi.js +38 -12
- package/package.json +23 -9
- package/dist/technical/index.d.ts +0 -2
- package/dist/technical/index.js +0 -2
- package/dist/technical/measurements.d.ts +0 -31
- package/dist/technical/measurements.js +0 -64
- package/dist/technical/scopes.d.ts +0 -261
- package/dist/technical/scopes.js +0 -676
- package/dist/types/typeChecks.d.ts +0 -5
- package/dist/types/typeChecks.js +0 -10
- package/dist/utils/traverse.d.ts +0 -30
- package/dist/utils/traverse.js +0 -124
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
const BOUNDS_EXCLUDED_OBJECT_NAMES = new Set([
|
|
3
|
+
"PlaneHelpers",
|
|
4
|
+
"PlaneMeshes",
|
|
5
|
+
"__parametricInspectOverlay",
|
|
6
|
+
"__parametricCopyOverlay",
|
|
7
|
+
]);
|
|
8
|
+
const BOUNDS_EXCLUDED_OBJECT_TYPES = new Set([
|
|
9
|
+
"AxesHelper",
|
|
10
|
+
"GridHelper",
|
|
11
|
+
"PlaneHelper",
|
|
12
|
+
]);
|
|
13
|
+
const isExcludedFromBounds = (object) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const name = (_a = object.name) !== null && _a !== void 0 ? _a : "";
|
|
16
|
+
return (BOUNDS_EXCLUDED_OBJECT_NAMES.has(name)
|
|
17
|
+
|| name.startsWith("__clipHelper_")
|
|
18
|
+
|| name.startsWith("__thumbnailIgnore")
|
|
19
|
+
|| BOUNDS_EXCLUDED_OBJECT_TYPES.has(object.type));
|
|
20
|
+
};
|
|
21
|
+
const collectVisibleShapeBounds = (viewer) => {
|
|
22
|
+
var _a, _b, _c, _d, _e;
|
|
23
|
+
const rootGroup = (_b = (_a = viewer.rendered) === null || _a === void 0 ? void 0 : _a.nestedGroup) === null || _b === void 0 ? void 0 : _b.rootGroup;
|
|
24
|
+
if (!rootGroup)
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
(_d = (_c = viewer.animation) === null || _c === void 0 ? void 0 : _c.update) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
28
|
+
}
|
|
29
|
+
catch (_f) {
|
|
30
|
+
// Animation may not exist or may throw; best-effort update.
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
(_e = viewer.update) === null || _e === void 0 ? void 0 : _e.call(viewer, true);
|
|
34
|
+
}
|
|
35
|
+
catch (_g) {
|
|
36
|
+
// Viewer may not be fully initialised; best-effort update.
|
|
37
|
+
}
|
|
38
|
+
rootGroup.updateMatrixWorld(true);
|
|
39
|
+
const bounds = new THREE.Box3();
|
|
40
|
+
const tempBox = new THREE.Box3();
|
|
41
|
+
let hasBounds = false;
|
|
42
|
+
rootGroup.traverse((object) => {
|
|
43
|
+
if (!object.visible || isExcludedFromBounds(object))
|
|
44
|
+
return;
|
|
45
|
+
if (!object.geometry)
|
|
46
|
+
return;
|
|
47
|
+
tempBox.setFromObject(object);
|
|
48
|
+
if (tempBox.isEmpty())
|
|
49
|
+
return;
|
|
50
|
+
bounds.union(tempBox);
|
|
51
|
+
hasBounds = true;
|
|
52
|
+
});
|
|
53
|
+
return hasBounds && !bounds.isEmpty() ? bounds : null;
|
|
54
|
+
};
|
|
55
|
+
const getFallbackFitDirection = (viewer) => {
|
|
56
|
+
const up = (() => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
try {
|
|
59
|
+
const value = (_b = (_a = viewer.state) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, "up");
|
|
60
|
+
return typeof value === "string" ? value : "Z";
|
|
61
|
+
}
|
|
62
|
+
catch (_c) {
|
|
63
|
+
return "Z";
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
return up === "Y"
|
|
67
|
+
? new THREE.Vector3(1, 1, 1).normalize()
|
|
68
|
+
: new THREE.Vector3(1, -1, 1).normalize();
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Fit an orthographic camera so that the given world-space bounds fill the
|
|
72
|
+
* render canvas at the given pixel dimensions, preserving the content aspect
|
|
73
|
+
* ratio. The frustum is computed in two passes:
|
|
74
|
+
*
|
|
75
|
+
* 1. Position the camera and project the 8 bounding-box corners into
|
|
76
|
+
* camera space to find the screen-space extents of the content.
|
|
77
|
+
* 2. Expand the frustum so the content fills the canvas without distortion,
|
|
78
|
+
* adding a small padding factor around the content.
|
|
79
|
+
*
|
|
80
|
+
* The resulting frustum aspect is guaranteed to equal `canvasAspect`, so no
|
|
81
|
+
* stretching occurs during rendering.
|
|
82
|
+
*/
|
|
83
|
+
const fitOrthographicCameraToBounds = (camera, bounds, target, direction, radius, paddingFactor, canvasAspect) => {
|
|
84
|
+
const corners = [];
|
|
85
|
+
const { min, max } = bounds;
|
|
86
|
+
for (let i = 0; i < 8; i++) {
|
|
87
|
+
corners.push(new THREE.Vector3((i & 1) ? max.x : min.x, (i & 2) ? max.y : min.y, (i & 4) ? max.z : min.z));
|
|
88
|
+
}
|
|
89
|
+
const distance = Math.max(radius * 4, 1);
|
|
90
|
+
camera.position.copy(target).add(direction.clone().multiplyScalar(distance));
|
|
91
|
+
camera.lookAt(target);
|
|
92
|
+
camera.zoom = 1;
|
|
93
|
+
camera.updateMatrixWorld(true);
|
|
94
|
+
camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
|
|
95
|
+
const projected = new THREE.Box3();
|
|
96
|
+
for (const corner of corners) {
|
|
97
|
+
projected.expandByPoint(corner.clone().applyMatrix4(camera.matrixWorldInverse));
|
|
98
|
+
}
|
|
99
|
+
const center = projected.getCenter(new THREE.Vector3());
|
|
100
|
+
const size = projected.getSize(new THREE.Vector3());
|
|
101
|
+
const contentWidth = Math.max(size.x, Number.EPSILON) * paddingFactor;
|
|
102
|
+
const contentHeight = Math.max(size.y, Number.EPSILON) * paddingFactor;
|
|
103
|
+
const contentAspect = contentWidth / contentHeight;
|
|
104
|
+
let frustumWidth;
|
|
105
|
+
let frustumHeight;
|
|
106
|
+
if (contentAspect > canvasAspect) {
|
|
107
|
+
frustumWidth = contentWidth;
|
|
108
|
+
frustumHeight = contentWidth / canvasAspect;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
frustumHeight = contentHeight;
|
|
112
|
+
frustumWidth = contentHeight * canvasAspect;
|
|
113
|
+
}
|
|
114
|
+
camera.left = center.x - frustumWidth / 2;
|
|
115
|
+
camera.right = center.x + frustumWidth / 2;
|
|
116
|
+
camera.bottom = center.y - frustumHeight / 2;
|
|
117
|
+
camera.top = center.y + frustumHeight / 2;
|
|
118
|
+
const depth = Math.max(size.z, radius, 1);
|
|
119
|
+
camera.near = Math.max(0.001, -projected.max.z - depth);
|
|
120
|
+
camera.far = Math.max(camera.near + 1, -projected.min.z + depth);
|
|
121
|
+
camera.updateProjectionMatrix();
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Fit a perspective camera so that the given world-space bounds fill the
|
|
125
|
+
* render canvas at the given pixel dimensions. The camera distance is chosen
|
|
126
|
+
* so that the projected content fits within the field of view, with padding.
|
|
127
|
+
*/
|
|
128
|
+
const fitPerspectiveCameraToBounds = (camera, bounds, target, direction, radius, paddingFactor) => {
|
|
129
|
+
const corners = [];
|
|
130
|
+
const { min, max } = bounds;
|
|
131
|
+
for (let i = 0; i < 8; i++) {
|
|
132
|
+
corners.push(new THREE.Vector3((i & 1) ? max.x : min.x, (i & 2) ? max.y : min.y, (i & 4) ? max.z : min.z));
|
|
133
|
+
}
|
|
134
|
+
camera.position.copy(target).add(direction.clone().multiplyScalar(Math.max(radius * 4, 1)));
|
|
135
|
+
camera.lookAt(target);
|
|
136
|
+
camera.zoom = 1;
|
|
137
|
+
camera.updateProjectionMatrix();
|
|
138
|
+
camera.updateMatrixWorld(true);
|
|
139
|
+
camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
|
|
140
|
+
const projected = new THREE.Box3();
|
|
141
|
+
for (const corner of corners) {
|
|
142
|
+
projected.expandByPoint(corner.clone().applyMatrix4(camera.matrixWorldInverse));
|
|
143
|
+
}
|
|
144
|
+
const center = projected.getCenter(new THREE.Vector3());
|
|
145
|
+
const halfWidth = Math.max(Math.abs(projected.max.x - center.x), Math.abs(center.x - projected.min.x));
|
|
146
|
+
const halfHeight = Math.max(Math.abs(projected.max.y - center.y), Math.abs(center.y - projected.min.y));
|
|
147
|
+
const tanY = Math.tan(THREE.MathUtils.degToRad(camera.fov) / 2);
|
|
148
|
+
const tanX = tanY * camera.aspect;
|
|
149
|
+
const distanceByWidth = (halfWidth * paddingFactor) / tanX;
|
|
150
|
+
const distanceByHeight = (halfHeight * paddingFactor) / tanY;
|
|
151
|
+
const distance = Math.max(distanceByWidth, distanceByHeight, radius, 1);
|
|
152
|
+
camera.position.copy(target).add(direction.clone().multiplyScalar(distance));
|
|
153
|
+
camera.lookAt(target);
|
|
154
|
+
camera.updateMatrixWorld(true);
|
|
155
|
+
camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
|
|
156
|
+
const reprojected = new THREE.Box3();
|
|
157
|
+
for (const corner of corners) {
|
|
158
|
+
reprojected.expandByPoint(corner.clone().applyMatrix4(camera.matrixWorldInverse));
|
|
159
|
+
}
|
|
160
|
+
const depth = Math.max(reprojected.getSize(new THREE.Vector3()).z, radius, 1);
|
|
161
|
+
camera.near = Math.max(0.001, -reprojected.max.z - depth);
|
|
162
|
+
camera.far = Math.max(camera.near + 1, -reprojected.min.z + depth);
|
|
163
|
+
camera.updateProjectionMatrix();
|
|
164
|
+
};
|
|
165
|
+
const fitCameraToBounds = (viewer, bounds, paddingFactor, canvasAspect) => {
|
|
166
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
167
|
+
try {
|
|
168
|
+
const cameraManager = viewer.rendered.camera;
|
|
169
|
+
const controls = viewer.rendered.controls;
|
|
170
|
+
const currentCamera = (_a = cameraManager.getCamera) === null || _a === void 0 ? void 0 : _a.call(cameraManager);
|
|
171
|
+
if (!currentCamera)
|
|
172
|
+
return false;
|
|
173
|
+
const target = bounds.getCenter(new THREE.Vector3());
|
|
174
|
+
const sphere = bounds.getBoundingSphere(new THREE.Sphere());
|
|
175
|
+
const radius = Math.max(sphere.radius, Number.EPSILON);
|
|
176
|
+
const currentTarget = (_h = (_e = (_d = (_c = (_b = controls.getTarget) === null || _b === void 0 ? void 0 : _b.call(controls)) === null || _c === void 0 ? void 0 : _c.clone) === null || _d === void 0 ? void 0 : _d.call(_c)) !== null && _e !== void 0 ? _e : (_g = (_f = controls.target) === null || _f === void 0 ? void 0 : _f.clone) === null || _g === void 0 ? void 0 : _g.call(_f)) !== null && _h !== void 0 ? _h : target.clone();
|
|
177
|
+
let direction = currentCamera.position.clone().sub(currentTarget);
|
|
178
|
+
if (direction.lengthSq() <= 1e-6) {
|
|
179
|
+
direction = currentCamera.position.clone().sub(target);
|
|
180
|
+
}
|
|
181
|
+
if (direction.lengthSq() <= 1e-6) {
|
|
182
|
+
direction = getFallbackFitDirection(viewer);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
direction.normalize();
|
|
186
|
+
}
|
|
187
|
+
cameraManager.target.copy(target);
|
|
188
|
+
if (currentCamera.isOrthographicCamera) {
|
|
189
|
+
const aspect = (canvasAspect !== null && canvasAspect !== void 0 ? canvasAspect : currentCamera.right - currentCamera.left > 0)
|
|
190
|
+
? (currentCamera.right - currentCamera.left) /
|
|
191
|
+
(currentCamera.top - currentCamera.bottom)
|
|
192
|
+
: 16 / 9;
|
|
193
|
+
fitOrthographicCameraToBounds(currentCamera, bounds, target, direction, radius, paddingFactor, aspect);
|
|
194
|
+
}
|
|
195
|
+
else if (currentCamera.isPerspectiveCamera) {
|
|
196
|
+
fitPerspectiveCameraToBounds(currentCamera, bounds, target, direction, radius, paddingFactor);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
cameraManager.updateFarPlane(radius);
|
|
200
|
+
cameraManager.updateCameraDistance(radius);
|
|
201
|
+
cameraManager.setupCamera(true, direction, null, null);
|
|
202
|
+
cameraManager.lookAtTarget();
|
|
203
|
+
}
|
|
204
|
+
(_j = controls.setTarget) === null || _j === void 0 ? void 0 : _j.call(controls, target.clone());
|
|
205
|
+
(_k = controls.update) === null || _k === void 0 ? void 0 : _k.call(controls);
|
|
206
|
+
viewer.update(true);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
catch (_l) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
export const fitThreeCadViewerCameraToBounds = (viewer) => {
|
|
214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
215
|
+
try {
|
|
216
|
+
const mutableViewer = viewer;
|
|
217
|
+
try {
|
|
218
|
+
(_b = (_a = viewer).updateBounds) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
219
|
+
}
|
|
220
|
+
catch (_k) {
|
|
221
|
+
// three-cad-viewer can throw while bounds are settling; use its current cache.
|
|
222
|
+
}
|
|
223
|
+
const sphere = (_d = (_c = mutableViewer.bbox) === null || _c === void 0 ? void 0 : _c.boundingSphere) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
224
|
+
const bboxCenter = (_f = (_e = mutableViewer.bbox) === null || _e === void 0 ? void 0 : _e.center) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
225
|
+
const currentCamera = (_h = (_g = viewer.rendered.camera).getCamera) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
226
|
+
if (!currentCamera || !(sphere === null || sphere === void 0 ? void 0 : sphere.center)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
const target = Array.isArray(bboxCenter)
|
|
230
|
+
? new THREE.Vector3(...bboxCenter)
|
|
231
|
+
: new THREE.Vector3(sphere.center.x, sphere.center.y, sphere.center.z);
|
|
232
|
+
const radius = Math.max((_j = sphere.radius) !== null && _j !== void 0 ? _j : mutableViewer.bb_radius, Number.EPSILON);
|
|
233
|
+
const bounds = new THREE.Box3(target.clone().subScalar(radius), target.clone().addScalar(radius));
|
|
234
|
+
return fitCameraToBounds(viewer, bounds, 1.0);
|
|
235
|
+
}
|
|
236
|
+
catch (_l) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
export const fitThreeCadViewerCameraToVisibleScene = (viewer, canvasAspect) => {
|
|
241
|
+
try {
|
|
242
|
+
const bounds = collectVisibleShapeBounds(viewer);
|
|
243
|
+
if (!bounds)
|
|
244
|
+
return false;
|
|
245
|
+
return fitCameraToBounds(viewer, bounds, 1.08, canvasAspect);
|
|
246
|
+
}
|
|
247
|
+
catch (_a) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
export const snapshotThreeCadViewerCamera = (viewer) => {
|
|
252
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
253
|
+
try {
|
|
254
|
+
const cameraManager = viewer.rendered.camera;
|
|
255
|
+
const controls = viewer.rendered.controls;
|
|
256
|
+
const camera = (_a = cameraManager.getCamera) === null || _a === void 0 ? void 0 : _a.call(cameraManager);
|
|
257
|
+
if (!camera)
|
|
258
|
+
return null;
|
|
259
|
+
const position = camera.position.clone();
|
|
260
|
+
const quaternion = camera.quaternion.clone();
|
|
261
|
+
const cameraWithZoom = camera;
|
|
262
|
+
const zoom = (_d = (_c = (_b = cameraManager.getZoom) === null || _b === void 0 ? void 0 : _b.call(cameraManager)) !== null && _c !== void 0 ? _c : cameraWithZoom.zoom) !== null && _d !== void 0 ? _d : 1;
|
|
263
|
+
const target = (_p = (_l = (_h = (_g = (_f = (_e = controls.getTarget) === null || _e === void 0 ? void 0 : _e.call(controls)) === null || _f === void 0 ? void 0 : _f.clone) === null || _g === void 0 ? void 0 : _g.call(_f)) !== null && _h !== void 0 ? _h : (_k = (_j = controls.target) === null || _j === void 0 ? void 0 : _j.clone) === null || _k === void 0 ? void 0 : _k.call(_j)) !== null && _l !== void 0 ? _l : (_o = (_m = cameraManager.target) === null || _m === void 0 ? void 0 : _m.clone) === null || _o === void 0 ? void 0 : _o.call(_m)) !== null && _p !== void 0 ? _p : null;
|
|
264
|
+
return () => {
|
|
265
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
266
|
+
try {
|
|
267
|
+
(_a = cameraManager.setPosition) === null || _a === void 0 ? void 0 : _a.call(cameraManager, position.clone(), false);
|
|
268
|
+
camera.position.copy(position);
|
|
269
|
+
(_b = cameraManager.setQuaternion) === null || _b === void 0 ? void 0 : _b.call(cameraManager, quaternion.clone());
|
|
270
|
+
camera.quaternion.copy(quaternion);
|
|
271
|
+
if (typeof zoom === "number" && Number.isFinite(zoom)) {
|
|
272
|
+
(_c = cameraManager.setZoom) === null || _c === void 0 ? void 0 : _c.call(cameraManager, zoom);
|
|
273
|
+
cameraWithZoom.zoom = zoom;
|
|
274
|
+
(_d = cameraWithZoom.updateProjectionMatrix) === null || _d === void 0 ? void 0 : _d.call(cameraWithZoom);
|
|
275
|
+
}
|
|
276
|
+
if (target) {
|
|
277
|
+
(_f = (_e = cameraManager.target) === null || _e === void 0 ? void 0 : _e.copy) === null || _f === void 0 ? void 0 : _f.call(_e, target);
|
|
278
|
+
(_g = controls.setTarget) === null || _g === void 0 ? void 0 : _g.call(controls, target.clone());
|
|
279
|
+
(_j = (_h = controls.target) === null || _h === void 0 ? void 0 : _h.copy) === null || _j === void 0 ? void 0 : _j.call(_h, target);
|
|
280
|
+
}
|
|
281
|
+
(_k = controls.update) === null || _k === void 0 ? void 0 : _k.call(controls);
|
|
282
|
+
viewer.update(true);
|
|
283
|
+
}
|
|
284
|
+
catch (_l) {
|
|
285
|
+
// Restore is best-effort; the overlay may be unmounting immediately after capture.
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
catch (_q) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface SceneThumbnailCaptureResult {
|
|
2
|
+
data: Uint8Array;
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
glRenderer?: string;
|
|
6
|
+
isGpu?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface CanvasThumbnailCaptureOptions {
|
|
9
|
+
trimTransparentBounds?: boolean;
|
|
10
|
+
targetLongEdge?: number;
|
|
11
|
+
maxSizeMB?: number;
|
|
12
|
+
trimScanLongEdge?: number;
|
|
13
|
+
trimPaddingPx?: number;
|
|
14
|
+
background?: string;
|
|
15
|
+
format?: "png" | "webp" | "jpeg";
|
|
16
|
+
}
|
|
17
|
+
export declare const cropAndScaleCanvasToOpaqueContent: (sourceCanvas: HTMLCanvasElement, targetLongEdge: number, options?: {
|
|
18
|
+
scanLongEdge?: number;
|
|
19
|
+
paddingPx?: number;
|
|
20
|
+
background?: string;
|
|
21
|
+
}) => HTMLCanvasElement | null;
|
|
22
|
+
export declare const scaleCanvasToLongEdge: (sourceCanvas: HTMLCanvasElement, targetLongEdge: number, background?: string) => HTMLCanvasElement;
|
|
23
|
+
export declare function captureCanvasThumbnail(sourceCanvas: HTMLCanvasElement, options?: CanvasThumbnailCaptureOptions): Promise<SceneThumbnailCaptureResult | null>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const PNG_ALPHA_THRESHOLD = 4;
|
|
11
|
+
const THUMB_LONG_EDGE = 1200;
|
|
12
|
+
const getOpaqueBounds = (pixels, width, height, alphaThreshold) => {
|
|
13
|
+
let minX = width;
|
|
14
|
+
let minY = height;
|
|
15
|
+
let maxX = -1;
|
|
16
|
+
let maxY = -1;
|
|
17
|
+
for (let y = 0; y < height; y++) {
|
|
18
|
+
for (let x = 0; x < width; x++) {
|
|
19
|
+
const alpha = pixels[(y * width + x) * 4 + 3];
|
|
20
|
+
if (alpha <= alphaThreshold)
|
|
21
|
+
continue;
|
|
22
|
+
if (x < minX)
|
|
23
|
+
minX = x;
|
|
24
|
+
if (y < minY)
|
|
25
|
+
minY = y;
|
|
26
|
+
if (x > maxX)
|
|
27
|
+
maxX = x;
|
|
28
|
+
if (y > maxY)
|
|
29
|
+
maxY = y;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (maxX < minX || maxY < minY)
|
|
33
|
+
return null;
|
|
34
|
+
return { minX, minY, maxX, maxY };
|
|
35
|
+
};
|
|
36
|
+
export const cropAndScaleCanvasToOpaqueContent = (sourceCanvas, targetLongEdge, options = {}) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const sourceWidth = Math.max(1, sourceCanvas.width);
|
|
39
|
+
const sourceHeight = Math.max(1, sourceCanvas.height);
|
|
40
|
+
const sourceLongEdge = Math.max(sourceWidth, sourceHeight);
|
|
41
|
+
const scanLongEdge = Math.max(1, Math.floor((_a = options.scanLongEdge) !== null && _a !== void 0 ? _a : sourceLongEdge));
|
|
42
|
+
const scanScale = Math.min(1, scanLongEdge / sourceLongEdge);
|
|
43
|
+
const scanWidth = Math.max(1, Math.round(sourceWidth * scanScale));
|
|
44
|
+
const scanHeight = Math.max(1, Math.round(sourceHeight * scanScale));
|
|
45
|
+
const scanCanvas = document.createElement("canvas");
|
|
46
|
+
scanCanvas.width = scanWidth;
|
|
47
|
+
scanCanvas.height = scanHeight;
|
|
48
|
+
const scanCtx = scanCanvas.getContext("2d", { willReadFrequently: true });
|
|
49
|
+
if (!scanCtx) {
|
|
50
|
+
scanCanvas.width = scanCanvas.height = 1;
|
|
51
|
+
return scaleCanvasToLongEdge(sourceCanvas, targetLongEdge, options.background);
|
|
52
|
+
}
|
|
53
|
+
scanCtx.clearRect(0, 0, scanWidth, scanHeight);
|
|
54
|
+
scanCtx.imageSmoothingEnabled = false;
|
|
55
|
+
scanCtx.drawImage(sourceCanvas, 0, 0, scanWidth, scanHeight);
|
|
56
|
+
const scanBounds = getOpaqueBounds(scanCtx.getImageData(0, 0, scanCanvas.width, scanCanvas.height).data, scanCanvas.width, scanCanvas.height, PNG_ALPHA_THRESHOLD);
|
|
57
|
+
scanCanvas.width = scanCanvas.height = 1;
|
|
58
|
+
if (!scanBounds)
|
|
59
|
+
return null;
|
|
60
|
+
const paddingPx = Math.max(0, Math.floor((_b = options.paddingPx) !== null && _b !== void 0 ? _b : 0));
|
|
61
|
+
const inverseScale = 1 / scanScale;
|
|
62
|
+
const bounds = {
|
|
63
|
+
minX: Math.max(0, Math.floor(scanBounds.minX * inverseScale) - paddingPx),
|
|
64
|
+
minY: Math.max(0, Math.floor(scanBounds.minY * inverseScale) - paddingPx),
|
|
65
|
+
maxX: Math.min(sourceWidth - 1, Math.ceil((scanBounds.maxX + 1) * inverseScale) + paddingPx - 1),
|
|
66
|
+
maxY: Math.min(sourceHeight - 1, Math.ceil((scanBounds.maxY + 1) * inverseScale) + paddingPx - 1),
|
|
67
|
+
};
|
|
68
|
+
const trimmedWidth = bounds.maxX - bounds.minX + 1;
|
|
69
|
+
const trimmedHeight = bounds.maxY - bounds.minY + 1;
|
|
70
|
+
const scale = targetLongEdge / Math.max(trimmedWidth, trimmedHeight);
|
|
71
|
+
const outputWidth = Math.max(1, Math.round(trimmedWidth * scale));
|
|
72
|
+
const outputHeight = Math.max(1, Math.round(trimmedHeight * scale));
|
|
73
|
+
const outputCanvas = document.createElement("canvas");
|
|
74
|
+
outputCanvas.width = outputWidth;
|
|
75
|
+
outputCanvas.height = outputHeight;
|
|
76
|
+
const outputCtx = outputCanvas.getContext("2d");
|
|
77
|
+
if (!outputCtx) {
|
|
78
|
+
outputCanvas.width = outputCanvas.height = 1;
|
|
79
|
+
return scaleCanvasToLongEdge(sourceCanvas, targetLongEdge, options.background);
|
|
80
|
+
}
|
|
81
|
+
if (options.background && options.background !== "transparent") {
|
|
82
|
+
outputCtx.fillStyle = options.background;
|
|
83
|
+
outputCtx.fillRect(0, 0, outputWidth, outputHeight);
|
|
84
|
+
}
|
|
85
|
+
outputCtx.imageSmoothingEnabled = true;
|
|
86
|
+
outputCtx.imageSmoothingQuality = "high";
|
|
87
|
+
outputCtx.drawImage(sourceCanvas, bounds.minX, bounds.minY, trimmedWidth, trimmedHeight, 0, 0, outputWidth, outputHeight);
|
|
88
|
+
return outputCanvas;
|
|
89
|
+
};
|
|
90
|
+
export const scaleCanvasToLongEdge = (sourceCanvas, targetLongEdge, background) => {
|
|
91
|
+
const sw = Math.max(1, sourceCanvas.width);
|
|
92
|
+
const sh = Math.max(1, sourceCanvas.height);
|
|
93
|
+
const currentLong = Math.max(sw, sh);
|
|
94
|
+
const scale = targetLongEdge / currentLong;
|
|
95
|
+
const scaledW = Math.max(1, Math.round(sw * scale));
|
|
96
|
+
const scaledH = Math.max(1, Math.round(sh * scale));
|
|
97
|
+
const scaledCanvas = document.createElement("canvas");
|
|
98
|
+
scaledCanvas.width = scaledW;
|
|
99
|
+
scaledCanvas.height = scaledH;
|
|
100
|
+
const ctx = scaledCanvas.getContext("2d");
|
|
101
|
+
if (!ctx) {
|
|
102
|
+
scaledCanvas.width = scaledCanvas.height = 1;
|
|
103
|
+
return sourceCanvas;
|
|
104
|
+
}
|
|
105
|
+
if (background && background !== "transparent") {
|
|
106
|
+
ctx.fillStyle = background;
|
|
107
|
+
ctx.fillRect(0, 0, scaledW, scaledH);
|
|
108
|
+
}
|
|
109
|
+
ctx.imageSmoothingEnabled = true;
|
|
110
|
+
ctx.imageSmoothingQuality = "high";
|
|
111
|
+
ctx.drawImage(sourceCanvas, 0, 0, scaledW, scaledH);
|
|
112
|
+
return scaledCanvas;
|
|
113
|
+
};
|
|
114
|
+
function canvasToBlob(canvas, type, quality) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
canvas.toBlob((blob) => resolve(blob), type, quality);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function captureCanvasThumbnail(sourceCanvas_1) {
|
|
122
|
+
return __awaiter(this, arguments, void 0, function* (sourceCanvas, options = {}) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
let scaled = null;
|
|
125
|
+
try {
|
|
126
|
+
const shouldTrim = (_a = options.trimTransparentBounds) !== null && _a !== void 0 ? _a : true;
|
|
127
|
+
const targetLongEdge = (_b = options.targetLongEdge) !== null && _b !== void 0 ? _b : THUMB_LONG_EDGE;
|
|
128
|
+
scaled = shouldTrim
|
|
129
|
+
? cropAndScaleCanvasToOpaqueContent(sourceCanvas, targetLongEdge, {
|
|
130
|
+
scanLongEdge: options.trimScanLongEdge,
|
|
131
|
+
paddingPx: options.trimPaddingPx,
|
|
132
|
+
background: options.background,
|
|
133
|
+
})
|
|
134
|
+
: scaleCanvasToLongEdge(sourceCanvas, targetLongEdge, options.background);
|
|
135
|
+
if (!scaled)
|
|
136
|
+
return null;
|
|
137
|
+
const mimeType = options.format === "webp"
|
|
138
|
+
? "image/webp"
|
|
139
|
+
: options.format === "jpeg"
|
|
140
|
+
? "image/jpeg"
|
|
141
|
+
: "image/png";
|
|
142
|
+
const blob = yield canvasToBlob(scaled, mimeType, 0.92);
|
|
143
|
+
if (!blob)
|
|
144
|
+
return null;
|
|
145
|
+
const arrayBuffer = yield blob.arrayBuffer();
|
|
146
|
+
const data = new Uint8Array(arrayBuffer);
|
|
147
|
+
return {
|
|
148
|
+
data,
|
|
149
|
+
width: scaled.width,
|
|
150
|
+
height: scaled.height,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch (_c) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
if (scaled && scaled !== sourceCanvas)
|
|
158
|
+
scaled.width = scaled.height = 1;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Viewer } from 'three-cad-viewer';
|
|
3
|
+
type ViewerInstance = InstanceType<typeof Viewer>;
|
|
4
|
+
export declare const THUMBNAIL_HIDDEN_OBJECT_PREFIX = "__thumbnailIgnore";
|
|
5
|
+
type ThumbnailRendererMode = 'parametric' | 'dxf';
|
|
6
|
+
interface PrepareSceneForThumbnailCaptureOptions {
|
|
7
|
+
scene: THREE.Scene;
|
|
8
|
+
rendererMode: ThumbnailRendererMode;
|
|
9
|
+
parametricViewer?: ViewerInstance | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const prepareSceneForThumbnailCapture: ({ scene, rendererMode, parametricViewer, }: PrepareSceneForThumbnailCaptureOptions) => (() => void);
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
const THUMBNAIL_HIDDEN_OBJECT_NAMES = new Set([
|
|
3
|
+
'PlaneHelpers',
|
|
4
|
+
'PlaneMeshes',
|
|
5
|
+
'__parametricInspectOverlay',
|
|
6
|
+
'__parametricCopyOverlay',
|
|
7
|
+
]);
|
|
8
|
+
const THUMBNAIL_HIDDEN_OBJECT_TYPES = new Set([
|
|
9
|
+
'AxesHelper',
|
|
10
|
+
'GridHelper',
|
|
11
|
+
'PlaneHelper',
|
|
12
|
+
]);
|
|
13
|
+
export const THUMBNAIL_HIDDEN_OBJECT_PREFIX = '__thumbnailIgnore';
|
|
14
|
+
const getBooleanValue = (value) => (typeof value === 'boolean' ? value : null);
|
|
15
|
+
const getBooleanTriple = (value) => {
|
|
16
|
+
if (!Array.isArray(value) || value.length !== 3)
|
|
17
|
+
return null;
|
|
18
|
+
return [Boolean(value[0]), Boolean(value[1]), Boolean(value[2])];
|
|
19
|
+
};
|
|
20
|
+
const shouldHideObjectForThumbnail = (object) => {
|
|
21
|
+
var _a;
|
|
22
|
+
const name = (_a = object.name) !== null && _a !== void 0 ? _a : '';
|
|
23
|
+
return (THUMBNAIL_HIDDEN_OBJECT_NAMES.has(name)
|
|
24
|
+
|| name.startsWith('__clipHelper_')
|
|
25
|
+
|| name.startsWith(THUMBNAIL_HIDDEN_OBJECT_PREFIX)
|
|
26
|
+
|| THUMBNAIL_HIDDEN_OBJECT_TYPES.has(object.type));
|
|
27
|
+
};
|
|
28
|
+
export const prepareSceneForThumbnailCapture = ({ scene, rendererMode, parametricViewer, }) => {
|
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
30
|
+
const restoreFns = [];
|
|
31
|
+
const previousBackground = scene.background;
|
|
32
|
+
if (previousBackground !== null) {
|
|
33
|
+
scene.background = null;
|
|
34
|
+
restoreFns.push(() => {
|
|
35
|
+
scene.background = previousBackground;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
scene.traverse((object) => {
|
|
39
|
+
if (!shouldHideObjectForThumbnail(object) || object.visible === false)
|
|
40
|
+
return;
|
|
41
|
+
const previousVisibility = object.visible;
|
|
42
|
+
object.visible = false;
|
|
43
|
+
restoreFns.push(() => {
|
|
44
|
+
object.visible = previousVisibility;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
if (rendererMode === 'parametric' && parametricViewer) {
|
|
48
|
+
const renderer = parametricViewer.renderer;
|
|
49
|
+
if ((renderer === null || renderer === void 0 ? void 0 : renderer.setClearColor) && (renderer === null || renderer === void 0 ? void 0 : renderer.getClearColor)) {
|
|
50
|
+
const prevColor = new THREE.Color();
|
|
51
|
+
renderer.getClearColor(prevColor);
|
|
52
|
+
const prevAlpha = (_b = (_a = renderer.getClearAlpha) === null || _a === void 0 ? void 0 : _a.call(renderer)) !== null && _b !== void 0 ? _b : 0;
|
|
53
|
+
renderer.setClearColor(0x000000, 0);
|
|
54
|
+
restoreFns.push(() => {
|
|
55
|
+
renderer.setClearColor(prevColor, prevAlpha);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const stateGet = (key) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
try {
|
|
61
|
+
return (_b = (_a = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.state) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, key);
|
|
62
|
+
}
|
|
63
|
+
catch (_c) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const currentAxes = getBooleanValue(stateGet('axes'));
|
|
68
|
+
if (currentAxes) {
|
|
69
|
+
(_c = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setAxes) === null || _c === void 0 ? void 0 : _c.call(parametricViewer, false, false);
|
|
70
|
+
restoreFns.push(() => { var _a; return (_a = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setAxes) === null || _a === void 0 ? void 0 : _a.call(parametricViewer, currentAxes, false); });
|
|
71
|
+
}
|
|
72
|
+
const currentGrids = getBooleanTriple(stateGet('grid'));
|
|
73
|
+
if (currentGrids && currentGrids.some(Boolean)) {
|
|
74
|
+
(_d = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setGrids) === null || _d === void 0 ? void 0 : _d.call(parametricViewer, currentGrids.map(() => false), false);
|
|
75
|
+
restoreFns.push(() => { var _a; return (_a = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setGrids) === null || _a === void 0 ? void 0 : _a.call(parametricViewer, currentGrids, false); });
|
|
76
|
+
}
|
|
77
|
+
const currentClipHelpers = getBooleanValue((_f = (_e = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.getClipPlaneHelpers) === null || _e === void 0 ? void 0 : _e.call(parametricViewer)) !== null && _f !== void 0 ? _f : stateGet('clipPlaneHelpers'));
|
|
78
|
+
if (currentClipHelpers) {
|
|
79
|
+
(_g = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setClipPlaneHelpers) === null || _g === void 0 ? void 0 : _g.call(parametricViewer, false, false);
|
|
80
|
+
restoreFns.push(() => { var _a; return (_a = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.setClipPlaneHelpers) === null || _a === void 0 ? void 0 : _a.call(parametricViewer, currentClipHelpers, false); });
|
|
81
|
+
}
|
|
82
|
+
const lastBbox = (_h = parametricViewer === null || parametricViewer === void 0 ? void 0 : parametricViewer.lastBbox) === null || _h === void 0 ? void 0 : _h.bbox;
|
|
83
|
+
if (lastBbox && lastBbox.visible !== false) {
|
|
84
|
+
const previousVisibility = lastBbox.visible;
|
|
85
|
+
lastBbox.visible = false;
|
|
86
|
+
restoreFns.push(() => {
|
|
87
|
+
lastBbox.visible = previousVisibility;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return () => {
|
|
92
|
+
var _a;
|
|
93
|
+
for (let index = restoreFns.length - 1; index >= 0; index -= 1) {
|
|
94
|
+
(_a = restoreFns[index]) === null || _a === void 0 ? void 0 : _a.call(restoreFns);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Viewer3DGrid, Viewer3DGridPlanes } from "../../types";
|
|
2
|
+
export type ViewerGridPlaneKey = keyof Viewer3DGridPlanes;
|
|
3
|
+
export declare const VIEWER_GRID_PLANE_KEYS: readonly ["xy", "xz", "yz"];
|
|
4
|
+
export declare const EMPTY_VIEWER_GRID_PLANES: Viewer3DGridPlanes;
|
|
5
|
+
export declare const ALL_VIEWER_GRID_PLANES: Viewer3DGridPlanes;
|
|
6
|
+
export declare const IFC_VIEWER_GRID_PLANES: Viewer3DGridPlanes;
|
|
7
|
+
export declare const getViewerGridPlanes: (grid: Viewer3DGrid | null | undefined) => Viewer3DGridPlanes;
|
|
8
|
+
export declare const hasAnyViewerGridPlaneEnabled: (planes: Viewer3DGridPlanes) => boolean;
|
|
9
|
+
export declare const isViewerGridEnabled: (grid: Viewer3DGrid | null | undefined) => boolean;
|
|
10
|
+
export declare const createViewerGridState: (planes: Partial<Viewer3DGridPlanes>) => Viewer3DGrid;
|
|
11
|
+
export declare const setViewerGridEnabled: (grid: Viewer3DGrid | null | undefined, enabled: boolean, fallbackWhenEnabled?: Viewer3DGridPlanes) => Viewer3DGrid;
|
|
12
|
+
export declare const setViewerGridPlane: (grid: Viewer3DGrid | null | undefined, planeKey: ViewerGridPlaneKey, enabled: boolean) => Viewer3DGrid;
|
|
13
|
+
export declare const viewerGridPlanesToTuple: (planes: Viewer3DGridPlanes) => [boolean, boolean, boolean];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const VIEWER_GRID_PLANE_KEYS = ["xy", "xz", "yz"];
|
|
2
|
+
export const EMPTY_VIEWER_GRID_PLANES = {
|
|
3
|
+
xy: false,
|
|
4
|
+
xz: false,
|
|
5
|
+
yz: false,
|
|
6
|
+
};
|
|
7
|
+
export const ALL_VIEWER_GRID_PLANES = {
|
|
8
|
+
xy: true,
|
|
9
|
+
xz: true,
|
|
10
|
+
yz: true,
|
|
11
|
+
};
|
|
12
|
+
export const IFC_VIEWER_GRID_PLANES = {
|
|
13
|
+
xy: false,
|
|
14
|
+
xz: true,
|
|
15
|
+
yz: false,
|
|
16
|
+
};
|
|
17
|
+
const cloneViewerGridPlanes = (planes) => ({
|
|
18
|
+
xy: Boolean(planes.xy),
|
|
19
|
+
xz: Boolean(planes.xz),
|
|
20
|
+
yz: Boolean(planes.yz),
|
|
21
|
+
});
|
|
22
|
+
const getRawViewerGridPlanes = (grid) => {
|
|
23
|
+
if (!grid || typeof grid !== "object")
|
|
24
|
+
return null;
|
|
25
|
+
if ("value" in grid && grid.value && typeof grid.value === "object") {
|
|
26
|
+
return grid.value;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
export const getViewerGridPlanes = (grid) => {
|
|
31
|
+
const rawPlanes = getRawViewerGridPlanes(grid);
|
|
32
|
+
if (rawPlanes) {
|
|
33
|
+
return cloneViewerGridPlanes(rawPlanes);
|
|
34
|
+
}
|
|
35
|
+
const enabled = Boolean(grid && "value" in grid && typeof grid.value === "boolean" ? grid.value : false);
|
|
36
|
+
return enabled ? Object.assign({}, ALL_VIEWER_GRID_PLANES) : Object.assign({}, EMPTY_VIEWER_GRID_PLANES);
|
|
37
|
+
};
|
|
38
|
+
export const hasAnyViewerGridPlaneEnabled = (planes) => VIEWER_GRID_PLANE_KEYS.some((planeKey) => planes[planeKey]);
|
|
39
|
+
export const isViewerGridEnabled = (grid) => hasAnyViewerGridPlaneEnabled(getViewerGridPlanes(grid));
|
|
40
|
+
export const createViewerGridState = (planes) => ({
|
|
41
|
+
type: "perPlane",
|
|
42
|
+
value: cloneViewerGridPlanes(planes),
|
|
43
|
+
});
|
|
44
|
+
export const setViewerGridEnabled = (grid, enabled, fallbackWhenEnabled = ALL_VIEWER_GRID_PLANES) => {
|
|
45
|
+
if (!enabled) {
|
|
46
|
+
return createViewerGridState(EMPTY_VIEWER_GRID_PLANES);
|
|
47
|
+
}
|
|
48
|
+
const currentPlanes = getViewerGridPlanes(grid);
|
|
49
|
+
return createViewerGridState(hasAnyViewerGridPlaneEnabled(currentPlanes)
|
|
50
|
+
? currentPlanes
|
|
51
|
+
: fallbackWhenEnabled);
|
|
52
|
+
};
|
|
53
|
+
export const setViewerGridPlane = (grid, planeKey, enabled) => {
|
|
54
|
+
const currentPlanes = getViewerGridPlanes(grid);
|
|
55
|
+
return createViewerGridState(Object.assign(Object.assign({}, currentPlanes), { [planeKey]: enabled }));
|
|
56
|
+
};
|
|
57
|
+
export const viewerGridPlanesToTuple = (planes) => [planes.xy, planes.xz, planes.yz];
|