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,177 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { CLIPPING_AXES, shouldMirrorSingleAxisIntersection, } from "./clippingUtils";
|
|
3
|
+
const CLIP_AXIS_INDEX = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 1,
|
|
6
|
+
z: 2,
|
|
7
|
+
};
|
|
8
|
+
const CLIP_AXIS_VECTOR_INDEX = {
|
|
9
|
+
x: 0,
|
|
10
|
+
y: 1,
|
|
11
|
+
z: 2,
|
|
12
|
+
};
|
|
13
|
+
const MIN_HALF_EXTENT = 1e-3;
|
|
14
|
+
const DISABLE_MARGIN_FACTOR = 1.05;
|
|
15
|
+
const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
16
|
+
const clampClipPercent = (value) => Math.max(-100, Math.min(100, value));
|
|
17
|
+
export const PARAMETRIC_CLIP_PERCENT_RANGE = {
|
|
18
|
+
min: -100,
|
|
19
|
+
max: 100,
|
|
20
|
+
step: 1,
|
|
21
|
+
};
|
|
22
|
+
export const PARAMETRIC_CLIP_AXIS_NORMALS = {
|
|
23
|
+
x: [-1, 0, 0],
|
|
24
|
+
y: [0, -1, 0],
|
|
25
|
+
z: [0, 0, -1],
|
|
26
|
+
};
|
|
27
|
+
const PLANE_MESH_GROUP_NAME = "PlaneMeshes";
|
|
28
|
+
const isIfcRenderedModel = (rendered) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const groups = (_a = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _a === void 0 ? void 0 : _a.groups;
|
|
31
|
+
if (!groups)
|
|
32
|
+
return false;
|
|
33
|
+
return Object.entries(groups).some(([path, group]) => {
|
|
34
|
+
var _a;
|
|
35
|
+
return (path.includes("ifc/")
|
|
36
|
+
|| (group instanceof THREE.Object3D && Boolean((_a = group.userData) === null || _a === void 0 ? void 0 : _a.ifc)));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const getParametricViewerHalfExtent = (viewer, axis) => {
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41
|
+
try {
|
|
42
|
+
const bbox = viewer === null || viewer === void 0 ? void 0 : viewer.bbox;
|
|
43
|
+
const vectorIndex = CLIP_AXIS_VECTOR_INDEX[axis];
|
|
44
|
+
const min = (_d = (_c = (_b = (_a = bbox === null || bbox === void 0 ? void 0 : bbox.min) === null || _a === void 0 ? void 0 : _a.toArray) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c[vectorIndex]) !== null && _d !== void 0 ? _d : (_e = bbox === null || bbox === void 0 ? void 0 : bbox.min) === null || _e === void 0 ? void 0 : _e[axis];
|
|
45
|
+
const max = (_j = (_h = (_g = (_f = bbox === null || bbox === void 0 ? void 0 : bbox.max) === null || _f === void 0 ? void 0 : _f.toArray) === null || _g === void 0 ? void 0 : _g.call(_f)) === null || _h === void 0 ? void 0 : _h[vectorIndex]) !== null && _j !== void 0 ? _j : (_k = bbox === null || bbox === void 0 ? void 0 : bbox.max) === null || _k === void 0 ? void 0 : _k[axis];
|
|
46
|
+
if (!isFiniteNumber(min) || !isFiniteNumber(max)) {
|
|
47
|
+
return Math.max(((_l = viewer === null || viewer === void 0 ? void 0 : viewer.gridSize) !== null && _l !== void 0 ? _l : 100) / 2, MIN_HALF_EXTENT);
|
|
48
|
+
}
|
|
49
|
+
return Math.max(Math.abs(max - min) / 2, MIN_HALF_EXTENT);
|
|
50
|
+
}
|
|
51
|
+
catch (_m) {
|
|
52
|
+
return 50;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const isPercentBasedClipPlane = (plane) => Array.isArray(plane.normal) && plane.normal.length === 3;
|
|
56
|
+
export const getParametricClipPercentValue = (viewer, axis, plane) => {
|
|
57
|
+
if (isPercentBasedClipPlane(plane)) {
|
|
58
|
+
return clampClipPercent(plane.value);
|
|
59
|
+
}
|
|
60
|
+
const halfExtent = getParametricViewerHalfExtent(viewer, axis);
|
|
61
|
+
return clampClipPercent((plane.value / halfExtent) * 100);
|
|
62
|
+
};
|
|
63
|
+
export const getParametricClipActualValue = (viewer, axis, plane) => {
|
|
64
|
+
if (!plane.enabled) {
|
|
65
|
+
return getParametricViewerHalfExtent(viewer, axis) * DISABLE_MARGIN_FACTOR;
|
|
66
|
+
}
|
|
67
|
+
if (!isPercentBasedClipPlane(plane)) {
|
|
68
|
+
return plane.value;
|
|
69
|
+
}
|
|
70
|
+
const halfExtent = getParametricViewerHalfExtent(viewer, axis);
|
|
71
|
+
return (clampClipPercent(plane.value) / 100) * halfExtent;
|
|
72
|
+
};
|
|
73
|
+
const getActiveParametricClipIndices = (clipping) => {
|
|
74
|
+
const activeIndices = [];
|
|
75
|
+
for (const axis of CLIPPING_AXES) {
|
|
76
|
+
if (clipping[axis].enabled) {
|
|
77
|
+
activeIndices.push(CLIP_AXIS_INDEX[axis]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return activeIndices;
|
|
81
|
+
};
|
|
82
|
+
const applyParametricClipPlaneSubset = (rendered, clipping, hasAnyClip) => {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
84
|
+
const activeIndices = getActiveParametricClipIndices(clipping);
|
|
85
|
+
const activeIndexSet = new Set(activeIndices);
|
|
86
|
+
const shouldMirrorSingleAxisClip = shouldMirrorSingleAxisIntersection(clipping);
|
|
87
|
+
const suppressCapMeshes = isIfcRenderedModel(rendered) && !clipping.objectColorCaps;
|
|
88
|
+
const activeClipPlanes = hasAnyClip
|
|
89
|
+
? activeIndices
|
|
90
|
+
.map((index) => {
|
|
91
|
+
var _a, _b, _c, _d;
|
|
92
|
+
return (shouldMirrorSingleAxisClip
|
|
93
|
+
? (_b = (_a = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _a === void 0 ? void 0 : _a.reverseClipPlanes) === null || _b === void 0 ? void 0 : _b[index]
|
|
94
|
+
: (_d = (_c = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _c === void 0 ? void 0 : _c.clipPlanes) === null || _d === void 0 ? void 0 : _d[index]);
|
|
95
|
+
})
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
: [];
|
|
98
|
+
const capAndHelperPlaneByIndex = new Map(activeIndices
|
|
99
|
+
.map((index) => {
|
|
100
|
+
var _a, _b, _c, _d;
|
|
101
|
+
return [
|
|
102
|
+
index,
|
|
103
|
+
clipping.intersection
|
|
104
|
+
? (_b = (_a = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _a === void 0 ? void 0 : _a.reverseClipPlanes) === null || _b === void 0 ? void 0 : _b[index]
|
|
105
|
+
: (_d = (_c = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _c === void 0 ? void 0 : _c.clipPlanes) === null || _d === void 0 ? void 0 : _d[index],
|
|
106
|
+
];
|
|
107
|
+
})
|
|
108
|
+
.filter((entry) => Boolean(entry[1])));
|
|
109
|
+
const capAndHelperPlanes = Array.from(capAndHelperPlaneByIndex.values());
|
|
110
|
+
(_b = (_a = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _a === void 0 ? void 0 : _a.setClipPlanes) === null || _b === void 0 ? void 0 : _b.call(_a, activeClipPlanes);
|
|
111
|
+
(_d = (_c = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _c === void 0 ? void 0 : _c.setVisible) === null || _d === void 0 ? void 0 : _d.call(_c, hasAnyClip);
|
|
112
|
+
const planeHelpers = (_e = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _e === void 0 ? void 0 : _e.planeHelpers;
|
|
113
|
+
if (planeHelpers) {
|
|
114
|
+
planeHelpers.visible = hasAnyClip && clipping.showPlanes;
|
|
115
|
+
for (const helper of (_f = planeHelpers.children) !== null && _f !== void 0 ? _f : []) {
|
|
116
|
+
const helperMesh = helper;
|
|
117
|
+
const helperIndex = helperMesh.index;
|
|
118
|
+
const isActive = helperIndex != null && activeIndexSet.has(helperIndex);
|
|
119
|
+
const ownPlane = helperIndex == null ? null : capAndHelperPlaneByIndex.get(helperIndex);
|
|
120
|
+
helper.visible = planeHelpers.visible && isActive;
|
|
121
|
+
if (helperMesh.material && "clippingPlanes" in helperMesh.material) {
|
|
122
|
+
helperMesh.material.clippingPlanes = ownPlane
|
|
123
|
+
? capAndHelperPlanes.filter((plane) => plane !== ownPlane)
|
|
124
|
+
: [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const child of (_j = (_h = (_g = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _g === void 0 ? void 0 : _g.rootGroup) === null || _h === void 0 ? void 0 : _h.children) !== null && _j !== void 0 ? _j : []) {
|
|
129
|
+
if ((child === null || child === void 0 ? void 0 : child.name) !== PLANE_MESH_GROUP_NAME)
|
|
130
|
+
continue;
|
|
131
|
+
child.visible = !suppressCapMeshes;
|
|
132
|
+
for (const capPlane of (_k = child.children) !== null && _k !== void 0 ? _k : []) {
|
|
133
|
+
const capPlaneMesh = capPlane;
|
|
134
|
+
const capPlaneIndex = capPlaneMesh.index;
|
|
135
|
+
const isActive = hasAnyClip && capPlaneIndex != null && activeIndexSet.has(capPlaneIndex);
|
|
136
|
+
const shouldShowCapPlane = isActive && !suppressCapMeshes;
|
|
137
|
+
const ownPlane = capPlaneIndex == null ? null : capAndHelperPlaneByIndex.get(capPlaneIndex);
|
|
138
|
+
capPlane.visible = shouldShowCapPlane;
|
|
139
|
+
if (capPlaneMesh.material) {
|
|
140
|
+
const mat = capPlaneMesh.material;
|
|
141
|
+
if ("visible" in mat) {
|
|
142
|
+
mat.visible = shouldShowCapPlane;
|
|
143
|
+
}
|
|
144
|
+
if ("clippingPlanes" in mat) {
|
|
145
|
+
mat.clippingPlanes = ownPlane
|
|
146
|
+
? capAndHelperPlanes.filter((plane) => plane !== ownPlane)
|
|
147
|
+
: [];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
export const applyParametricClipping = (viewer, clipping) => {
|
|
154
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
155
|
+
let rendered;
|
|
156
|
+
try {
|
|
157
|
+
rendered = viewer === null || viewer === void 0 ? void 0 : viewer.rendered;
|
|
158
|
+
}
|
|
159
|
+
catch (_h) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!(rendered === null || rendered === void 0 ? void 0 : rendered.clipping))
|
|
163
|
+
return;
|
|
164
|
+
const hasAnyClip = CLIPPING_AXES.some((axis) => clipping[axis].enabled);
|
|
165
|
+
for (const axis of CLIPPING_AXES) {
|
|
166
|
+
const index = CLIP_AXIS_INDEX[axis];
|
|
167
|
+
const plane = clipping[axis];
|
|
168
|
+
const actualValue = getParametricClipActualValue(viewer, axis, plane);
|
|
169
|
+
(_a = viewer === null || viewer === void 0 ? void 0 : viewer.setClipSlider) === null || _a === void 0 ? void 0 : _a.call(viewer, index, actualValue, false);
|
|
170
|
+
}
|
|
171
|
+
(_b = viewer === null || viewer === void 0 ? void 0 : viewer.setClipIntersection) === null || _b === void 0 ? void 0 : _b.call(viewer, clipping.intersection, false);
|
|
172
|
+
(_c = viewer === null || viewer === void 0 ? void 0 : viewer.setClipPlaneHelpers) === null || _c === void 0 ? void 0 : _c.call(viewer, clipping.showPlanes, false);
|
|
173
|
+
(_d = viewer === null || viewer === void 0 ? void 0 : viewer.setLocalClipping) === null || _d === void 0 ? void 0 : _d.call(viewer, hasAnyClip);
|
|
174
|
+
(_f = (_e = rendered.nestedGroup) === null || _e === void 0 ? void 0 : _e.setBackVisible) === null || _f === void 0 ? void 0 : _f.call(_e, hasAnyClip);
|
|
175
|
+
applyParametricClipPlaneSubset(rendered, clipping, hasAnyClip);
|
|
176
|
+
(_g = viewer === null || viewer === void 0 ? void 0 : viewer.update) === null || _g === void 0 ? void 0 : _g.call(viewer, true);
|
|
177
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeParametricShapes: (value: unknown) => unknown;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { applyDefaultModelColors } from "./defaultModelColor";
|
|
2
|
+
const isObjectRecord = (value) => {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
};
|
|
5
|
+
const getSanitizedShapeToken = (value, fallback) => {
|
|
6
|
+
if (typeof value === "string" && value.trim()) {
|
|
7
|
+
return value.trim();
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
10
|
+
return String(value);
|
|
11
|
+
}
|
|
12
|
+
return fallback;
|
|
13
|
+
};
|
|
14
|
+
const sanitizeParametricShapeNode = (value, fallbackId, fallbackName) => {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return {
|
|
17
|
+
id: fallbackId,
|
|
18
|
+
name: fallbackName,
|
|
19
|
+
parts: value.map((part, index) => sanitizeParametricShapeNode(part, `${fallbackId}/part-${index + 1}`, `part-${index + 1}`)).filter((part) => part !== null),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!isObjectRecord(value)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const name = getSanitizedShapeToken(value.name, fallbackName);
|
|
26
|
+
const id = getSanitizedShapeToken(value.id, fallbackId);
|
|
27
|
+
const hasNestedParts = Array.isArray(value.parts) || isObjectRecord(value.parts);
|
|
28
|
+
if (!hasNestedParts) {
|
|
29
|
+
return Object.assign(Object.assign({}, value), { id,
|
|
30
|
+
name });
|
|
31
|
+
}
|
|
32
|
+
const rawParts = Array.isArray(value.parts)
|
|
33
|
+
? value.parts
|
|
34
|
+
: isObjectRecord(value.parts)
|
|
35
|
+
? [value.parts]
|
|
36
|
+
: [];
|
|
37
|
+
const parts = rawParts.map((part, index) => sanitizeParametricShapeNode(part, `${id}/${getSanitizedShapeToken(isObjectRecord(part) ? part.name : null, `part-${index + 1}`)}`, `part-${index + 1}`)).filter((part) => part !== null);
|
|
38
|
+
return Object.assign(Object.assign({}, value), { id,
|
|
39
|
+
name,
|
|
40
|
+
parts });
|
|
41
|
+
};
|
|
42
|
+
const isInstancedFormat = (value) => {
|
|
43
|
+
if (!isObjectRecord(value))
|
|
44
|
+
return false;
|
|
45
|
+
return Array.isArray(value.instances) && isObjectRecord(value.shapes);
|
|
46
|
+
};
|
|
47
|
+
const isWellFormedParametricNode = (value) => {
|
|
48
|
+
if (!isObjectRecord(value))
|
|
49
|
+
return false;
|
|
50
|
+
if (typeof value.id !== "string" || !value.id)
|
|
51
|
+
return false;
|
|
52
|
+
if (typeof value.name !== "string" || !value.name)
|
|
53
|
+
return false;
|
|
54
|
+
if (Array.isArray(value.parts))
|
|
55
|
+
return true;
|
|
56
|
+
if (isObjectRecord(value.shape))
|
|
57
|
+
return true;
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
export const sanitizeParametricShapes = (value) => {
|
|
61
|
+
var _a;
|
|
62
|
+
value = applyDefaultModelColors(value);
|
|
63
|
+
if (isInstancedFormat(value)) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
if (isWellFormedParametricNode(value)) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
const sanitized = (_a = sanitizeParametricShapeNode(value, "model", "model")) !== null && _a !== void 0 ? _a : {
|
|
70
|
+
id: "model",
|
|
71
|
+
name: "model",
|
|
72
|
+
parts: [],
|
|
73
|
+
};
|
|
74
|
+
return sanitized;
|
|
75
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Viewer3DClipping, Viewer3DState } from "../../types";
|
|
2
|
+
import { Viewer } from "three-cad-viewer";
|
|
3
|
+
type ViewerInstance = InstanceType<typeof Viewer>;
|
|
4
|
+
export declare const setParametricZebraActive: (viewer: ViewerInstance | null, active: boolean) => void;
|
|
5
|
+
export declare const getParametricZebraActive: (viewer: ViewerInstance | null) => boolean;
|
|
6
|
+
export declare const setParametricExplodeState: (viewer: ViewerInstance | null, active: boolean, value: number) => void;
|
|
7
|
+
export declare const getParametricExplodeState: (viewer: ViewerInstance | null) => {
|
|
8
|
+
active: boolean;
|
|
9
|
+
value: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const extractParametricClippingState: (viewer: ViewerInstance | null) => Viewer3DClipping;
|
|
12
|
+
interface ApplyParametricViewerStateOptions {
|
|
13
|
+
applyCamera?: boolean;
|
|
14
|
+
previousState?: Viewer3DState | null;
|
|
15
|
+
}
|
|
16
|
+
export interface ParametricViewerStateApplyPlan {
|
|
17
|
+
camera: boolean;
|
|
18
|
+
display: boolean;
|
|
19
|
+
material: boolean;
|
|
20
|
+
clipping: boolean;
|
|
21
|
+
explode: boolean;
|
|
22
|
+
zebra: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const getParametricViewerStateApplyPlan: (state: Viewer3DState, previousState: Viewer3DState | null | undefined) => ParametricViewerStateApplyPlan;
|
|
25
|
+
export declare const applyParametricViewerState: (viewer: ViewerInstance | null, state: Viewer3DState, options?: ApplyParametricViewerStateOptions) => boolean;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { applyParametricClipping, getParametricClipPercentValue, PARAMETRIC_CLIP_AXIS_NORMALS, } from "./parametricClip";
|
|
2
|
+
import { getViewerGridPlanes, viewerGridPlanesToTuple } from "./viewerGrid";
|
|
3
|
+
const PARAMETRIC_CLIP_AXES = ["x", "y", "z"];
|
|
4
|
+
const PARAMETRIC_CLIP_SLIDER_KEYS = ["clipSlider0", "clipSlider1", "clipSlider2"];
|
|
5
|
+
const zebraActiveByViewer = new WeakMap();
|
|
6
|
+
const explodeStateByViewer = new WeakMap();
|
|
7
|
+
const deepEqual = (a, b) => {
|
|
8
|
+
if (a === b)
|
|
9
|
+
return true;
|
|
10
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object")
|
|
11
|
+
return false;
|
|
12
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
13
|
+
};
|
|
14
|
+
const getRenderedViewer = (viewer) => {
|
|
15
|
+
var _a;
|
|
16
|
+
try {
|
|
17
|
+
return (_a = viewer === null || viewer === void 0 ? void 0 : viewer.rendered) !== null && _a !== void 0 ? _a : null;
|
|
18
|
+
}
|
|
19
|
+
catch (_b) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const safeViewerStateGet = (viewer, key) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
try {
|
|
26
|
+
return (_b = (_a = viewer === null || viewer === void 0 ? void 0 : viewer.state) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, key);
|
|
27
|
+
}
|
|
28
|
+
catch (_c) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const setParametricZebraActive = (viewer, active) => {
|
|
33
|
+
if (!viewer)
|
|
34
|
+
return;
|
|
35
|
+
zebraActiveByViewer.set(viewer, active);
|
|
36
|
+
};
|
|
37
|
+
export const getParametricZebraActive = (viewer) => {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!viewer)
|
|
40
|
+
return false;
|
|
41
|
+
return (_a = zebraActiveByViewer.get(viewer)) !== null && _a !== void 0 ? _a : false;
|
|
42
|
+
};
|
|
43
|
+
export const setParametricExplodeState = (viewer, active, value) => {
|
|
44
|
+
if (!viewer)
|
|
45
|
+
return;
|
|
46
|
+
explodeStateByViewer.set(viewer, {
|
|
47
|
+
active,
|
|
48
|
+
value: active ? value : 0,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export const getParametricExplodeState = (viewer) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (!viewer) {
|
|
54
|
+
return { active: false, value: 0 };
|
|
55
|
+
}
|
|
56
|
+
const cachedState = explodeStateByViewer.get(viewer);
|
|
57
|
+
if (cachedState) {
|
|
58
|
+
return cachedState;
|
|
59
|
+
}
|
|
60
|
+
const active = (_a = safeViewerStateGet(viewer, "explode")) !== null && _a !== void 0 ? _a : false;
|
|
61
|
+
const relativeTime = (_b = safeViewerStateGet(viewer, "relativeTime")) !== null && _b !== void 0 ? _b : 0;
|
|
62
|
+
const resolvedState = {
|
|
63
|
+
active,
|
|
64
|
+
value: active && Number.isFinite(relativeTime) ? relativeTime : 0,
|
|
65
|
+
};
|
|
66
|
+
explodeStateByViewer.set(viewer, resolvedState);
|
|
67
|
+
return resolvedState;
|
|
68
|
+
};
|
|
69
|
+
export const extractParametricClippingState = (viewer) => {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
71
|
+
const rendered = getRenderedViewer(viewer);
|
|
72
|
+
if (!viewer || !(rendered === null || rendered === void 0 ? void 0 : rendered.clipping)) {
|
|
73
|
+
return {
|
|
74
|
+
x: { enabled: false, value: 0, normal: null },
|
|
75
|
+
y: { enabled: false, value: 0, normal: null },
|
|
76
|
+
z: { enabled: false, value: 0, normal: null },
|
|
77
|
+
intersection: false,
|
|
78
|
+
showPlanes: false,
|
|
79
|
+
objectColorCaps: false,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const hasLocalClipping = Boolean((_a = viewer.renderer) === null || _a === void 0 ? void 0 : _a.localClippingEnabled);
|
|
83
|
+
const activeClipPlaneSet = new Set((_c = (_b = rendered.nestedGroup) === null || _b === void 0 ? void 0 : _b.clipPlanes) !== null && _c !== void 0 ? _c : []);
|
|
84
|
+
const allClipPlanes = (_d = rendered.clipping.clipPlanes) !== null && _d !== void 0 ? _d : [];
|
|
85
|
+
const reverseClipPlanes = (_e = rendered.clipping.reverseClipPlanes) !== null && _e !== void 0 ? _e : [];
|
|
86
|
+
const planes = {};
|
|
87
|
+
for (let index = 0; index < PARAMETRIC_CLIP_AXES.length; index++) {
|
|
88
|
+
const axis = PARAMETRIC_CLIP_AXES[index];
|
|
89
|
+
const sliderValue = safeViewerStateGet(viewer, PARAMETRIC_CLIP_SLIDER_KEYS[index]);
|
|
90
|
+
const actualValue = typeof sliderValue === "number" && Number.isFinite(sliderValue)
|
|
91
|
+
? sliderValue
|
|
92
|
+
: 0;
|
|
93
|
+
const enabled = hasLocalClipping && (activeClipPlaneSet.has(allClipPlanes[index]) ||
|
|
94
|
+
activeClipPlaneSet.has(reverseClipPlanes[index]));
|
|
95
|
+
planes[axis] = enabled
|
|
96
|
+
? {
|
|
97
|
+
enabled: true,
|
|
98
|
+
value: getParametricClipPercentValue(viewer, axis, {
|
|
99
|
+
enabled: true,
|
|
100
|
+
value: actualValue,
|
|
101
|
+
normal: null,
|
|
102
|
+
}),
|
|
103
|
+
normal: PARAMETRIC_CLIP_AXIS_NORMALS[axis],
|
|
104
|
+
}
|
|
105
|
+
: {
|
|
106
|
+
enabled: false,
|
|
107
|
+
value: 0,
|
|
108
|
+
normal: null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return Object.assign(Object.assign({}, planes), { intersection: (_f = safeViewerStateGet(viewer, "clipIntersection")) !== null && _f !== void 0 ? _f : false, showPlanes: (_g = safeViewerStateGet(viewer, "clipPlaneHelpers")) !== null && _g !== void 0 ? _g : false, objectColorCaps: (_h = safeViewerStateGet(viewer, "clipObjectColors")) !== null && _h !== void 0 ? _h : false });
|
|
112
|
+
};
|
|
113
|
+
export const getParametricViewerStateApplyPlan = (state, previousState) => ({
|
|
114
|
+
camera: !previousState || !deepEqual(previousState.camera, state.camera),
|
|
115
|
+
display: !previousState || !deepEqual(previousState.display, state.display),
|
|
116
|
+
material: !previousState || !deepEqual(previousState.material, state.material),
|
|
117
|
+
clipping: !previousState || !deepEqual(previousState.clipping, state.clipping),
|
|
118
|
+
explode: !previousState || !deepEqual(previousState.explode, state.explode),
|
|
119
|
+
zebra: !previousState || !deepEqual(previousState.zebra, state.zebra),
|
|
120
|
+
});
|
|
121
|
+
export const applyParametricViewerState = (viewer, state, options = {}) => {
|
|
122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
|
|
123
|
+
const rendered = getRenderedViewer(viewer);
|
|
124
|
+
if (!viewer || !rendered)
|
|
125
|
+
return false;
|
|
126
|
+
try {
|
|
127
|
+
const applyCamera = (_a = options.applyCamera) !== null && _a !== void 0 ? _a : true;
|
|
128
|
+
const { display, material, clipping, explode, zebra } = state;
|
|
129
|
+
const applyPlan = getParametricViewerStateApplyPlan(state, options.previousState);
|
|
130
|
+
if (applyCamera && applyPlan.camera) {
|
|
131
|
+
const currentOrtho = (_c = (_b = viewer.state) === null || _b === void 0 ? void 0 : _b.get) === null || _c === void 0 ? void 0 : _c.call(_b, "ortho");
|
|
132
|
+
if (typeof currentOrtho === "boolean" && currentOrtho !== state.camera.ortho) {
|
|
133
|
+
(_e = (_d = viewer).switchCamera) === null || _e === void 0 ? void 0 : _e.call(_d, state.camera.ortho);
|
|
134
|
+
}
|
|
135
|
+
const camera = rendered.camera.getCamera();
|
|
136
|
+
const controls = rendered.controls;
|
|
137
|
+
const { position, quaternion, target, zoom } = state.camera;
|
|
138
|
+
if ((position === null || position === void 0 ? void 0 : position.length) === 3) {
|
|
139
|
+
camera.position.set(position[0], position[1], position[2]);
|
|
140
|
+
}
|
|
141
|
+
if ((quaternion === null || quaternion === void 0 ? void 0 : quaternion.length) === 4) {
|
|
142
|
+
camera.quaternion.set(quaternion[0], quaternion[1], quaternion[2], quaternion[3]);
|
|
143
|
+
}
|
|
144
|
+
if (typeof zoom === "number" && "zoom" in camera) {
|
|
145
|
+
camera.zoom = zoom;
|
|
146
|
+
(_g = (_f = camera).updateProjectionMatrix) === null || _g === void 0 ? void 0 : _g.call(_f);
|
|
147
|
+
}
|
|
148
|
+
if ((target === null || target === void 0 ? void 0 : target.length) === 3 && (controls === null || controls === void 0 ? void 0 : controls.target)) {
|
|
149
|
+
controls.target.set(target[0], target[1], target[2]);
|
|
150
|
+
(_h = controls.update) === null || _h === void 0 ? void 0 : _h.call(controls);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (applyPlan.material) {
|
|
154
|
+
(_k = (_j = viewer).setAmbientLight) === null || _k === void 0 ? void 0 : _k.call(_j, material.ambientIntensity);
|
|
155
|
+
(_m = (_l = viewer).setDirectLight) === null || _m === void 0 ? void 0 : _m.call(_l, material.directIntensity);
|
|
156
|
+
(_p = (_o = viewer).setMetalness) === null || _p === void 0 ? void 0 : _p.call(_o, material.metalness);
|
|
157
|
+
(_r = (_q = viewer).setRoughness) === null || _r === void 0 ? void 0 : _r.call(_q, material.roughness);
|
|
158
|
+
}
|
|
159
|
+
if (applyPlan.display) {
|
|
160
|
+
const [gridXY, gridXZ, gridYZ] = viewerGridPlanesToTuple(getViewerGridPlanes(display.grid));
|
|
161
|
+
(_t = (_s = viewer).setTransparent) === null || _t === void 0 ? void 0 : _t.call(_s, display.transparent);
|
|
162
|
+
(_v = (_u = viewer).setBlackEdges) === null || _v === void 0 ? void 0 : _v.call(_u, display.blackEdges);
|
|
163
|
+
(_x = (_w = viewer).setAxes) === null || _x === void 0 ? void 0 : _x.call(_w, display.axesVisible);
|
|
164
|
+
(_z = (_y = viewer).setAxes0) === null || _z === void 0 ? void 0 : _z.call(_y, display.axesAtOrigin);
|
|
165
|
+
(_1 = (_0 = viewer).setGrids) === null || _1 === void 0 ? void 0 : _1.call(_0, [gridXY, gridXZ, gridYZ]);
|
|
166
|
+
}
|
|
167
|
+
if (applyPlan.clipping) {
|
|
168
|
+
applyParametricClipping(viewer, clipping);
|
|
169
|
+
}
|
|
170
|
+
if (applyPlan.explode) {
|
|
171
|
+
setParametricExplodeState(viewer, explode.active, explode.value);
|
|
172
|
+
(_3 = (_2 = viewer).setExplode) === null || _3 === void 0 ? void 0 : _3.call(_2, explode.active);
|
|
173
|
+
(_5 = (_4 = viewer).setRelativeTime) === null || _5 === void 0 ? void 0 : _5.call(_4, explode.active ? explode.value : 0);
|
|
174
|
+
}
|
|
175
|
+
if (applyPlan.zebra) {
|
|
176
|
+
setParametricZebraActive(viewer, zebra.active);
|
|
177
|
+
(_7 = (_6 = viewer).enableZebraTool) === null || _7 === void 0 ? void 0 : _7.call(_6, zebra.active);
|
|
178
|
+
(_9 = (_8 = viewer).setZebraCount) === null || _9 === void 0 ? void 0 : _9.call(_8, zebra.stripeCount);
|
|
179
|
+
(_11 = (_10 = viewer).setZebraOpacity) === null || _11 === void 0 ? void 0 : _11.call(_10, zebra.opacity);
|
|
180
|
+
(_13 = (_12 = viewer).setZebraDirection) === null || _13 === void 0 ? void 0 : _13.call(_12, zebra.stripeDirection);
|
|
181
|
+
(_15 = (_14 = viewer).setZebraColorScheme) === null || _15 === void 0 ? void 0 : _15.call(_14, zebra.colorScheme);
|
|
182
|
+
(_17 = (_16 = viewer).setZebraMappingMode) === null || _17 === void 0 ? void 0 : _17.call(_16, zebra.mappingMode);
|
|
183
|
+
}
|
|
184
|
+
const didApplyState = ((applyCamera && applyPlan.camera)
|
|
185
|
+
|| applyPlan.display
|
|
186
|
+
|| applyPlan.material
|
|
187
|
+
|| applyPlan.clipping
|
|
188
|
+
|| applyPlan.explode
|
|
189
|
+
|| applyPlan.zebra);
|
|
190
|
+
if (didApplyState) {
|
|
191
|
+
(_19 = (_18 = viewer).update) === null || _19 === void 0 ? void 0 : _19.call(_18, true);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch (_20) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Viewer } from "three-cad-viewer";
|
|
2
|
+
type ThreeViewer = InstanceType<typeof Viewer>;
|
|
3
|
+
export declare const fitThreeCadViewerCameraToBounds: (viewer: ThreeViewer) => boolean;
|
|
4
|
+
export declare const fitThreeCadViewerCameraToVisibleScene: (viewer: ThreeViewer, canvasAspect?: number) => boolean;
|
|
5
|
+
export declare const snapshotThreeCadViewerCamera: (viewer: ThreeViewer) => (() => void) | null;
|
|
6
|
+
export {};
|