@code3d/core 0.0.1-alpha.0 → 0.0.1-alpha.10

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 (154) hide show
  1. package/README.md +43 -807
  2. package/THIRD_PARTY.md +40 -0
  3. package/bld/THIRD_PARTY_NOTICES.txt +182 -0
  4. package/bld/chunks/chunk-5IP37Z5U.js +30 -0
  5. package/bld/chunks/chunk-5IP37Z5U.js.map +7 -0
  6. package/bld/chunks/chunk-7FIFPADJ.js +1 -0
  7. package/bld/chunks/chunk-7FIFPADJ.js.map +7 -0
  8. package/bld/chunks/chunk-HBRLIGQN.js +31 -0
  9. package/bld/chunks/chunk-HBRLIGQN.js.map +7 -0
  10. package/bld/chunks/chunk-IJHQ57VL.js +19 -0
  11. package/bld/chunks/chunk-IJHQ57VL.js.map +7 -0
  12. package/bld/chunks/chunk-TTJOM4DJ.js +26458 -0
  13. package/bld/chunks/chunk-TTJOM4DJ.js.map +7 -0
  14. package/bld/library/bound-solver.d.ts +29 -5
  15. package/bld/library/bound-solver.d.ts.map +1 -1
  16. package/bld/library/cached.d.ts +35 -0
  17. package/bld/library/cached.d.ts.map +1 -0
  18. package/bld/library/font.d.ts +39 -0
  19. package/bld/library/font.d.ts.map +1 -0
  20. package/bld/library/google-font.d.ts +14 -0
  21. package/bld/library/google-font.d.ts.map +1 -0
  22. package/bld/library/index.d.ts +10 -2
  23. package/bld/library/index.d.ts.map +1 -1
  24. package/bld/library/index.js +94 -3
  25. package/bld/library/index.js.map +7 -1
  26. package/bld/library/inspect.d.ts +98 -0
  27. package/bld/library/inspect.d.ts.map +1 -0
  28. package/bld/library/kernel-artifact-codec.d.ts.map +1 -1
  29. package/bld/library/kernel-cache.d.ts +28 -7
  30. package/bld/library/kernel-cache.d.ts.map +1 -1
  31. package/bld/library/loft.d.ts.map +1 -1
  32. package/bld/library/material.d.ts +1 -1
  33. package/bld/library/material.d.ts.map +1 -1
  34. package/bld/library/open-cascade.d.ts +4 -0
  35. package/bld/library/open-cascade.d.ts.map +1 -0
  36. package/bld/library/relation-solver.d.ts +19 -8
  37. package/bld/library/relation-solver.d.ts.map +1 -1
  38. package/bld/library/replicad.d.ts +3 -2
  39. package/bld/library/replicad.d.ts.map +1 -1
  40. package/bld/library/replicad.js +10 -24
  41. package/bld/library/replicad.js.map +7 -1
  42. package/bld/library/retained-memory.d.ts.map +1 -1
  43. package/bld/library/runtime.d.ts +518 -155
  44. package/bld/library/runtime.d.ts.map +1 -1
  45. package/bld/library/sketch-solver.d.ts +1 -1
  46. package/bld/library/sketch-solver.d.ts.map +1 -1
  47. package/bld/library/sketch.d.ts +21 -1
  48. package/bld/library/sketch.d.ts.map +1 -1
  49. package/bld/library/text.d.ts +53 -0
  50. package/bld/library/text.d.ts.map +1 -0
  51. package/bld/library/three.js +3 -3
  52. package/bld/library/three.js.map +7 -1
  53. package/bld/library/topology.d.ts +6 -2
  54. package/bld/library/topology.d.ts.map +1 -1
  55. package/bld/node/index.d.ts.map +1 -1
  56. package/bld/node/index.js +96 -14
  57. package/bld/node/index.js.map +7 -1
  58. package/bld/node/replicad.js +13 -3
  59. package/bld/node/replicad.js.map +7 -1
  60. package/bld/tooling/index.d.ts +18 -15
  61. package/bld/tooling/index.d.ts.map +1 -1
  62. package/bld/tooling/index.js +165 -19
  63. package/bld/tooling/index.js.map +7 -1
  64. package/docs/api.md +764 -0
  65. package/docs/custom-primitives.mdx +58 -0
  66. package/docs/local-coordinates.md +187 -0
  67. package/docs/origins-and-rotation.mdx +105 -0
  68. package/docs/relations.mdx +450 -0
  69. package/docs/runtime.md +297 -0
  70. package/docs/shells.mdx +70 -0
  71. package/docs/sketches.md +83 -0
  72. package/docs/text.md +23 -0
  73. package/docs/topology.md +152 -0
  74. package/docs/values.md +119 -0
  75. package/package.json +20 -7
  76. package/src/library/bound-solver.ts +103 -73
  77. package/src/library/cached.ts +153 -0
  78. package/src/library/font.ts +186 -0
  79. package/src/library/google-font.ts +97 -0
  80. package/src/library/index.ts +53 -5
  81. package/src/library/inspect.ts +176 -0
  82. package/src/library/kernel-artifact-codec.ts +129 -20
  83. package/src/library/kernel-cache.ts +175 -39
  84. package/src/library/loft.ts +9 -1
  85. package/src/library/material.ts +3 -4
  86. package/src/library/open-cascade.ts +13 -0
  87. package/src/library/relation-solver.ts +230 -113
  88. package/src/library/replicad.ts +5 -5
  89. package/src/library/retained-memory.ts +6 -1
  90. package/src/library/runtime.ts +3753 -1181
  91. package/src/library/shell.ts +3 -3
  92. package/src/library/sketch-solver.ts +3 -1
  93. package/src/library/sketch.ts +112 -13
  94. package/src/library/text.ts +477 -0
  95. package/src/library/topology.ts +61 -17
  96. package/src/library/tsconfig.json +2 -1
  97. package/src/node/index.ts +14 -3
  98. package/src/node/tsconfig.json +2 -1
  99. package/src/tooling/index.ts +64 -51
  100. package/src/tooling/tsconfig.json +2 -1
  101. package/bld/library/alignment-geometry.js +0 -322
  102. package/bld/library/alignment-geometry.js.map +0 -1
  103. package/bld/library/bound-solver.js +0 -252
  104. package/bld/library/bound-solver.js.map +0 -1
  105. package/bld/library/extrude.js +0 -28
  106. package/bld/library/extrude.js.map +0 -1
  107. package/bld/library/kernel-artifact-codec.js +0 -148
  108. package/bld/library/kernel-artifact-codec.js.map +0 -1
  109. package/bld/library/kernel-cache.js +0 -245
  110. package/bld/library/kernel-cache.js.map +0 -1
  111. package/bld/library/kernel-shapes.js +0 -108
  112. package/bld/library/kernel-shapes.js.map +0 -1
  113. package/bld/library/loft.js +0 -161
  114. package/bld/library/loft.js.map +0 -1
  115. package/bld/library/material.js +0 -176
  116. package/bld/library/material.js.map +0 -1
  117. package/bld/library/model-color.js +0 -36
  118. package/bld/library/model-color.js.map +0 -1
  119. package/bld/library/open-cascade-error.js +0 -22
  120. package/bld/library/open-cascade-error.js.map +0 -1
  121. package/bld/library/relation-solver.js +0 -258
  122. package/bld/library/relation-solver.js.map +0 -1
  123. package/bld/library/retained-memory.js +0 -27
  124. package/bld/library/retained-memory.js.map +0 -1
  125. package/bld/library/runtime.js +0 -2954
  126. package/bld/library/runtime.js.map +0 -1
  127. package/bld/library/shell.js +0 -221
  128. package/bld/library/shell.js.map +0 -1
  129. package/bld/library/sketch-curve-intersections.js +0 -117
  130. package/bld/library/sketch-curve-intersections.js.map +0 -1
  131. package/bld/library/sketch-curves.js +0 -89
  132. package/bld/library/sketch-curves.js.map +0 -1
  133. package/bld/library/sketch-drag-rules.js +0 -522
  134. package/bld/library/sketch-drag-rules.js.map +0 -1
  135. package/bld/library/sketch-face.js +0 -72
  136. package/bld/library/sketch-face.js.map +0 -1
  137. package/bld/library/sketch-incidence.js +0 -114
  138. package/bld/library/sketch-incidence.js.map +0 -1
  139. package/bld/library/sketch-precision.js +0 -55
  140. package/bld/library/sketch-precision.js.map +0 -1
  141. package/bld/library/sketch-regions.js +0 -193
  142. package/bld/library/sketch-regions.js.map +0 -1
  143. package/bld/library/sketch-solver.js +0 -578
  144. package/bld/library/sketch-solver.js.map +0 -1
  145. package/bld/library/sketch.js +0 -650
  146. package/bld/library/sketch.js.map +0 -1
  147. package/bld/library/spatial.js +0 -195
  148. package/bld/library/spatial.js.map +0 -1
  149. package/bld/library/topology-id.js +0 -67
  150. package/bld/library/topology-id.js.map +0 -1
  151. package/bld/library/topology-inspection.js +0 -267
  152. package/bld/library/topology-inspection.js.map +0 -1
  153. package/bld/library/topology.js +0 -455
  154. package/bld/library/topology.js.map +0 -1
@@ -119,7 +119,7 @@ function openShell(
119
119
  return {
120
120
  shape: result,
121
121
  topology: transferShapeTopology(
122
- [{shape, topology, index: 1}],
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 input paths for either direction. Offset
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, index: 1}],
210
+ [{shape, topology, namespace: 'preserve'}],
211
211
  result,
212
212
  cut,
213
213
  ),
@@ -1,4 +1,6 @@
1
- import type {GcsSystem, ModuleStatic} from '@salusoft89/planegcs';
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';
@@ -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
- sketchFaceModel,
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
- entries?: readonly SketchEntry[],
117
- options?: SketchOptions,
118
- base?: Sketch,
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) || !ancestors.has(ref.sketch)) {
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) || !ancestors.has(ref.sketch)
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 sketchFaceModel(regions[0]);
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(sketchFaceModel(region));
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 => String(values.indexOf(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, identity, points).map(e =>
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, identity),
609
+ constraints: snapshotConstraints(constraints, id, pointIdentity),
511
610
  degreesOfFreedom,
512
611
  redundant,
513
612
  };