@code3d/core 0.0.1-alpha.0 → 0.0.1-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -807
- package/THIRD_PARTY.md +40 -0
- package/bld/THIRD_PARTY_NOTICES.txt +182 -0
- package/bld/chunks/chunk-7FIFPADJ.js +1 -0
- package/bld/chunks/chunk-7FIFPADJ.js.map +7 -0
- package/bld/chunks/chunk-CL3E2DE4.js +19 -0
- package/bld/chunks/chunk-CL3E2DE4.js.map +7 -0
- package/bld/chunks/chunk-HZRQUHM2.js +30 -0
- package/bld/chunks/chunk-HZRQUHM2.js.map +7 -0
- package/bld/chunks/chunk-JBVIAMJ6.js +26474 -0
- package/bld/chunks/chunk-JBVIAMJ6.js.map +7 -0
- package/bld/chunks/chunk-QK6ZET47.js +31 -0
- package/bld/chunks/chunk-QK6ZET47.js.map +7 -0
- package/bld/library/bound-solver.d.ts +29 -5
- package/bld/library/bound-solver.d.ts.map +1 -1
- package/bld/library/cached.d.ts +35 -0
- package/bld/library/cached.d.ts.map +1 -0
- package/bld/library/font.d.ts +39 -0
- package/bld/library/font.d.ts.map +1 -0
- package/bld/library/google-font.d.ts +14 -0
- package/bld/library/google-font.d.ts.map +1 -0
- package/bld/library/index.d.ts +10 -2
- package/bld/library/index.d.ts.map +1 -1
- package/bld/library/index.js +94 -3
- package/bld/library/index.js.map +7 -1
- package/bld/library/inspect.d.ts +100 -0
- package/bld/library/inspect.d.ts.map +1 -0
- package/bld/library/kernel-artifact-codec.d.ts.map +1 -1
- package/bld/library/kernel-cache.d.ts +28 -7
- package/bld/library/kernel-cache.d.ts.map +1 -1
- package/bld/library/loft.d.ts.map +1 -1
- package/bld/library/material.d.ts +1 -1
- package/bld/library/material.d.ts.map +1 -1
- package/bld/library/open-cascade.d.ts +4 -0
- package/bld/library/open-cascade.d.ts.map +1 -0
- package/bld/library/relation-solver.d.ts +19 -8
- package/bld/library/relation-solver.d.ts.map +1 -1
- package/bld/library/replicad.d.ts +3 -2
- package/bld/library/replicad.d.ts.map +1 -1
- package/bld/library/replicad.js +10 -24
- package/bld/library/replicad.js.map +7 -1
- package/bld/library/retained-memory.d.ts.map +1 -1
- package/bld/library/runtime.d.ts +518 -155
- package/bld/library/runtime.d.ts.map +1 -1
- package/bld/library/sketch-solver.d.ts +1 -1
- package/bld/library/sketch-solver.d.ts.map +1 -1
- package/bld/library/sketch.d.ts +21 -1
- package/bld/library/sketch.d.ts.map +1 -1
- package/bld/library/text.d.ts +53 -0
- package/bld/library/text.d.ts.map +1 -0
- package/bld/library/three.js +3 -3
- package/bld/library/three.js.map +7 -1
- package/bld/library/topology.d.ts +6 -2
- package/bld/library/topology.d.ts.map +1 -1
- package/bld/node/index.d.ts.map +1 -1
- package/bld/node/index.js +96 -14
- package/bld/node/index.js.map +7 -1
- package/bld/node/replicad.js +13 -3
- package/bld/node/replicad.js.map +7 -1
- package/bld/tooling/index.d.ts +18 -15
- package/bld/tooling/index.d.ts.map +1 -1
- package/bld/tooling/index.js +165 -19
- package/bld/tooling/index.js.map +7 -1
- package/docs/api.md +764 -0
- package/docs/custom-primitives.mdx +58 -0
- package/docs/local-coordinates.md +187 -0
- package/docs/origins-and-rotation.mdx +105 -0
- package/docs/relations.mdx +450 -0
- package/docs/runtime.md +297 -0
- package/docs/shells.mdx +70 -0
- package/docs/sketches.md +83 -0
- package/docs/text.md +23 -0
- package/docs/topology.md +152 -0
- package/docs/values.md +119 -0
- package/package.json +20 -7
- package/src/library/bound-solver.ts +103 -73
- package/src/library/cached.ts +153 -0
- package/src/library/font.ts +186 -0
- package/src/library/google-font.ts +97 -0
- package/src/library/index.ts +53 -5
- package/src/library/inspect.ts +178 -0
- package/src/library/kernel-artifact-codec.ts +129 -20
- package/src/library/kernel-cache.ts +175 -39
- package/src/library/loft.ts +9 -1
- package/src/library/material.ts +3 -4
- package/src/library/open-cascade.ts +13 -0
- package/src/library/relation-solver.ts +230 -113
- package/src/library/replicad.ts +5 -5
- package/src/library/retained-memory.ts +6 -1
- package/src/library/runtime.ts +3769 -1178
- package/src/library/shell.ts +3 -3
- package/src/library/sketch-solver.ts +3 -1
- package/src/library/sketch.ts +112 -13
- package/src/library/text.ts +477 -0
- package/src/library/topology.ts +61 -17
- package/src/library/tsconfig.json +2 -1
- package/src/node/index.ts +14 -3
- package/src/node/tsconfig.json +2 -1
- package/src/tooling/index.ts +64 -51
- package/src/tooling/tsconfig.json +2 -1
- package/bld/library/alignment-geometry.js +0 -322
- package/bld/library/alignment-geometry.js.map +0 -1
- package/bld/library/bound-solver.js +0 -252
- package/bld/library/bound-solver.js.map +0 -1
- package/bld/library/extrude.js +0 -28
- package/bld/library/extrude.js.map +0 -1
- package/bld/library/kernel-artifact-codec.js +0 -148
- package/bld/library/kernel-artifact-codec.js.map +0 -1
- package/bld/library/kernel-cache.js +0 -245
- package/bld/library/kernel-cache.js.map +0 -1
- package/bld/library/kernel-shapes.js +0 -108
- package/bld/library/kernel-shapes.js.map +0 -1
- package/bld/library/loft.js +0 -161
- package/bld/library/loft.js.map +0 -1
- package/bld/library/material.js +0 -176
- package/bld/library/material.js.map +0 -1
- package/bld/library/model-color.js +0 -36
- package/bld/library/model-color.js.map +0 -1
- package/bld/library/open-cascade-error.js +0 -22
- package/bld/library/open-cascade-error.js.map +0 -1
- package/bld/library/relation-solver.js +0 -258
- package/bld/library/relation-solver.js.map +0 -1
- package/bld/library/retained-memory.js +0 -27
- package/bld/library/retained-memory.js.map +0 -1
- package/bld/library/runtime.js +0 -2954
- package/bld/library/runtime.js.map +0 -1
- package/bld/library/shell.js +0 -221
- package/bld/library/shell.js.map +0 -1
- package/bld/library/sketch-curve-intersections.js +0 -117
- package/bld/library/sketch-curve-intersections.js.map +0 -1
- package/bld/library/sketch-curves.js +0 -89
- package/bld/library/sketch-curves.js.map +0 -1
- package/bld/library/sketch-drag-rules.js +0 -522
- package/bld/library/sketch-drag-rules.js.map +0 -1
- package/bld/library/sketch-face.js +0 -72
- package/bld/library/sketch-face.js.map +0 -1
- package/bld/library/sketch-incidence.js +0 -114
- package/bld/library/sketch-incidence.js.map +0 -1
- package/bld/library/sketch-precision.js +0 -55
- package/bld/library/sketch-precision.js.map +0 -1
- package/bld/library/sketch-regions.js +0 -193
- package/bld/library/sketch-regions.js.map +0 -1
- package/bld/library/sketch-solver.js +0 -578
- package/bld/library/sketch-solver.js.map +0 -1
- package/bld/library/sketch.js +0 -650
- package/bld/library/sketch.js.map +0 -1
- package/bld/library/spatial.js +0 -195
- package/bld/library/spatial.js.map +0 -1
- package/bld/library/topology-id.js +0 -67
- package/bld/library/topology-id.js.map +0 -1
- package/bld/library/topology-inspection.js +0 -267
- package/bld/library/topology-inspection.js.map +0 -1
- package/bld/library/topology.js +0 -455
- package/bld/library/topology.js.map +0 -1
package/src/library/shell.ts
CHANGED
|
@@ -119,7 +119,7 @@ function openShell(
|
|
|
119
119
|
return {
|
|
120
120
|
shape: result,
|
|
121
121
|
topology: transferShapeTopology(
|
|
122
|
-
[{shape, topology,
|
|
122
|
+
[{shape, topology, namespace: 'preserve'}],
|
|
123
123
|
result,
|
|
124
124
|
builder,
|
|
125
125
|
),
|
|
@@ -202,12 +202,12 @@ function closedShell(
|
|
|
202
202
|
} finally {
|
|
203
203
|
shells.delete();
|
|
204
204
|
}
|
|
205
|
-
// Original boundaries retain their
|
|
205
|
+
// Original boundaries retain their IDs for either direction. Offset
|
|
206
206
|
// boundaries are new topology, even when OCCT has generation history.
|
|
207
207
|
return {
|
|
208
208
|
shape: result,
|
|
209
209
|
topology: transferShapeTopology(
|
|
210
|
-
[{shape, topology,
|
|
210
|
+
[{shape, topology, namespace: 'preserve'}],
|
|
211
211
|
result,
|
|
212
212
|
cut,
|
|
213
213
|
),
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {GcsSystem
|
|
1
|
+
import type {GcsSystem} from '@salusoft89/planegcs/dist/planegcs_dist/gcs_system.js';
|
|
2
|
+
// Upstream ships this declaration alongside sources, but omits it from dist.
|
|
3
|
+
import type {ModuleStatic} from '@salusoft89/planegcs/planegcs_dist/planegcs.js';
|
|
2
4
|
import type {SketchArcDirection, SketchPosition} from './sketch.js';
|
|
3
5
|
import {sketchArcGeometry} from './sketch-curves.js';
|
|
4
6
|
import {pointLineDistance} from './sketch-incidence.js';
|
package/src/library/sketch.ts
CHANGED
|
@@ -6,11 +6,16 @@ import {
|
|
|
6
6
|
import {solveSketchDrag} from './sketch-drag-rules.js';
|
|
7
7
|
import {sketchRegions} from './sketch-regions.js';
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
SketchFrame,
|
|
10
|
+
relate,
|
|
10
11
|
disposeModelObjects,
|
|
11
12
|
isModelObject,
|
|
13
|
+
type Relation,
|
|
14
|
+
type FaceAnchor,
|
|
12
15
|
type FaceModel,
|
|
13
16
|
} from './runtime.js';
|
|
17
|
+
import {retainInspectionIdentity} from './inspect.js';
|
|
18
|
+
import type {RigidTransform} from './spatial.js';
|
|
14
19
|
import {
|
|
15
20
|
sketchIncidences,
|
|
16
21
|
sketchIncidencePoints,
|
|
@@ -85,6 +90,16 @@ export type SketchOptions = Readonly<{
|
|
|
85
90
|
|
|
86
91
|
/** An immutable sketch definition, independent of B-Rep construction. */
|
|
87
92
|
export interface Sketch {
|
|
93
|
+
/** The unbounded local XZ plane (+Y normal), independent of closed regions. */
|
|
94
|
+
readonly plane: FaceAnchor;
|
|
95
|
+
/**
|
|
96
|
+
* Relates a new frame without changing this sketch's two-dimensional data.
|
|
97
|
+
* Each constraint must involve callback self; external references keep their identity.
|
|
98
|
+
* @code3d.inspect relate.inspectCall
|
|
99
|
+
* @code3d.inspect.context build relate.inspectContext
|
|
100
|
+
* @code3d.inspect.closure build relate.inspectBody
|
|
101
|
+
*/
|
|
102
|
+
relate(build: (self: Sketch) => Relation | readonly Relation[]): Sketch;
|
|
88
103
|
/** References a point defined in this layer. */
|
|
89
104
|
point(id: number): SketchPoint;
|
|
90
105
|
/** Adds a local layer while retaining the upstream sketch as read-only input. */
|
|
@@ -110,13 +125,31 @@ type Definition = Readonly<{
|
|
|
110
125
|
|
|
111
126
|
const definitions = new WeakMap<Sketch, Definition>();
|
|
112
127
|
const references = new WeakSet<SketchPoint>();
|
|
128
|
+
const framedSketches = new WeakMap<SketchFrame, Sketch>();
|
|
113
129
|
|
|
114
130
|
class SketchValue implements Sketch {
|
|
131
|
+
readonly frame: SketchFrame;
|
|
132
|
+
readonly source?: Sketch;
|
|
133
|
+
|
|
115
134
|
constructor(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
input:
|
|
136
|
+
| {
|
|
137
|
+
entries?: readonly SketchEntry[];
|
|
138
|
+
options?: SketchOptions;
|
|
139
|
+
base?: Sketch;
|
|
140
|
+
}
|
|
141
|
+
| {source: Sketch; frame: SketchFrame},
|
|
119
142
|
) {
|
|
143
|
+
if ('source' in input) {
|
|
144
|
+
this.frame = input.frame;
|
|
145
|
+
framedSketches.set(this.frame, this);
|
|
146
|
+
this.source = input.source;
|
|
147
|
+
definitions.set(this, definitions.get(input.source)!);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const {entries, options, base} = input;
|
|
151
|
+
this.frame = new SketchFrame(base && (base as SketchValue).frame);
|
|
152
|
+
framedSketches.set(this.frame, this);
|
|
120
153
|
const ids = new Set<number>();
|
|
121
154
|
const points = new Map<number, SketchPosition>();
|
|
122
155
|
const copied = (entries ?? []).map<SketchEntry>(entry => {
|
|
@@ -164,6 +197,10 @@ class SketchValue implements Sketch {
|
|
|
164
197
|
ancestor = definitions.get(ancestor)?.base
|
|
165
198
|
)
|
|
166
199
|
ancestors.add(ancestor);
|
|
200
|
+
const ancestorFor = (value: Sketch) =>
|
|
201
|
+
[...ancestors].find(
|
|
202
|
+
ancestor => definitions.get(ancestor) === definitions.get(value),
|
|
203
|
+
);
|
|
167
204
|
for (const [kind, id, data] of copied) {
|
|
168
205
|
if (kind === 'point' && Array.isArray(data)) continue;
|
|
169
206
|
const refs =
|
|
@@ -180,7 +217,7 @@ class SketchValue implements Sketch {
|
|
|
180
217
|
throw new Error(
|
|
181
218
|
`Sketch ${kind} ${id} references missing local point ${ref}.`,
|
|
182
219
|
);
|
|
183
|
-
} else if (!references.has(ref) || !
|
|
220
|
+
} else if (!references.has(ref) || !ancestorFor(ref.sketch)) {
|
|
184
221
|
throw new Error(
|
|
185
222
|
`Sketch ${kind} ${id} must reference a local or upstream point.`,
|
|
186
223
|
);
|
|
@@ -209,7 +246,7 @@ class SketchValue implements Sketch {
|
|
|
209
246
|
if (
|
|
210
247
|
typeof ref === 'number'
|
|
211
248
|
? !points.has(ref)
|
|
212
|
-
: !references.has(ref) || !
|
|
249
|
+
: !references.has(ref) || !ancestorFor(ref.sketch)
|
|
213
250
|
)
|
|
214
251
|
throw new Error(
|
|
215
252
|
'Sketch constraints must reference a local or upstream point.',
|
|
@@ -304,6 +341,7 @@ class SketchValue implements Sketch {
|
|
|
304
341
|
const local = 'local';
|
|
305
342
|
const layers = new Map<Sketch, string>();
|
|
306
343
|
const identity = (value: Sketch) => {
|
|
344
|
+
value = ancestorFor(value) ?? value;
|
|
307
345
|
let id = layers.get(value);
|
|
308
346
|
if (!id) layers.set(value, (id = `upstream:${layers.size}`));
|
|
309
347
|
return id;
|
|
@@ -345,8 +383,21 @@ class SketchValue implements Sketch {
|
|
|
345
383
|
return ref;
|
|
346
384
|
}
|
|
347
385
|
|
|
386
|
+
get plane(): FaceAnchor {
|
|
387
|
+
return this.frame.plane;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
relate(build: (self: Sketch) => Relation | readonly Relation[]): Sketch {
|
|
391
|
+
let related!: SketchValue;
|
|
392
|
+
this.frame.relate(frame => {
|
|
393
|
+
related = new SketchValue({source: this, frame});
|
|
394
|
+
return build(related);
|
|
395
|
+
});
|
|
396
|
+
return related;
|
|
397
|
+
}
|
|
398
|
+
|
|
348
399
|
derive(entries?: readonly SketchEntry[], options?: SketchOptions): Sketch {
|
|
349
|
-
return new SketchValue(entries, options, this);
|
|
400
|
+
return new SketchValue({entries, options, base: this});
|
|
350
401
|
}
|
|
351
402
|
|
|
352
403
|
face(): FaceModel {
|
|
@@ -355,14 +406,14 @@ class SketchValue implements Sketch {
|
|
|
355
406
|
throw new Error(
|
|
356
407
|
`sketch.face() requires exactly one closed region; found ${regions.length}. Use faces() for multiple regions.`,
|
|
357
408
|
);
|
|
358
|
-
return
|
|
409
|
+
return this.frame.face(regions[0]);
|
|
359
410
|
}
|
|
360
411
|
|
|
361
412
|
faces(): readonly FaceModel[] {
|
|
362
413
|
const faces: FaceModel[] = [];
|
|
363
414
|
try {
|
|
364
415
|
for (const region of sketchRegions(this.layers()))
|
|
365
|
-
faces.push(
|
|
416
|
+
faces.push(this.frame.face(region));
|
|
366
417
|
return faces;
|
|
367
418
|
} catch (error) {
|
|
368
419
|
disposeModelObjects(
|
|
@@ -381,7 +432,13 @@ class SketchValue implements Sketch {
|
|
|
381
432
|
)
|
|
382
433
|
values.unshift(value);
|
|
383
434
|
return values.map(value =>
|
|
384
|
-
snapshotSketch(value, s =>
|
|
435
|
+
snapshotSketch(value, s =>
|
|
436
|
+
String(
|
|
437
|
+
values.findIndex(
|
|
438
|
+
value => definitions.get(value) === definitions.get(s),
|
|
439
|
+
),
|
|
440
|
+
),
|
|
441
|
+
),
|
|
385
442
|
);
|
|
386
443
|
}
|
|
387
444
|
}
|
|
@@ -391,17 +448,46 @@ export function sketch(
|
|
|
391
448
|
entries?: readonly SketchEntry[],
|
|
392
449
|
options?: SketchOptions,
|
|
393
450
|
): Sketch {
|
|
394
|
-
return new SketchValue(entries, options);
|
|
451
|
+
return new SketchValue({entries, options});
|
|
395
452
|
}
|
|
396
453
|
|
|
397
454
|
export function isSketch(value: unknown): value is Sketch {
|
|
398
455
|
return value instanceof SketchValue;
|
|
399
456
|
}
|
|
400
457
|
|
|
458
|
+
export function isSketchPoint(value: unknown): value is SketchPoint {
|
|
459
|
+
return (
|
|
460
|
+
!!value && typeof value === 'object' && references.has(value as SketchPoint)
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Internal correspondence between a spatial participant and its sketch data. */
|
|
465
|
+
export function sketchForFrame(frame: SketchFrame): Sketch {
|
|
466
|
+
return framedSketches.get(frame)!;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** A normal immutable sketch value in a captured inspection stage. */
|
|
470
|
+
export function retainSketchFrame(value: Sketch, pose: RigidTransform): Sketch {
|
|
471
|
+
return retainInspectionIdentity(
|
|
472
|
+
new SketchValue({source: value, frame: sketchFrame(value).retained(pose)}),
|
|
473
|
+
value,
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
401
477
|
export function sketchDefinition(value: Sketch): Definition {
|
|
402
478
|
return definitions.get(value)!;
|
|
403
479
|
}
|
|
404
480
|
|
|
481
|
+
/** The preceding spatial value; it shares a geometry definition, not a derived layer. */
|
|
482
|
+
export function sketchSource(value: Sketch): Sketch | undefined {
|
|
483
|
+
return (value as SketchValue).source;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** The relation frame used by this sketch and inherited by its generated faces. */
|
|
487
|
+
export function sketchFrame(value: Sketch): SketchFrame {
|
|
488
|
+
return (value as SketchValue).frame;
|
|
489
|
+
}
|
|
490
|
+
|
|
405
491
|
export type SketchPointSnapshot = Readonly<{
|
|
406
492
|
kind: 'point';
|
|
407
493
|
id: number;
|
|
@@ -497,17 +583,30 @@ export function snapshotSketch(
|
|
|
497
583
|
redundant,
|
|
498
584
|
} = sketchDefinition(value);
|
|
499
585
|
const id = identity(value);
|
|
586
|
+
const ancestors: Sketch[] = [];
|
|
587
|
+
for (
|
|
588
|
+
let ancestor = base;
|
|
589
|
+
ancestor;
|
|
590
|
+
ancestor = sketchDefinition(ancestor).base
|
|
591
|
+
)
|
|
592
|
+
ancestors.push(ancestor);
|
|
593
|
+
const pointIdentity = (reference: Sketch) =>
|
|
594
|
+
identity(
|
|
595
|
+
ancestors.find(
|
|
596
|
+
ancestor => definitions.get(ancestor) === definitions.get(reference),
|
|
597
|
+
) ?? reference,
|
|
598
|
+
);
|
|
500
599
|
return {
|
|
501
600
|
id,
|
|
502
601
|
base: base && identity(base),
|
|
503
|
-
entities: snapshotEntries(entries, id,
|
|
602
|
+
entities: snapshotEntries(entries, id, pointIdentity, points).map(e =>
|
|
504
603
|
e.kind === 'point'
|
|
505
604
|
? {...e, position: points.get(e.id)!}
|
|
506
605
|
: e.kind === 'circle' || e.kind === 'arc'
|
|
507
606
|
? {...e, radius: radii.get(e.id)!}
|
|
508
607
|
: e,
|
|
509
608
|
),
|
|
510
|
-
constraints: snapshotConstraints(constraints, id,
|
|
609
|
+
constraints: snapshotConstraints(constraints, id, pointIdentity),
|
|
511
610
|
degreesOfFreedom,
|
|
512
611
|
redundant,
|
|
513
612
|
};
|