fluidcad 0.0.12 → 0.0.14

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.
Files changed (32) hide show
  1. package/lib/dist/common/scene-object.d.ts +2 -2
  2. package/lib/dist/common/scene-object.js +2 -3
  3. package/lib/dist/features/2d/sketch.d.ts +3 -3
  4. package/lib/dist/features/2d/sketch.js +12 -6
  5. package/lib/dist/features/extrude-base.d.ts +11 -0
  6. package/lib/dist/features/extrude-base.js +19 -8
  7. package/lib/dist/features/extrude-to-face.d.ts +10 -2
  8. package/lib/dist/features/extrude-to-face.js +4 -4
  9. package/lib/dist/features/extrude-two-distances.d.ts +9 -2
  10. package/lib/dist/features/extrude-two-distances.js +4 -4
  11. package/lib/dist/features/extrude.d.ts +9 -2
  12. package/lib/dist/features/extrude.js +9 -9
  13. package/lib/dist/features/infinite-extrude.d.ts +3 -1
  14. package/lib/dist/features/infinite-extrude.js +11 -5
  15. package/lib/dist/features/revolve.d.ts +9 -2
  16. package/lib/dist/features/revolve.js +1 -4
  17. package/lib/dist/features/sweep.d.ts +9 -2
  18. package/lib/dist/features/sweep.js +1 -4
  19. package/lib/dist/rendering/render.js +4 -2
  20. package/lib/dist/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/server/dist/index.js +25 -15
  23. package/server/dist/preferences.d.ts +5 -0
  24. package/server/dist/preferences.js +36 -0
  25. package/server/dist/routes/actions.js +12 -0
  26. package/server/dist/routes/preferences.d.ts +2 -0
  27. package/server/dist/routes/preferences.js +29 -0
  28. package/server/dist/ws-protocol.d.ts +8 -1
  29. package/ui/dist/assets/index-BpvgjPLm.css +2 -0
  30. package/ui/dist/assets/{index-qqJ_mWi7.js → index-mLcpjEcV.js} +117 -62
  31. package/ui/dist/index.html +3 -3
  32. package/ui/dist/assets/index-DXW2yo2v.css +0 -2
@@ -12,7 +12,7 @@ export interface Comparable<T> {
12
12
  compareTo(other: T): boolean;
13
13
  }
14
14
  export interface Serializable {
15
- serialize(): any;
15
+ serialize(scope?: Set<SceneObject>): any;
16
16
  }
