@constructorfleet/sketchforge-engine 1.27.0 → 1.29.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/cadAnalysis.d.ts.map +1 -1
- package/dist/cadAnalysis.js +14 -0
- package/dist/cadAnalysis.js.map +1 -1
- package/dist/cadBakeMetadata.d.ts +11 -2
- package/dist/cadBakeMetadata.d.ts.map +1 -1
- package/dist/cadBakeMetadata.js +9 -0
- package/dist/cadBakeMetadata.js.map +1 -1
- package/dist/cadProjection.d.ts.map +1 -1
- package/dist/cadProjection.js.map +1 -1
- package/dist/cadSection.d.ts.map +1 -1
- package/dist/cadShell.d.ts +1 -1
- package/dist/cadShell.d.ts.map +1 -1
- package/dist/cadShell.js +7 -0
- package/dist/cadShell.js.map +1 -1
- package/dist/cadSolids.d.ts.map +1 -1
- package/dist/cadSolids.js +18 -1
- package/dist/cadSolids.js.map +1 -1
- package/dist/cutBrepFrameMigration.d.ts +46 -0
- package/dist/cutBrepFrameMigration.d.ts.map +1 -0
- package/dist/cutBrepFrameMigration.js +105 -0
- package/dist/cutBrepFrameMigration.js.map +1 -0
- package/dist/cutterPadding.d.ts.map +1 -1
- package/dist/domain/cameraProjection.js.map +1 -1
- package/dist/domain/sketchforge.d.ts +30 -0
- package/dist/domain/sketchforge.d.ts.map +1 -1
- package/dist/editorHistory.d.ts.map +1 -1
- package/dist/editorHistory.js.map +1 -1
- package/dist/engine.d.ts +3 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +203 -146
- package/dist/engine.js.map +1 -1
- package/dist/exactBooleanParts.d.ts +4 -2
- package/dist/exactBooleanParts.d.ts.map +1 -1
- package/dist/exactBooleanParts.js +7 -3
- package/dist/exactBooleanParts.js.map +1 -1
- package/dist/exactBooleanSolids.d.ts.map +1 -1
- package/dist/faceMetadata.d.ts +4 -0
- package/dist/faceMetadata.d.ts.map +1 -0
- package/dist/faceMetadata.js +71 -0
- package/dist/faceMetadata.js.map +1 -0
- package/dist/gearProfile.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loftProfile.d.ts +1 -1
- package/dist/loftProfile.d.ts.map +1 -1
- package/dist/loftProfile.js.map +1 -1
- package/dist/meshEdgeProjection.d.ts +104 -0
- package/dist/meshEdgeProjection.d.ts.map +1 -0
- package/dist/meshEdgeProjection.js +439 -0
- package/dist/meshEdgeProjection.js.map +1 -0
- package/dist/meshImport.d.ts.map +1 -1
- package/dist/meshImport.js +2 -20
- package/dist/meshImport.js.map +1 -1
- package/dist/meshMassProperties.d.ts +92 -0
- package/dist/meshMassProperties.d.ts.map +1 -0
- package/dist/meshMassProperties.js +570 -0
- package/dist/meshMassProperties.js.map +1 -0
- package/dist/meshSection.d.ts +44 -0
- package/dist/meshSection.d.ts.map +1 -0
- package/dist/meshSection.js +154 -0
- package/dist/meshSection.js.map +1 -0
- package/dist/meshShellOverlap.d.ts +75 -0
- package/dist/meshShellOverlap.d.ts.map +1 -0
- package/dist/meshShellOverlap.js +797 -0
- package/dist/meshShellOverlap.js.map +1 -0
- package/dist/meshShellSolids.d.ts +44 -0
- package/dist/meshShellSolids.d.ts.map +1 -0
- package/dist/meshShellSolids.js +116 -0
- package/dist/meshShellSolids.js.map +1 -0
- package/dist/nodeSvgDomParser.d.ts +3 -0
- package/dist/nodeSvgDomParser.d.ts.map +1 -0
- package/dist/nodeSvgDomParser.js +53 -0
- package/dist/nodeSvgDomParser.js.map +1 -0
- package/dist/parametricRecompute.d.ts +22 -4
- package/dist/parametricRecompute.d.ts.map +1 -1
- package/dist/parametricRecompute.js +504 -129
- package/dist/parametricRecompute.js.map +1 -1
- package/dist/placementWorkplane.d.ts.map +1 -1
- package/dist/placementWorkplane.js.map +1 -1
- package/dist/projectAssets.d.ts +1 -1
- package/dist/projectStore.d.ts +1 -1
- package/dist/projectStore.d.ts.map +1 -1
- package/dist/projectStore.js +23 -2
- package/dist/projectStore.js.map +1 -1
- package/dist/revolveRequests.d.ts +57 -1
- package/dist/revolveRequests.d.ts.map +1 -1
- package/dist/revolveRequests.js +103 -4
- package/dist/revolveRequests.js.map +1 -1
- package/dist/sceneExport.d.ts +6 -0
- package/dist/sceneExport.d.ts.map +1 -1
- package/dist/sceneExport.js +6 -2
- package/dist/sceneExport.js.map +1 -1
- package/dist/serverCadInterference.d.ts.map +1 -1
- package/dist/serverCadInterference.js +9 -2
- package/dist/serverCadInterference.js.map +1 -1
- package/dist/serverCadOperations.d.ts +73 -4
- package/dist/serverCadOperations.d.ts.map +1 -1
- package/dist/serverCadOperations.js +328 -51
- package/dist/serverCadOperations.js.map +1 -1
- package/dist/serverCadProjection.d.ts +14 -1
- package/dist/serverCadProjection.d.ts.map +1 -1
- package/dist/serverCadProjection.js +135 -13
- package/dist/serverCadProjection.js.map +1 -1
- package/dist/serverCadProperties.d.ts +14 -7
- package/dist/serverCadProperties.d.ts.map +1 -1
- package/dist/serverCadProperties.js +109 -24
- package/dist/serverCadProperties.js.map +1 -1
- package/dist/serverCadSection.d.ts +21 -1
- package/dist/serverCadSection.d.ts.map +1 -1
- package/dist/serverCadSection.js +157 -43
- package/dist/serverCadSection.js.map +1 -1
- package/dist/serverCadShell.d.ts.map +1 -1
- package/dist/serverCadShell.js +0 -3
- package/dist/serverCadShell.js.map +1 -1
- package/dist/serverShapeBooleans.d.ts +75 -0
- package/dist/serverShapeBooleans.d.ts.map +1 -1
- package/dist/serverShapeBooleans.js +251 -9
- package/dist/serverShapeBooleans.js.map +1 -1
- package/dist/serverShapeGroups.js.map +1 -1
- package/dist/shapeBounds.d.ts.map +1 -1
- package/dist/shapeCatalog.d.ts.map +1 -1
- package/dist/shapeCatalog.js +1 -0
- package/dist/shapeCatalog.js.map +1 -1
- package/dist/shapeRequests.d.ts +13 -0
- package/dist/shapeRequests.d.ts.map +1 -1
- package/dist/shapeRequests.js +14 -0
- package/dist/shapeRequests.js.map +1 -1
- package/dist/sketchCadProfile.d.ts +13 -0
- package/dist/sketchCadProfile.d.ts.map +1 -1
- package/dist/sketchCadProfile.js +108 -0
- package/dist/sketchCadProfile.js.map +1 -1
- package/dist/sketchCadSweep.js.map +1 -1
- package/dist/sketchEdgeSegmentLineage.d.ts +32 -0
- package/dist/sketchEdgeSegmentLineage.d.ts.map +1 -0
- package/dist/sketchEdgeSegmentLineage.js +49 -0
- package/dist/sketchEdgeSegmentLineage.js.map +1 -0
- package/dist/sketchEdgeSegmentLineageKernel.d.ts +83 -0
- package/dist/sketchEdgeSegmentLineageKernel.d.ts.map +1 -0
- package/dist/sketchEdgeSegmentLineageKernel.js +125 -0
- package/dist/sketchEdgeSegmentLineageKernel.js.map +1 -0
- package/dist/sketchFaceDraftKernel.d.ts +11 -4
- package/dist/sketchFaceDraftKernel.d.ts.map +1 -1
- package/dist/sketchFaceDraftKernel.js +8 -2
- package/dist/sketchFaceDraftKernel.js.map +1 -1
- package/dist/sketchRevolve.d.ts +13 -0
- package/dist/sketchRevolve.d.ts.map +1 -1
- package/dist/sketchRevolve.js +4 -1
- package/dist/sketchRevolve.js.map +1 -1
- package/dist/skfProject.d.ts +1 -1
- package/dist/skfProject.d.ts.map +1 -1
- package/dist/skfProject.js +63 -4
- package/dist/skfProject.js.map +1 -1
- package/dist/sphereTessellation.d.ts.map +1 -1
- package/dist/stepAssemblyExplode.d.ts.map +1 -1
- package/dist/stepAssemblyExplode.js +1 -1
- package/dist/stepAssemblyExplode.js.map +1 -1
- package/dist/stepAssemblyHierarchy.js.map +1 -1
- package/dist/stepComponentMetadata.d.ts +1 -1
- package/dist/stepComponentMetadata.d.ts.map +1 -1
- package/dist/stepComponentMetadata.js +93 -39
- package/dist/stepComponentMetadata.js.map +1 -1
- package/dist/stepExport.d.ts +14 -1
- package/dist/stepExport.d.ts.map +1 -1
- package/dist/stepExport.js +81 -32
- package/dist/stepExport.js.map +1 -1
- package/dist/stepImportCommon.d.ts +4 -1
- package/dist/stepImportCommon.d.ts.map +1 -1
- package/dist/stepImportCommon.js +7 -6
- package/dist/stepImportCommon.js.map +1 -1
- package/dist/stlImport.d.ts.map +1 -1
- package/dist/stlImport.js +9 -1
- package/dist/stlImport.js.map +1 -1
- package/dist/support/cadModifierTypes.d.ts +41 -1
- package/dist/support/cadModifierTypes.d.ts.map +1 -1
- package/dist/support/i18n/LocalizedError.d.ts.map +1 -1
- package/dist/support/i18n/locales/en/messages.json +30 -2
- package/dist/support/i18n/locales.d.ts.map +1 -1
- package/dist/support/lib/appTheme.d.ts.map +1 -1
- package/dist/support/lib/materialPresets.js.map +1 -1
- package/dist/support/lib/measurementUnits.d.ts.map +1 -1
- package/dist/support/lib/operator-configuration.json +13 -1
- package/dist/support/lib/operatorConfiguration.d.ts +5 -5
- package/dist/support/lib/workplaneGrid.js.map +1 -1
- package/dist/svgImport.d.ts +2 -0
- package/dist/svgImport.d.ts.map +1 -1
- package/dist/svgImport.js +7 -0
- package/dist/svgImport.js.map +1 -1
- package/dist/threadCatalog.js.map +1 -1
- package/dist/workplaneSettings.js.map +1 -1
- package/dist/workplaneShapes.d.ts +2 -2
- package/dist/workplaneShapes.d.ts.map +1 -1
- package/dist/workplaneShapes.js.map +1 -1
- package/package.json +7 -6
package/dist/engine.js
CHANGED
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
* -- including the project lock, which a macro writing a directory needs and
|
|
15
15
|
* does not have today -- without pulling `next/server` in with it.
|
|
16
16
|
*/
|
|
17
|
-
import { allEdgeTreatmentEdgeCount, applyEdgeTreatment, applyBakedMirror, applyDraftPrism, applySketchFaceDraft, exactPlainSketchRevolveResult, isPlainFullTurnSketchRevolve, orientedSolidForShape, shapeEdges, shapeWithCadResult, ServerCadError, } from "./serverCadOperations.js";
|
|
17
|
+
import { allEdgeTreatmentEdgeCount, applyEdgeTreatment, applyBakedMirror, applyDraftPrism, applySketchFaceDraft, exactPlainSketchRevolveResult, isPlainFullTurnSketchRevolve, orientedSolidForShape, shapeEdges, shapeWithCadResult, sketchResizeFactors, ServerCadError, } from "./serverCadOperations.js";
|
|
18
18
|
import { resolveRetainedFaceDraft, retainedDraftSourcePlacement, retainedFaceDraftFields, retainedPrismDraftFields, } from "./sketchFaceDraftKernel.js";
|
|
19
19
|
import { withCadKernel } from "./serverCadKernel.js";
|
|
20
20
|
import { cadSketchRegions, cadSketchSweepPaths } from "./sketchCadProfile.js";
|
|
21
21
|
import { applyShell, shapeFaces, } from "./serverCadShell.js";
|
|
22
22
|
import { measureBetween as measureBetweenEntities, shapeMeasurements, } from "./serverCadMeasure.js";
|
|
23
23
|
import { shapeProperties } from "./serverCadProperties.js";
|
|
24
|
+
import { preserveUnambiguousFaceMetadata } from "./faceMetadata.js";
|
|
24
25
|
import { checkInterference } from "./serverCadInterference.js";
|
|
25
26
|
import { explodeStepAssembly } from "./serverStepExplode.js";
|
|
26
27
|
import { alignShifts, effectiveAlignAnchorId, ALIGN_EPSILON, } from "./alignShapes.js";
|
|
@@ -30,16 +31,16 @@ import { circularPatternPlacements, linearPatternPlacements } from "./patternSha
|
|
|
30
31
|
import { dedupeProjectAssets } from "./projectAssets.js";
|
|
31
32
|
import { isRevolveShape, outlineFromProfile, parseRevolveRequest, rebuiltRevolveShape, requestedRevolveSettings, resolvedThreadRequest, revolvedShapeFromRequest, REVOLVE_CHANGE_FIELDS, REVOLVE_ONLY_FIELDS, } from "./revolveRequests.js";
|
|
32
33
|
import { buildGroupFromSelection } from "./serverShapeBooleans.js";
|
|
33
|
-
import { boundsForShapes as boundsForMirroring, restoreGroupedChildren, separateShapeParts } from "./serverShapeGroups.js";
|
|
34
|
+
import { boundsForShapes as boundsForMirroring, restoreGroupedChildren, separateShapeParts, worldMeshForShape } from "./serverShapeGroups.js";
|
|
34
35
|
import { serverManifoldRuntime } from "./serverManifoldRuntime.js";
|
|
35
36
|
import { createLocalId } from "./localIds.js";
|
|
36
37
|
import { invalidSketchSweepProfile, sketchSweepShapeFromRequest } from "./sketchSweepRequest.js";
|
|
37
38
|
import { sketchExtrusionShapeFromRequest } from "./sketchExtrusionRequest.js";
|
|
38
|
-
import {
|
|
39
|
+
import { sketchSourceEdgesForEdgeIndexes } from "./sketchEdgeSegmentLineage.js";
|
|
40
|
+
import { edgeTreatmentAppliedFrame, findSketchOutput, recompute, replaceSketchOutput, replaySingleAllEdgeTreatment, } from "./parametricRecompute.js";
|
|
39
41
|
import { boundsForShapes, footprintCenter, shapeBounds } from "./shapeBounds.js";
|
|
40
|
-
import { REQUESTABLE_SHAPE_KINDS, shapeFromRequest, shapeWithRequestedChanges, SHAPE_PARAMETERS, } from "./shapeRequests.js";
|
|
42
|
+
import { REQUESTABLE_SHAPE_KINDS, shapeFromRequest, shapeWithRequestedChanges, SHAPE_PARAMETERS, withResultAttributes, } from "./shapeRequests.js";
|
|
41
43
|
import { canonicalizeShape, cleanNearZero, cleanRotationDegrees, cloneWorkplaneShapeTreeWithFreshIds, withHoleMode, } from "./workplaneShapes.js";
|
|
42
|
-
const UNIQUE_CURVED_FACE_SURFACES = new Set(["cone", "sphere", "torus", "cylinder"]);
|
|
43
44
|
const FACE_DRAFT_AXES = new Set(["x", "y", "z", "-x", "-y", "-z"]);
|
|
44
45
|
function faceDraftInput(value) {
|
|
45
46
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -104,81 +105,6 @@ function unmirroredDraftSource(shape) {
|
|
|
104
105
|
function retainDraftSourceMirrors(result, source) {
|
|
105
106
|
return { ...result, mirrorX: source.mirrorX, mirrorY: source.mirrorY, mirrorZ: source.mirrorZ };
|
|
106
107
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Carry face metadata across a parameter edit only when a face has a unique
|
|
109
|
-
* counterpart. Curved faces may change their sampled normal as their defining
|
|
110
|
-
* dimensions change, so a curved surface type can be a fallback identity only
|
|
111
|
-
* when it occurs exactly once before and after. Repeated faces remain
|
|
112
|
-
* unmatched rather than guessed.
|
|
113
|
-
*/
|
|
114
|
-
async function preserveUnambiguousFaceMetadata(previous, next) {
|
|
115
|
-
if (!previous.faceIds?.length && !previous.faceColors)
|
|
116
|
-
return next;
|
|
117
|
-
const before = await shapeFaces(previous);
|
|
118
|
-
const after = await shapeFaces(next);
|
|
119
|
-
const signature = (face) => face.normal
|
|
120
|
-
? `${face.surfaceType}:${Math.round(face.normal.x * 1000)}:${Math.round(face.normal.y * 1000)}:${Math.round(face.normal.z * 1000)}:${face.facing ?? "interior"}`
|
|
121
|
-
: undefined;
|
|
122
|
-
const beforeBySignature = new Map();
|
|
123
|
-
const afterBySignature = new Map();
|
|
124
|
-
for (const face of before) {
|
|
125
|
-
const key = signature(face);
|
|
126
|
-
if (key)
|
|
127
|
-
beforeBySignature.set(key, [...(beforeBySignature.get(key) ?? []), face]);
|
|
128
|
-
}
|
|
129
|
-
for (const face of after) {
|
|
130
|
-
const key = signature(face);
|
|
131
|
-
if (key)
|
|
132
|
-
afterBySignature.set(key, [...(afterBySignature.get(key) ?? []), face]);
|
|
133
|
-
}
|
|
134
|
-
const beforeBySurface = new Map();
|
|
135
|
-
const afterBySurface = new Map();
|
|
136
|
-
for (const face of before)
|
|
137
|
-
beforeBySurface.set(face.surfaceType, [...(beforeBySurface.get(face.surfaceType) ?? []), face]);
|
|
138
|
-
for (const face of after)
|
|
139
|
-
afterBySurface.set(face.surfaceType, [...(afterBySurface.get(face.surfaceType) ?? []), face]);
|
|
140
|
-
const beforeForAfter = new Map();
|
|
141
|
-
const matchedBefore = new Set();
|
|
142
|
-
for (const face of after) {
|
|
143
|
-
const key = signature(face);
|
|
144
|
-
const oldMatches = key ? beforeBySignature.get(key) ?? [] : [];
|
|
145
|
-
const newMatches = key ? afterBySignature.get(key) ?? [] : [];
|
|
146
|
-
if (oldMatches.length === 1 && newMatches.length === 1) {
|
|
147
|
-
beforeForAfter.set(face.index, oldMatches[0]);
|
|
148
|
-
matchedBefore.add(oldMatches[0].index);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
for (const face of after) {
|
|
152
|
-
if (beforeForAfter.has(face.index) || !UNIQUE_CURVED_FACE_SURFACES.has(face.surfaceType))
|
|
153
|
-
continue;
|
|
154
|
-
const oldMatches = beforeBySurface.get(face.surfaceType) ?? [];
|
|
155
|
-
const newMatches = afterBySurface.get(face.surfaceType) ?? [];
|
|
156
|
-
if (oldMatches.length === 1 && newMatches.length === 1 && !matchedBefore.has(oldMatches[0].index)) {
|
|
157
|
-
beforeForAfter.set(face.index, oldMatches[0]);
|
|
158
|
-
matchedBefore.add(oldMatches[0].index);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const ids = after.map((face) => beforeForAfter.get(face.index)?.id
|
|
162
|
-
?? `face_${createLocalId(`${next.id}-${face.index}`)}`);
|
|
163
|
-
const mappedColors = {};
|
|
164
|
-
for (const [key, color] of Object.entries(previous.faceColors ?? {})) {
|
|
165
|
-
const oldIndex = /^\d+$/.test(key) ? Number(key) : -1;
|
|
166
|
-
const oldFace = oldIndex >= 0
|
|
167
|
-
? before[oldIndex]
|
|
168
|
-
: before.find((face) => face.id === key);
|
|
169
|
-
if (!oldFace)
|
|
170
|
-
continue;
|
|
171
|
-
const matched = after.find((face) => beforeForAfter.get(face.index)?.index === oldFace.index);
|
|
172
|
-
if (!matched)
|
|
173
|
-
continue;
|
|
174
|
-
mappedColors[ids[matched.index]] = color;
|
|
175
|
-
}
|
|
176
|
-
return canonicalizeShape({
|
|
177
|
-
...next,
|
|
178
|
-
faceIds: ids,
|
|
179
|
-
faceColors: Object.keys(mappedColors).length ? mappedColors : undefined,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
108
|
function ok(value) {
|
|
183
109
|
return { ok: true, value };
|
|
184
110
|
}
|
|
@@ -256,11 +182,12 @@ function alignEntry(shape, axis) {
|
|
|
256
182
|
: { min: bounds.minY, max: bounds.maxY };
|
|
257
183
|
return { id: shape.id, ...span, locked: shape.locked };
|
|
258
184
|
}
|
|
259
|
-
/** `ServerCadError` keeps its own wording
|
|
185
|
+
/** `ServerCadError` keeps its own wording; unexpected kernel errors stay visible in server logs. */
|
|
260
186
|
function cadFailure(error) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
187
|
+
if (error instanceof ServerCadError)
|
|
188
|
+
return { reason: "cad_refused", message: error.message, status: error.status };
|
|
189
|
+
console.error("Unexpected CAD kernel failure", error);
|
|
190
|
+
return { reason: "cad_failed" };
|
|
264
191
|
}
|
|
265
192
|
/**
|
|
266
193
|
* One shape from one request, built before any lock is taken.
|
|
@@ -276,17 +203,6 @@ function cadFailure(error) {
|
|
|
276
203
|
* and there is no reason to hold a project busy for it.
|
|
277
204
|
*/
|
|
278
205
|
async function builtShape(request, index) {
|
|
279
|
-
if (request.kind === "sketchSweep") {
|
|
280
|
-
const invalidProfile = invalidSketchSweepProfile(request.profile);
|
|
281
|
-
if (invalidProfile)
|
|
282
|
-
return failed({ reason: "invalid_shape_request", index, message: invalidProfile });
|
|
283
|
-
try {
|
|
284
|
-
return ok(await sketchSweepShapeFromRequest(request));
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
return failed({ reason: "sweep_failed", index, message: error instanceof Error ? error.message : "The sketch sweep could not be built." });
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
206
|
if (request.kind === "sketchSweep") {
|
|
291
207
|
const invalidProfile = invalidSketchSweepProfile(request.profile);
|
|
292
208
|
if (invalidProfile)
|
|
@@ -371,7 +287,7 @@ export function createEngine(store) {
|
|
|
371
287
|
* them off the stored shapes, `booleans` is told which operands to treat as
|
|
372
288
|
* holes. `holes` being undefined is the former.
|
|
373
289
|
*/
|
|
374
|
-
async function combine(projectId, ids, holes) {
|
|
290
|
+
async function combine(projectId, ids, holes, attributes = {}) {
|
|
375
291
|
return mutating(projectId, async (document) => {
|
|
376
292
|
const resolved = shapesByIds(document, ids);
|
|
377
293
|
if (!resolved.ok)
|
|
@@ -392,9 +308,10 @@ export function createEngine(store) {
|
|
|
392
308
|
// from success. The editor treats the same case as a failed cut.
|
|
393
309
|
if (outcome.cutRemovedNothing)
|
|
394
310
|
return failed({ reason: "cut_removed_nothing" });
|
|
311
|
+
const group = withResultAttributes(outcome.group, attributes);
|
|
395
312
|
const consumed = new Set(ids);
|
|
396
|
-
const shapes = [...document.shapes.filter((shape) => !consumed.has(shape.id)),
|
|
397
|
-
return ok({ shape:
|
|
313
|
+
const shapes = [...document.shapes.filter((shape) => !consumed.has(shape.id)), group];
|
|
314
|
+
return ok({ shape: group, revision: await writeShapes(projectId, document, shapes) });
|
|
398
315
|
});
|
|
399
316
|
}
|
|
400
317
|
/** The shared tail of `treat` and `shell`: run the kernel, store the result on the shape. */
|
|
@@ -601,7 +518,13 @@ export function createEngine(store) {
|
|
|
601
518
|
}
|
|
602
519
|
if (faceDraftChanged && existing.faceDraft && requestedFaceDraft
|
|
603
520
|
&& requestedFaceDraft.sourceFaceId !== existing.faceDraft.sourceFaceId) {
|
|
604
|
-
|
|
521
|
+
let currentOutputFaces;
|
|
522
|
+
try {
|
|
523
|
+
currentOutputFaces = await shapeFaces(existing);
|
|
524
|
+
}
|
|
525
|
+
catch (error) {
|
|
526
|
+
return failed(cadFailure(error));
|
|
527
|
+
}
|
|
605
528
|
if (!canReselectUntreatedExtrusionFace
|
|
606
529
|
|| !existing.faceDraftSourceFaceIds?.includes(requestedFaceDraft.sourceFaceId)
|
|
607
530
|
|| currentOutputFaces.filter((face) => face.id === requestedFaceDraft.sourceFaceId && face.surfaceType === "plane").length !== 1) {
|
|
@@ -627,6 +550,70 @@ export function createEngine(store) {
|
|
|
627
550
|
if (replacingSketchProfile && !isSketchSweep && !isSketchExtrusion && !isSketchRevolve) {
|
|
628
551
|
return failed({ reason: "unapplicable_fields", kind: existing.kind, fields: ["sketchProfile"], because: "no_sweep" });
|
|
629
552
|
}
|
|
553
|
+
if (sourceSketchTarget && rebuildsFromSource) {
|
|
554
|
+
if (replacingSketchProfile && isSketchSweep) {
|
|
555
|
+
const invalidProfile = invalidSketchSweepProfile(changes.sketchProfile);
|
|
556
|
+
if (invalidProfile)
|
|
557
|
+
return failed({ reason: "invalid_shape_request", message: invalidProfile });
|
|
558
|
+
}
|
|
559
|
+
let recipeFaceDraft = existing.faceDraft;
|
|
560
|
+
let recipeFaceDraftSourceFaceIds = existing.faceDraftSourceFaceIds;
|
|
561
|
+
let recipeFaceDraftSourceSegmentId = existing.faceDraftSourceSegmentId;
|
|
562
|
+
let recipeFaceDraftSourceFrame = existing.faceDraftSourceFrame;
|
|
563
|
+
if (faceDraftChanged) {
|
|
564
|
+
if (!requestedFaceDraft) {
|
|
565
|
+
recipeFaceDraft = undefined;
|
|
566
|
+
recipeFaceDraftSourceFaceIds = undefined;
|
|
567
|
+
recipeFaceDraftSourceSegmentId = undefined;
|
|
568
|
+
recipeFaceDraftSourceFrame = undefined;
|
|
569
|
+
}
|
|
570
|
+
else if (existing.faceDraft && requestedFaceDraft.sourceFaceId === existing.faceDraft.sourceFaceId) {
|
|
571
|
+
recipeFaceDraft = { ...existing.faceDraft, ...requestedFaceDraft };
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
try {
|
|
575
|
+
const resolved = await withCadKernel((cad) => resolveRetainedFaceDraft(cad, {
|
|
576
|
+
existing,
|
|
577
|
+
source: existing,
|
|
578
|
+
request: requestedFaceDraft,
|
|
579
|
+
profileChanged: false,
|
|
580
|
+
}, (kernel, shape) => orientedSolidForShape(kernel, unmirroredDraftSource(shape))));
|
|
581
|
+
const retained = retainedFaceDraftFields(existing.faceIds, existing, resolved, requestedFaceDraft);
|
|
582
|
+
recipeFaceDraft = retained.faceDraft;
|
|
583
|
+
recipeFaceDraftSourceFaceIds = retained.faceDraftSourceFaceIds;
|
|
584
|
+
recipeFaceDraftSourceSegmentId = retained.faceDraftSourceSegmentId;
|
|
585
|
+
recipeFaceDraftSourceFrame = retained.faceDraftSourceFrame;
|
|
586
|
+
}
|
|
587
|
+
catch (error) {
|
|
588
|
+
return failed({ reason: "sweep_failed", message: error instanceof Error ? error.message : "The selected face could not be resolved." });
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
const recipe = {
|
|
593
|
+
...existing,
|
|
594
|
+
...(replacingSketchProfile ? { sketchProfile: changes.sketchProfile } : {}),
|
|
595
|
+
...(draftPrismChanged ? { draftPrismAngle: requestedDraftPrismAngle } : {}),
|
|
596
|
+
...(faceDraftChanged ? { faceDraft: recipeFaceDraft } : {}),
|
|
597
|
+
...(faceDraftChanged ? {
|
|
598
|
+
faceDraftSourceFaceIds: recipeFaceDraftSourceFaceIds,
|
|
599
|
+
faceDraftSourceSegmentId: recipeFaceDraftSourceSegmentId,
|
|
600
|
+
faceDraftSourceFrame: !recipeFaceDraft && existing.faceDraft
|
|
601
|
+
? existing.faceDraftSourceFrame
|
|
602
|
+
: recipeFaceDraftSourceFrame,
|
|
603
|
+
} : {}),
|
|
604
|
+
...(isRevolveShape(existing) && REVOLVE_CHANGE_FIELDS.some((field) => changes[field] !== undefined)
|
|
605
|
+
? { sketchRevolve: requestedRevolveSettings(existing.sketchRevolve, changes) }
|
|
606
|
+
: {}),
|
|
607
|
+
};
|
|
608
|
+
const candidate = replaceSketchOutput(document.shapes, shapeId, recipe);
|
|
609
|
+
if (candidate.matchCount !== 1) {
|
|
610
|
+
return failed({ reason: "sweep_failed", message: `Sketch source ${shapeId} has no unique output node.` });
|
|
611
|
+
}
|
|
612
|
+
const recomputed = await recompute({ ...document, shapes: candidate.shapes }, [shapeId], document);
|
|
613
|
+
if (!recomputed.ok)
|
|
614
|
+
return failed({ reason: "sweep_failed", message: recomputed.message ?? "The sketch source could not be recomputed." });
|
|
615
|
+
return ok({ shape: recomputed.updated, revision: await writeShapes(projectId, document, recomputed.shapes) });
|
|
616
|
+
}
|
|
630
617
|
const sweptShape = isRevolveShape(existing);
|
|
631
618
|
const misplaced = REVOLVE_ONLY_FIELDS.filter((field) => changes[field] !== undefined);
|
|
632
619
|
if (!sweptShape && misplaced.length > 0) {
|
|
@@ -639,10 +626,29 @@ export function createEngine(store) {
|
|
|
639
626
|
let swept = existing;
|
|
640
627
|
if ((replacingSketchProfile && isSketchExtrusion) || (draftPrismChanged && isSketchExtrusion)
|
|
641
628
|
|| (faceDraftChanged && isSketchExtrusion)) {
|
|
629
|
+
// A treatment is built from the extrusion at the size it was shown
|
|
630
|
+
// (#539), and its record keeps that shape as `before`. Replaying it on
|
|
631
|
+
// a new profile rebuilds at that same resize, or the edit would hand
|
|
632
|
+
// back the treatment at the size the sketch was first drawn.
|
|
633
|
+
const treatmentSource = existing.edgeTreatmentHistory?.[0]?.before;
|
|
634
|
+
const recordedTreatmentScale = hasExistingTreatment && !existing.faceDraft && existing.draftPrismAngle === undefined
|
|
635
|
+
&& treatmentSource?.sketchOperation === "extrude" && treatmentSource.cadBrep
|
|
636
|
+
? sketchResizeFactors(treatmentSource)
|
|
637
|
+
: undefined;
|
|
638
|
+
// A treatment recorded before #539 kept the resize in `before` but was
|
|
639
|
+
// built, and stored, at the drawn size. Its shape is nearer that drawn
|
|
640
|
+
// size than the resized one on every resized axis, and its edit keeps
|
|
641
|
+
// the old behaviour: rebuilt at the profile's own size.
|
|
642
|
+
const nearerResized = (current, resized, factor) => Math.abs(factor - 1) < 1e-8 || Math.abs(current - resized) < Math.abs(current - resized / factor);
|
|
643
|
+
const treatmentSourceScale = recordedTreatmentScale && treatmentSource
|
|
644
|
+
&& nearerResized(existing.width, treatmentSource.width, recordedTreatmentScale.width)
|
|
645
|
+
&& nearerResized(existing.depth, treatmentSource.depth, recordedTreatmentScale.depth)
|
|
646
|
+
&& nearerResized(existing.height, treatmentSource.height, recordedTreatmentScale.height)
|
|
647
|
+
? recordedTreatmentScale
|
|
648
|
+
: undefined;
|
|
642
649
|
const sourceFrame = existing.faceDraftSourceFrame ?? existing.draftPrismSourceFrame ?? existing.cadBrepFrame;
|
|
643
|
-
const sourceHeight = existing.draftPrismSourceHeight ?? existing.faceDraftSourceFrame?.height ?? existing.height;
|
|
644
650
|
const ratio = (drawn, source) => source && source > 0 && drawn > 0 ? drawn / source : 1;
|
|
645
|
-
const
|
|
651
|
+
const recordedFaceDraftScale = (existing.faceDraft ? existing.faceDraftSourceScale : undefined) ?? (existing.faceDraft ? {
|
|
646
652
|
// Editor-written drafts predate this field. Their output bounds
|
|
647
653
|
// include the taper, so they cannot be used to infer the source
|
|
648
654
|
// resize ratio; these shapes were only retained before resize support.
|
|
@@ -652,7 +658,21 @@ export function createEngine(store) {
|
|
|
652
658
|
depth: ratio(existing.depth, sourceFrame?.depth ?? existing.importedMesh?.baseDepth),
|
|
653
659
|
height: ratio(existing.height, sourceFrame?.height ?? existing.importedMesh?.baseHeight),
|
|
654
660
|
});
|
|
655
|
-
|
|
661
|
+
// Height is unchanged by face drafting, so a later dimension edit can
|
|
662
|
+
// be composed with the original scale without trying to infer scale
|
|
663
|
+
// from the tapered width/depth bounds.
|
|
664
|
+
const faceDraftSourceScale = existing.faceDraft && sourceFrame
|
|
665
|
+
? { ...recordedFaceDraftScale, height: ratio(existing.height, sourceFrame.height) }
|
|
666
|
+
: recordedFaceDraftScale;
|
|
667
|
+
const rebuildScale = existing.faceDraft || faceDraftChanged
|
|
668
|
+
? faceDraftSourceScale
|
|
669
|
+
: treatmentSourceScale ?? { width: 1, depth: 1, height: 1 };
|
|
670
|
+
// The extrusion is rebuilt at the height it was drawn and then scaled
|
|
671
|
+
// by `rebuildScale`, as its width is. Rebuilding a height-resized
|
|
672
|
+
// extrusion at its shown height applied that resize twice (#546).
|
|
673
|
+
const sourceHeight = existing.draftPrismSourceHeight ?? existing.faceDraftSourceFrame?.height
|
|
674
|
+
?? (treatmentSourceScale ? treatmentSource.height / treatmentSourceScale.height
|
|
675
|
+
: existing.height / rebuildScale.height);
|
|
656
676
|
try {
|
|
657
677
|
const rebuilt = await sketchExtrusionShapeFromRequest({
|
|
658
678
|
id: existing.id,
|
|
@@ -669,7 +689,7 @@ export function createEngine(store) {
|
|
|
669
689
|
rotationX: existing.rotationX,
|
|
670
690
|
rotationZ: existing.rotationZ,
|
|
671
691
|
});
|
|
672
|
-
const { faceIds: _oldFaceIds, faceColors: _faceColors, edgeTreatments: _edgeTreatments, edgeTreatmentHistory: _edgeTreatmentHistory, cadDisplayEdges: _cadDisplayEdges, cadDisplayEdgesVersion: _cadDisplayEdgesVersion, ...sourceMetadata } = existing;
|
|
692
|
+
const { faceIds: _oldFaceIds, faceColors: _faceColors, edgeTreatments: _edgeTreatments, edgeTreatmentHistory: _edgeTreatmentHistory, faceDraft: _faceDraft, cadDisplayEdges: _cadDisplayEdges, cadDisplayEdgesVersion: _cadDisplayEdgesVersion, ...sourceMetadata } = existing;
|
|
673
693
|
const draftPrismAngle = draftPrismChanged ? requestedDraftPrismAngle : existing.draftPrismAngle;
|
|
674
694
|
const rebuiltSource = {
|
|
675
695
|
...sourceMetadata,
|
|
@@ -678,7 +698,9 @@ export function createEngine(store) {
|
|
|
678
698
|
mirrorY: existing.mirrorY,
|
|
679
699
|
mirrorZ: existing.mirrorZ,
|
|
680
700
|
...retainedDraftSourcePlacement(existing, rebuilt.cadBrepFrame, existing.faceDraft && !hasExistingTreatment ? existing.cadBrepFrame : undefined),
|
|
681
|
-
|
|
701
|
+
// A cleared draft's resize is not kept: the bounds carry it from here.
|
|
702
|
+
faceDraftSourceScale: clearingFaceDraft ? undefined
|
|
703
|
+
: existing.faceDraft || faceDraftChanged ? faceDraftSourceScale : existing.faceDraftSourceScale,
|
|
682
704
|
width: rebuilt.width * rebuildScale.width,
|
|
683
705
|
depth: rebuilt.depth * rebuildScale.depth,
|
|
684
706
|
height: rebuilt.height * rebuildScale.height,
|
|
@@ -1025,6 +1047,23 @@ export function createEngine(store) {
|
|
|
1025
1047
|
const geometryChanged = geometryFields.some((field) => JSON.stringify(existing[field])
|
|
1026
1048
|
!== JSON.stringify(changed.shape[field]));
|
|
1027
1049
|
let updatedShape = changed.shape;
|
|
1050
|
+
if (existing.kind === "mesh" && existing.importedMesh && !existing.cadBrep
|
|
1051
|
+
&& ["rotation", "rotationX", "rotationZ"].some((field) => field in requestedChanges)) {
|
|
1052
|
+
const previousMesh = worldMeshForShape(existing);
|
|
1053
|
+
const mesh = worldMeshForShape(updatedShape);
|
|
1054
|
+
if (previousMesh?.vertices.length && mesh?.vertices.length) {
|
|
1055
|
+
const lowestPointOf = (vertices) => vertices.reduce((lowest, [, y]) => Math.min(lowest, y), Number.POSITIVE_INFINITY);
|
|
1056
|
+
const previousLowestPoint = lowestPointOf(previousMesh.vertices);
|
|
1057
|
+
const lowestPoint = lowestPointOf(mesh.vertices);
|
|
1058
|
+
const targetElevation = typeof requestedChanges.elevation === "number"
|
|
1059
|
+
? requestedChanges.elevation
|
|
1060
|
+
: previousLowestPoint;
|
|
1061
|
+
updatedShape = {
|
|
1062
|
+
...updatedShape,
|
|
1063
|
+
elevation: (updatedShape.elevation ?? 0) + targetElevation - lowestPoint,
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1028
1067
|
if (!replacingSketchProfile && geometryChanged && (existing.faceIds?.length || existing.faceColors)) {
|
|
1029
1068
|
try {
|
|
1030
1069
|
updatedShape = await preserveUnambiguousFaceMetadata(existing, changed.shape);
|
|
@@ -1034,7 +1073,16 @@ export function createEngine(store) {
|
|
|
1034
1073
|
}
|
|
1035
1074
|
}
|
|
1036
1075
|
if (sourceSketchTarget) {
|
|
1037
|
-
const
|
|
1076
|
+
const candidate = replaceSketchOutput(document.shapes, shapeId, updatedShape);
|
|
1077
|
+
if (candidate.matchCount !== 1) {
|
|
1078
|
+
return failed({
|
|
1079
|
+
reason: "sweep_failed",
|
|
1080
|
+
message: candidate.matchCount === 0
|
|
1081
|
+
? `Sketch source ${shapeId} has no output node.`
|
|
1082
|
+
: `Sketch source ${shapeId} has multiple output nodes.`,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
const recomputed = await recompute({ ...document, shapes: candidate.shapes }, [shapeId], document);
|
|
1038
1086
|
if (!recomputed.ok) {
|
|
1039
1087
|
return failed({
|
|
1040
1088
|
reason: "sweep_failed",
|
|
@@ -1161,8 +1209,8 @@ export function createEngine(store) {
|
|
|
1161
1209
|
const { revision } = await store.write(projectId, { ...document, assets }, shapes);
|
|
1162
1210
|
return ok({ shape: imported.shape, revision });
|
|
1163
1211
|
}),
|
|
1164
|
-
cut: (projectId, request) => combine(projectId, [...request.solidIds, ...request.holeIds], new Set(request.holeIds)),
|
|
1165
|
-
group: (projectId, ids) => combine(projectId, ids, undefined),
|
|
1212
|
+
cut: (projectId, request) => combine(projectId, [...request.solidIds, ...request.holeIds], new Set(request.holeIds), request),
|
|
1213
|
+
group: (projectId, ids, result) => combine(projectId, ids, undefined, result),
|
|
1166
1214
|
ungroup: (projectId, shapeId) => mutating(projectId, async (document) => {
|
|
1167
1215
|
const found = oneShape(document, shapeId);
|
|
1168
1216
|
if (!found.ok)
|
|
@@ -1286,45 +1334,54 @@ export function createEngine(store) {
|
|
|
1286
1334
|
return failed(cadFailure(error));
|
|
1287
1335
|
}
|
|
1288
1336
|
}),
|
|
1289
|
-
treat: (projectId, shapeId,
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1337
|
+
treat: (projectId, shapeId, requested) => {
|
|
1338
|
+
// An edge named twice is one edge: rounding it once is what the caller
|
|
1339
|
+
// gets, so it is counted, and recorded, once.
|
|
1340
|
+
const treatment = requested.edges ? { ...requested, edges: [...new Set(requested.edges)] } : requested;
|
|
1341
|
+
return cadTreatment(projectId, shapeId, (treatment.edges === undefined || treatment.edges.length === 0)
|
|
1342
|
+
&& treatment.kind === "chamfer" && (treatment.angle === undefined || Math.abs(treatment.angle - 45) < 0.001)
|
|
1343
|
+
? "all-edge-chamfer-treatment"
|
|
1344
|
+
: (treatment.edges === undefined || treatment.edges.length === 0)
|
|
1345
|
+
&& treatment.kind === "fillet"
|
|
1346
|
+
? "all-edge-treatment"
|
|
1347
|
+
: "edge-treatment", async (shape) => {
|
|
1348
|
+
const treated = shapeWithCadResult(shape, await applyEdgeTreatment(shape, treatment));
|
|
1349
|
+
// Every treatment is recorded, as the editor records its own. A source
|
|
1350
|
+
// edit rebuilds the solid from the sketch and replays this record; with
|
|
1351
|
+
// no record it rebuilt a bare solid and silently dropped the treatment.
|
|
1352
|
+
// Selected edges are recorded by sketch lineage -- segment and cap --
|
|
1353
|
+
// when every one of them has exactly one, never by their transient
|
|
1354
|
+
// indexes (#350). A selected-edge record without lineage cannot be
|
|
1355
|
+
// replayed, so a later source edit is refused rather than lossy.
|
|
1356
|
+
const allEdges = treatment.edges === undefined || treatment.edges.length === 0;
|
|
1357
|
+
const lineage = allEdges ? undefined : await sketchSourceEdgesForEdgeIndexes(shape, treatment.edges);
|
|
1358
|
+
const feature = {
|
|
1359
|
+
kind: treatment.kind,
|
|
1360
|
+
amount: treatment.amount,
|
|
1361
|
+
edgeCount: allEdges ? await allEdgeTreatmentEdgeCount(shape, treatment.kind) : treatment.edges.length,
|
|
1362
|
+
...(allEdges ? { allEdges: true } : {}),
|
|
1363
|
+
...(treatment.kind === "chamfer" ? { chamferAngle: treatment.angle ?? 45 } : {}),
|
|
1364
|
+
...(lineage?.status === "matched" ? { sourceEdges: lineage.sourceEdges } : {}),
|
|
1365
|
+
};
|
|
1366
|
+
// The snapshot drops its own history, as the editor's does, so each
|
|
1367
|
+
// treatment does not nest a copy of every earlier one.
|
|
1368
|
+
const { edgeTreatmentHistory: _ownHistory, ...before } = shape;
|
|
1369
|
+
return {
|
|
1370
|
+
...treated,
|
|
1371
|
+
edgeTreatments: [...(shape.edgeTreatments ?? []), feature],
|
|
1372
|
+
edgeTreatmentHistory: [
|
|
1373
|
+
...(shape.edgeTreatmentHistory ?? []),
|
|
1374
|
+
{
|
|
1375
|
+
id: createLocalId("edge-history"),
|
|
1376
|
+
createdAt: Date.now(),
|
|
1377
|
+
feature,
|
|
1378
|
+
before: structuredClone(before),
|
|
1379
|
+
appliedFrame: edgeTreatmentAppliedFrame(treated),
|
|
1380
|
+
},
|
|
1381
|
+
],
|
|
1382
|
+
};
|
|
1383
|
+
});
|
|
1384
|
+
},
|
|
1328
1385
|
draftPrism: (projectId, shapeId, angle) => cadTreatment(projectId, shapeId, "prism-draft", async (shape) => ({
|
|
1329
1386
|
...retainDraftSourceMirrors(shapeWithCadResult(shape, await applyDraftPrism(shape, { angle })), shape),
|
|
1330
1387
|
...retainedPrismDraftFields(shape, angle),
|