17
17
  export type BuildSceneObjectContext = {
18
18
  getSceneObjects(): SceneObject[];
@@ -51,7 +51,7 @@ export declare abstract class SceneObject implements Comparable<SceneObject>, Se
51
51
  isContainer(): boolean;
52
52
  saveShapesSnapshot(context: BuildSceneObjectContext): void;
53
53
  getSnapshot(): Map<SceneObject, Shape[]>;
54
- abstract serialize(): any;
54
+ abstract serialize(scope?: Set<SceneObject>): any;
55
55
  abstract getType(): string;
56
56
  abstract build(context?: BuildSceneObjectContext): void;
57
57
  compareTo(other: SceneObject): boolean;
@@ -7,7 +7,7 @@ export class SceneObject {
7
7
  _transform = null;
8
8
  _parent = null;
9
9
  _alwaysVisible = false;
10
- _name = '';
10
+ _name = null;
11
11
  _guide = false;
12
12
  _sourceLocation = null;
13
13
  _error = null;
@@ -19,7 +19,6 @@ export class SceneObject {
19
19
  this.state.set('addedShapes', []);
20
20
  this.state.set('removedShapes', []);
21
21
  this._id = randomUUID().toString();
22
- this._name = this.getType();
23
22
  }
24
23
  get id() {
25
24
  return this._id;
@@ -287,7 +286,7 @@ export class SceneObject {
287
286
  return this._order;
288
287
  }
289
288
  getName() {
290
- return this._name;
289
+ return this._name ?? this.getType();
291
290
  }
292
291
  name(value) {
293
292
  this._name = value;
@@ -14,7 +14,7 @@ export declare class Sketch extends SceneObject implements Extrudable {
14
14
  getStartPoint(): Point2D;
15
15
  getTangentAt(currentObj: GeometrySceneObject): Point2D | null;
16
16
  getPositionAt(currentObj: GeometrySceneObject): Point2D;
17
- getLastPosition(): Point2D;
17
+ getLastPosition(scope?: Set<SceneObject>): Point2D;
18
18
  build(): void;
19
19
  getEdges(): Edge[];
20
20
  getEdgesWithOwner(): Map<Edge, GeometrySceneObject>;
@@ -23,9 +23,9 @@ export declare class Sketch extends SceneObject implements Extrudable {
23
23
  getDependencies(): SceneObject[];
24
24
  createCopy(remap: Map<SceneObject, SceneObject>): SceneObject;
25
25
  compareTo(other: Sketch): boolean;
26
- getTangent(): Point2D | null;
26
+ getTangent(scope?: Set<SceneObject>): Point2D | null;
27
27
  getType(): string;
28
- serialize(): {
28
+ serialize(scope?: Set<SceneObject>): {
29
29
  currentPosition: import("../../math/point.js").Point;
30
30
  currentTangent: import("../../math/point.js").Point;
31
31
  plane: any;
@@ -57,8 +57,11 @@ export class Sketch extends SceneObject {
57
57
  }
58
58
  return this.getStartPoint();
59
59
  }
60
- getLastPosition() {
61
- const children = this.getChildren().slice();
60
+ getLastPosition(scope) {
61
+ let children = this.getChildren().slice();
62
+ if (scope) {
63
+ children = children.filter(c => scope.has(c));
64
+ }
62
65
  if (children.length === 0) {
63
66
  return this.getStartPoint();
64
67
  }
@@ -132,8 +135,11 @@ export class Sketch extends SceneObject {
132
135
  }
133
136
  return true;
134
137
  }
135
- getTangent() {
138
+ getTangent(scope) {
136
139
  let children = this.getChildren()?.slice();
140
+ if (scope) {
141
+ children = children.filter(c => scope.has(c));
142
+ }
137
143
  if (children.length === 0) {
138
144
  return null;
139
145
  }
@@ -156,11 +162,11 @@ export class Sketch extends SceneObject {
156
162
  getType() {
157
163
  return "sketch";
158
164
  }
159
- serialize() {
165
+ serialize(scope) {
160
166
  const plane = this.getPlane();
161
- const tangent = this.getTangent();
167
+ const tangent = this.getTangent(scope);
162
168
  return {
163
- currentPosition: plane.localToWorld(this.getLastPosition()),
169
+ currentPosition: plane.localToWorld(this.getLastPosition(scope)),
164
170
  currentTangent: tangent ? plane.localToWorld(tangent) : null,
165
171
  plane: this.planeObj.serialize(),
166
172
  };
@@ -35,6 +35,17 @@ export declare abstract class ExtrudeBase extends SceneObject implements IExtrud
35
35
  draft(value: number | [number, number]): this;
36
36
  endOffset(value: number): this;
37
37
  drill(value?: boolean): this;
38
+ protected serializePickFields(): {
39
+ picking: true;
40
+ pickPoints: number[][];
41
+ trigger: "region-picking";
42
+ pickPlane: {
43
+ origin: import("../math/point.js").Point;
44
+ xDirection: import("../math/vector3d.js").Vector3d;
45
+ yDirection: import("../math/vector3d.js").Vector3d;
46
+ normal: import("../math/vector3d.js").Vector3d;
47
+ };
48
+ };
38
49
  pick(...points: Point2DLike[]): this;
39
50
  isPicking(): boolean;
40
51
  getPickPoints(): LazyVertex[];
@@ -198,6 +198,22 @@ export class ExtrudeBase extends SceneObject {
198
198
  this._drill = value;
199
199
  return this;
200
200
  }
201
+ serializePickFields() {
202
+ const plane = this._extrudable?.getPlane();
203
+ return {
204
+ picking: this.isPicking() || undefined,
205
+ pickPoints: this.isPicking()
206
+ ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
207
+ : undefined,
208
+ trigger: 'region-picking',
209
+ pickPlane: plane ? {
210
+ origin: plane.origin,
211
+ xDirection: plane.xDirection,
212
+ yDirection: plane.yDirection,
213
+ normal: plane.normal,
214
+ } : undefined,
215
+ };
216
+ }
201
217
  pick(...points) {
202
218
  this._picking = true;
203
219
  this._pickPoints = points.map(p => normalizePoint2D(p));
@@ -219,13 +235,8 @@ export class ExtrudeBase extends SceneObject {
219
235
  if (!this.isPicking()) {
220
236
  return null;
221
237
  }
222
- let cells = this.extrudable.getState('pick-region-cells');
223
- if (!cells) {
224
- console.log(':::::::: No cached cells found, computing cells for the first time');
225
- const sketchShapes = this.extrudable.getGeometries();
226
- cells = FaceMaker2.getRegions(sketchShapes, plane, false);
227
- this.extrudable.setState('pick-region-cells', cells);
228
- }
238
+ const sketchShapes = this.extrudable.getGeometries();
239
+ const cells = FaceMaker2.getRegions(sketchShapes, plane, false);
229
240
  if (cells.length === 0) {
230
241
  return [];
231
242
  }
@@ -327,6 +338,6 @@ export class ExtrudeBase extends SceneObject {
327
338
  return true;
328
339
  }
329
340
  getType() {
330
- return "extrude";
341
+ return this._operationMode === "remove" ? "cut" : "extrude";
331
342
  }
332
343
  }
@@ -1,6 +1,7 @@
1
1
  import { BuildSceneObjectContext, SceneObject } from "../common/scene-object.js";
2
2
  import { ExtrudeBase } from "./extrude-base.js";
3
3
  import { Extrudable } from "../helpers/types.js";
4
+ import { Point } from "../math/point.js";
4
5
  export declare class ExtrudeToFace extends ExtrudeBase {
5
6
  face: SceneObject | 'first-face' | 'last-face';
6
7
  constructor(face: SceneObject | 'first-face' | 'last-face', extrudable?: Extrudable);
@@ -24,12 +25,19 @@ export declare class ExtrudeToFace extends ExtrudeBase {
24
25
  compareTo(other: ExtrudeToFace): boolean;
25
26
  getUniqueType(): string;
26
27
  serialize(): {
28
+ picking: true;
29
+ pickPoints: number[][];
30
+ trigger: "region-picking";
31
+ pickPlane: {
32
+ origin: Point;
33
+ xDirection: import("../math/vector3d.js").Vector3d;
34
+ yDirection: import("../math/vector3d.js").Vector3d;
35
+ normal: import("../math/vector3d.js").Vector3d;
36
+ };
27
37
  sheptType: string;
28
38
  extrudable: any;
29
39
  draft: [number, number];
30
40
  endOffset: number;
31
41
  face: string;
32
- picking: true;
33
- pickPoints: number[][];
34
42
  };
35
43
  }
@@ -257,6 +257,9 @@ export class ExtrudeToFace extends ExtrudeBase {
257
257
  return true;
258
258
  }
259
259
  getUniqueType() {
260
+ if (this._operationMode === 'remove') {
261
+ return 'cut';
262
+ }
260
263
  return 'extrude-to-face';
261
264
  }
262
265
  serialize() {
@@ -266,10 +269,7 @@ export class ExtrudeToFace extends ExtrudeBase {
266
269
  draft: this.getDraft(),
267
270
  endOffset: this.getEndOffset(),
268
271
  face: typeof (this.face) === 'string' ? this.face : 'selection',
269
- picking: this.isPicking() || undefined,
270
- pickPoints: this.isPicking()
271
- ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
272
- : undefined,
272
+ ...this.serializePickFields(),
273
273
  };
274
274
  }
275
275
  }
@@ -11,11 +11,18 @@ export declare class ExtrudeTwoDistances extends ExtrudeBase {
11
11
  compareTo(other: ExtrudeTwoDistances): boolean;
12
12
  getUniqueType(): string;
13
13
  serialize(): {
14
+ picking: true;
15
+ pickPoints: number[][];
16
+ trigger: "region-picking";
17
+ pickPlane: {
18
+ origin: import("../math/point.js").Point;
19
+ xDirection: import("../math/vector3d.js").Vector3d;
20
+ yDirection: import("../math/vector3d.js").Vector3d;
21
+ normal: import("../math/vector3d.js").Vector3d;
22
+ };
14
23
  extrudable: any;
15
24
  distance1: number;
16
25
  distance2: number;
17
26
  operationMode: "new" | "remove";
18
- picking: true;
19
- pickPoints: number[][];
20
27
  };
21
28
  }
@@ -99,6 +99,9 @@ export class ExtrudeTwoDistances extends ExtrudeBase {
99
99
  return true;
100
100
  }
101
101
  getUniqueType() {
102
+ if (this._operationMode === 'remove') {
103
+ return 'cut';
104
+ }
102
105
  return 'extrude-by-two-distance';
103
106
  }
104
107
  serialize() {
@@ -107,10 +110,7 @@ export class ExtrudeTwoDistances extends ExtrudeBase {
107
110
  distance1: this.distance1,
108
111
  distance2: this.distance2,
109
112
  operationMode: this._operationMode !== 'add' ? this._operationMode : undefined,
110
- picking: this.isPicking() || undefined,
111
- pickPoints: this.isPicking()
112
- ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
113
- : undefined,
113
+ ...this.serializePickFields(),
114
114
  };
115
115
  }
116
116
  }
@@ -13,13 +13,20 @@ export declare class Extrude extends ExtrudeBase {
13
13
  compareTo(other: Extrude): boolean;
14
14
  getUniqueType(): string;
15
15
  serialize(): {
16
+ picking: true;
17
+ pickPoints: number[][];
18
+ trigger: "region-picking";
19
+ pickPlane: {
20
+ origin: import("../math/point.js").Point;
21
+ xDirection: import("../math/vector3d.js").Vector3d;
22
+ yDirection: import("../math/vector3d.js").Vector3d;
23
+ normal: import("../math/vector3d.js").Vector3d;
24
+ };
16
25
  extrudable: any;
17
26
  distance: number;
18
27
  operationMode: "new" | "remove";
19
28
  symmetric: true;
20
29
  draft: [number, number];
21
30
  endOffset: number;
22
- picking: true;
23
- pickPoints: number[][];
24
31
  };
25
32
  }
@@ -107,7 +107,7 @@ export class Extrude extends ExtrudeBase {
107
107
  if (this._symmetric) {
108
108
  // Symmetric cut: create tool centered on sketch plane
109
109
  if (isThroughAll) {
110
- const extrudeThroughAll = new ExtrudeThroughAll(this.extrudable, true, true);
110
+ const extrudeThroughAll = new ExtrudeThroughAll(this.extrudable, true, true, faces);
111
111
  toolShapes = extrudeThroughAll.build();
112
112
  }
113
113
  else {
@@ -121,7 +121,7 @@ export class Extrude extends ExtrudeBase {
121
121
  }
122
122
  }
123
123
  else if (isThroughAll) {
124
- const extrudeThroughAll = new ExtrudeThroughAll(this.extrudable, false, true);
124
+ const extrudeThroughAll = new ExtrudeThroughAll(this.extrudable, false, true, faces);
125
125
  toolShapes = extrudeThroughAll.build();
126
126
  }
127
127
  else {
@@ -157,12 +157,15 @@ export class Extrude extends ExtrudeBase {
157
157
  return true;
158
158
  }
159
159
  getUniqueType() {
160
+ if (this._operationMode === 'remove') {
161
+ if (this._symmetric) {
162
+ return 'cut-symmetric';
163
+ }
164
+ return 'cut';
165
+ }
160
166
  if (this._symmetric) {
161
167
  return 'extrude-symmetric';
162
168
  }
163
- if (this._operationMode === 'remove') {
164
- return 'cut-by-distance';
165
- }
166
169
  return 'extrude-by-distance';
167
170
  }
168
171
  serialize() {
@@ -173,10 +176,7 @@ export class Extrude extends ExtrudeBase {
173
176
  symmetric: this._symmetric || undefined,
174
177
  draft: this.getDraft(),
175
178
  endOffset: this.getEndOffset(),
176
- picking: this.isPicking() || undefined,
177
- pickPoints: this.isPicking()
178
- ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
179
- : undefined,
179
+ ...this.serializePickFields(),
180
180
  };
181
181
  }
182
182
  }
@@ -1,10 +1,12 @@
1
1
  import { Solid } from "../common/shapes.js";
2
+ import { Face } from "../common/face.js";
2
3
  import { Extrudable } from "../helpers/types.js";
3
4
  export declare class ExtrudeThroughAll {
4
5
  extrudable: Extrudable;
5
6
  symmetric: boolean;
6
7
  reversed: boolean;
8
+ pickedFaces?: Face[];
7
9
  private shapes;
8
- constructor(extrudable: Extrudable, symmetric: boolean, reversed: boolean);
10
+ constructor(extrudable: Extrudable, symmetric: boolean, reversed: boolean, pickedFaces?: Face[]);
9
11
  build(): Solid[];
10
12
  }
@@ -4,30 +4,34 @@ export class ExtrudeThroughAll {
4
4
  extrudable;
5
5
  symmetric;
6
6
  reversed;
7
+ pickedFaces;
7
8
  shapes = null;
8
- constructor(extrudable, symmetric, reversed) {
9
+ constructor(extrudable, symmetric, reversed, pickedFaces) {
9
10
  this.extrudable = extrudable;
10
11
  this.symmetric = symmetric;
11
12
  this.reversed = reversed;
13
+ this.pickedFaces = pickedFaces;
12
14
  }
13
15
  build() {
14
16
  if (this.shapes) {
15
17
  return this.shapes;
16
18
  }
17
19
  const solids = [];
18
- const wires = this.extrudable.getGeometries();
19
20
  const plane = this.extrudable.getPlane();
20
- const faces = FaceMaker2.getRegions(wires, plane);
21
+ const faces = this.pickedFaces ?? FaceMaker2.getRegions(this.extrudable.getGeometries(), plane);
21
22
  console.log("Extruding faces:", faces);
22
23
  let dir = plane.normal;
23
24
  if (this.reversed) {
24
25
  dir = dir.multiply(-1);
25
26
  }
27
+ const shouldDispose = !this.pickedFaces;
26
28
  if (this.symmetric) {
27
29
  for (const face of faces) {
28
30
  const solid = ExtrudeOps.makePrismSymmetric(face, dir);
29
31
  solids.push(solid);
30
- face.dispose();
32
+ if (shouldDispose) {
33
+ face.dispose();
34
+ }
31
35
  }
32
36
  }
33
37
  else {
@@ -35,7 +39,9 @@ export class ExtrudeThroughAll {
35
39
  for (const face of faces) {
36
40
  const solid = ExtrudeOps.makePrism(face, dir, 1);
37
41
  solids.push(solid);
38
- face.dispose();
42
+ if (shouldDispose) {
43
+ face.dispose();
44
+ }
39
45
  }
40
46
  }
41
47
  this.shapes = solids;
@@ -13,11 +13,18 @@ export declare class Revolve extends ExtrudeBase implements IRevolve {
13
13
  compareTo(other: Revolve): boolean;
14
14
  getType(): string;
15
15
  serialize(): {
16
+ picking: true;
17
+ pickPoints: number[][];
18
+ trigger: "region-picking";
19
+ pickPlane: {
20
+ origin: import("../math/point.js").Point;
21
+ xDirection: import("../math/vector3d.js").Vector3d;
22
+ yDirection: import("../math/vector3d.js").Vector3d;
23
+ normal: import("../math/vector3d.js").Vector3d;
24
+ };
16
25
  angle: number;
17
26
  axis: any;
18
27
  operationMode: "new" | "remove";
19
28
  symmetric: true;
20
- picking: true;
21
- pickPoints: number[][];
22
29
  };
23
30
  }
@@ -141,10 +141,7 @@ export class Revolve extends ExtrudeBase {
141
141
  axis: this.axis.serialize(),
142
142
  operationMode: this._operationMode !== 'add' ? this._operationMode : undefined,
143
143
  symmetric: this._symmetric || undefined,
144
- picking: this.isPicking() || undefined,
145
- pickPoints: this.isPicking()
146
- ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
147
- : undefined,
144
+ ...this.serializePickFields(),
148
145
  };
149
146
  }
150
147
  }
@@ -13,10 +13,17 @@ export declare class Sweep extends ExtrudeBase implements ISweep {
13
13
  compareTo(other: Sweep): boolean;
14
14
  getType(): string;
15
15
  serialize(): {
16
+ picking: true;
17
+ pickPoints: number[][];
18
+ trigger: "region-picking";
19
+ pickPlane: {
20
+ origin: import("../math/point.js").Point;
21
+ xDirection: import("../math/vector3d.js").Vector3d;
22
+ yDirection: import("../math/vector3d.js").Vector3d;
23
+ normal: import("../math/vector3d.js").Vector3d;
24
+ };
16
25
  path: any;
17
26
  extrudable: any;
18
27
  operationMode: "new" | "remove";
19
- picking: true;
20
- pickPoints: number[][];
21
28
  };
22
29
  }
@@ -120,10 +120,7 @@ export class Sweep extends ExtrudeBase {
120
120
  path: this._path.serialize(),
121
121
  extrudable: this.extrudable.serialize(),
122
122
  operationMode: this._operationMode !== 'add' ? this._operationMode : undefined,
123
- picking: this.isPicking() || undefined,
124
- pickPoints: this.isPicking()
125
- ? this._pickPoints.map(p => { const pt = p.asPoint2D(); return [pt.x, pt.y]; })
126
- : undefined,
123
+ ...this.serializePickFields(),
127
124
  };
128
125
  }
129
126
  }
@@ -78,6 +78,8 @@ export function renderSceneRollback(scene, rollbackIndex) {
78
78
  shapeType: shape.getType(),
79
79
  isMetaShape: shape.isMetaShape() || undefined,
80
80
  isGuide: shape.isGuideShape() || undefined,
81
+ metaType: shape.metaType || undefined,
82
+ metaData: shape.metaData || undefined,
81
83
  });
82
84
  }
83
85
  let isVisible = !!sceneShapes.length;
@@ -97,7 +99,7 @@ export function renderSceneRollback(scene, rollbackIndex) {
97
99
  id: obj.id,
98
100
  name: obj.getName(),
99
101
  parentId: obj.parentId,
100
- object: obj.serialize(),
102
+ object: obj.serialize(scope),
101
103
  sceneShapes: renderedSceneShapes,
102
104
  type: obj.getType(),
103
105
  uniqueType: obj.getUniqueType(),
@@ -113,7 +115,7 @@ export function renderSceneRollback(scene, rollbackIndex) {
113
115
  id: obj.id,
114
116
  name: obj.getName(),
115
117
  parentId: obj.parentId,
116
- object: obj.serialize(),
118
+ object: obj.serialize(scope),
117
119
  sceneShapes: [],
118
120
  type: obj.getType(),
119
121
  uniqueType: obj.getUniqueType(),