three-cad-viewer 5.0.1 → 5.0.3

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/index.d.ts CHANGED
@@ -34,5 +34,5 @@ export type { DomEventCallback } from "./core/types.js";
34
34
  export type { ColoredMaterial } from "./core/types.js";
35
35
  export type { MaterialAppearance, MaterialXMaterial, StudioOptions, StudioBackground, StudioModeOptions, StudioEnvironment, StudioToneMapping, StudioTextureMapping, } from "./core/types.js";
36
36
  export { isMaterialXMaterial } from "./core/types.js";
37
- export { isInstancedFormat, decodeInstancedFormat, } from "./utils/decode-instances.js";
37
+ export { isInstancedFormat, decodeBuffers, resolveInstances, decodeInstancedFormat, } from "./utils/decode-instances.js";
38
38
  export type { SubscribeOptions } from "./core/types.js";
@@ -60,6 +60,18 @@ declare class Grid extends THREE.Group {
60
60
  * @param options - Configuration options
61
61
  */
62
62
  constructor(options: GridOptions);
63
+ /**
64
+ * Heuristics, experimentally determined
65
+ */
66
+ private computeMinFontIndex;
67
+ /**
68
+ * Update the cached canvas dimensions after the CAD view was resized.
69
+ * The label scale is derived from these (see calculateTextScale), so the
70
+ * caller must rescale afterwards via scaleLabels() / update(zoom, true).
71
+ * @param cadWidth - New width of the CAD view in pixels
72
+ * @param height - New height of the CAD view in pixels
73
+ */
74
+ resize(cadWidth: number, height: number): void;
63
75
  /**
64
76
  * Calculate text scale based on camera mode and canvas size
65
77
  */
@@ -22,6 +22,7 @@ interface EdgeData {
22
22
  edges: Float32Array | number[][];
23
23
  segments_per_edge?: number[] | Uint32Array;
24
24
  obj_vertices?: Float32Array | number[];
25
+ edge_types?: number[] | Uint8Array | Uint32Array;
25
26
  }
26
27
  interface VertexData {
27
28
  obj_vertices: Float32Array | number[];
@@ -87606,11 +87606,14 @@ class NestedGroup {
87606
87606
  // widen + recolor the flagged segment in-shader (Option A).
87607
87607
  this.highlight?.patchEdgeMaterial(edges.material);
87608
87608
  // Internal measurement backend: record the standalone edge node's geometry
87609
- // (obj_vertices lets the hover status resolve a picked corner's coords).
87609
+ // (obj_vertices lets the hover status resolve a picked corner's coords,
87610
+ // edge_types the exact curve type — without it every edge reads as "other"
87611
+ // and a circle/arc loses its center + radius readout).
87610
87612
  this.meshGeometry.register(path, {
87611
87613
  edges: edgeData.edges,
87612
87614
  segments_per_edge: edgeData.segments_per_edge,
87613
87615
  obj_vertices: edgeData.obj_vertices,
87616
+ edge_types: edgeData.edge_types,
87614
87617
  }, group, null);
87615
87618
  }
87616
87619
  group.setEdges(edges);
@@ -88611,11 +88614,7 @@ class Grid extends Group {
88611
88614
  this.getCamera = getCamera;
88612
88615
  this.getAxes0 = getAxes0;
88613
88616
  this.onGridChange = onGridChange || null;
88614
- // Heuristics, experimentally determined
88615
- const size = bbox.max_dist_from_center();
88616
- const canvasSize = Math.min(cadWidth, height);
88617
- const scale = Math.max(1.0, 6 - Math.log2(canvasSize / 100));
88618
- this.minFontIndex = Math.round((size < 2 ? 6 : size < 1000 ? 5 : 3) * scale);
88617
+ this.minFontIndex = this.computeMinFontIndex();
88619
88618
  this.minZoomIndex = -4;
88620
88619
  this.zoomMaxIndex = 5;
88621
88620
  this.canvasHeight = 128; // Fixed height for all label textures (higher = crisper)
@@ -88639,6 +88638,27 @@ class Grid extends Group {
88639
88638
  };
88640
88639
  this.create();
88641
88640
  }
88641
+ /**
88642
+ * Heuristics, experimentally determined
88643
+ */
88644
+ computeMinFontIndex() {
88645
+ const size = this.bbox.max_dist_from_center();
88646
+ const canvasSize = Math.min(this.cadWidth, this.height);
88647
+ const scale = Math.max(1.0, 6 - Math.log2(canvasSize / 100));
88648
+ return Math.round((size < 2 ? 6 : size < 1000 ? 5 : 3) * scale);
88649
+ }
88650
+ /**
88651
+ * Update the cached canvas dimensions after the CAD view was resized.
88652
+ * The label scale is derived from these (see calculateTextScale), so the
88653
+ * caller must rescale afterwards via scaleLabels() / update(zoom, true).
88654
+ * @param cadWidth - New width of the CAD view in pixels
88655
+ * @param height - New height of the CAD view in pixels
88656
+ */
88657
+ resize(cadWidth, height) {
88658
+ this.cadWidth = cadWidth;
88659
+ this.height = height;
88660
+ this.minFontIndex = this.computeMinFontIndex();
88661
+ }
88642
88662
  /**
88643
88663
  * Calculate text scale based on camera mode and canvas size
88644
88664
  */
@@ -97308,7 +97328,7 @@ class Tools {
97308
97328
  }
97309
97329
  }
97310
97330
 
97311
- const version = "5.0.1";
97331
+ const version = "5.0.3";
97312
97332
 
97313
97333
  /**
97314
97334
  * `PickedComponent` over a GPU id-pick result. Drives the shader
@@ -108733,20 +108753,41 @@ function isInstancedFormat(data) {
108733
108753
  "shapes" in data &&
108734
108754
  typeof data.shapes === "object");
108735
108755
  }
108756
+ /**
108757
+ * Decode every instance's buffers from base64 into TypedArrays.
108758
+ *
108759
+ * This is the leaf half of the instanced format: it knows the encoding and
108760
+ * nothing about the shapes tree. A host that receives its geometry as raw
108761
+ * binary rather than base64 skips this step and builds the `Shape[]` itself.
108762
+ */
108763
+ function decodeBuffers(instances) {
108764
+ return instances.map(decodeInstance);
108765
+ }
108766
+ /**
108767
+ * Resolve `{ ref: N }` entries in the shapes tree against decoded instances,
108768
+ * and return the tree.
108769
+ *
108770
+ * This is the structural half: the same geometry referenced N times - twenty
108771
+ * identical bolts - which every host needs whatever encoding it received the
108772
+ * buffers in. Held separate from `decodeBuffers` so that a host holding
108773
+ * TypedArrays already does not have to reimplement the walk.
108774
+ */
108775
+ function resolveInstances(shapes, decoded) {
108776
+ resolveRefs(shapes, decoded);
108777
+ return shapes;
108778
+ }
108736
108779
  /**
108737
108780
  * Decode the instanced format into a standard Shapes object.
108738
108781
  *
108739
108782
  * 1. Decode all instance buffers from base64 → TypedArrays
108740
108783
  * 2. Walk the shapes tree and replace { ref: N } with decoded instances
108741
108784
  * 3. Return the unwrapped Shapes object
108785
+ *
108786
+ * Kept as the composition of the two halves above, so existing callers see
108787
+ * no change.
108742
108788
  */
108743
108789
  function decodeInstancedFormat(data) {
108744
- // Decode all instances
108745
- const decoded = data.instances.map(decodeInstance);
108746
- // Resolve all shape references
108747
- const shapes = data.shapes;
108748
- resolveRefs(shapes, decoded);
108749
- return shapes;
108790
+ return resolveInstances(data.shapes, decodeBuffers(data.instances));
108750
108791
  }
108751
108792
 
108752
108793
  // =============================================================================
@@ -112470,6 +112511,13 @@ class Viewer {
112470
112511
  // Adapt camera to new dimensions
112471
112512
  this.rendered.camera.changeDimensions(this.bb_radius, cadWidth, height);
112472
112513
  this.controls.handleResize();
112514
+ // Rescale the grid labels explicitly: their size is derived from the
112515
+ // canvas height (and, for ortho, the frustum), both of which just
112516
+ // changed — but a resize alone never trips the zoom-based rescale gate
112517
+ // in Grid.update().
112518
+ this.rendered.gridHelper.resize(cadWidth, height);
112519
+ this.rendered.gridHelper.scaleLabels();
112520
+ this.rendered.gridHelper.update(this.rendered.camera.getZoom(), true);
112473
112521
  // Resize the post-processing composer (render targets must match viewport)
112474
112522
  this._studioManager.setSize(cadWidth, height);
112475
112523
  // update the this
@@ -115808,5 +115856,5 @@ class Display {
115808
115856
  }
115809
115857
  }
115810
115858
 
115811
- export { CLIP_INDICES, CollapseState, Display, EnvironmentManager, MATERIAL_PRESETS, MATERIAL_PRESET_NAMES, Timer$1 as Timer, Viewer, decodeInstancedFormat, gpuTracker, hasSegmentsPerEdge, hasTrianglesPerFace, isClipIndex, isInstancedFormat, isMaterialXMaterial, isShapeBinaryFormat, logger, version };
115859
+ export { CLIP_INDICES, CollapseState, Display, EnvironmentManager, MATERIAL_PRESETS, MATERIAL_PRESET_NAMES, Timer$1 as Timer, Viewer, decodeBuffers, decodeInstancedFormat, gpuTracker, hasSegmentsPerEdge, hasTrianglesPerFace, isClipIndex, isInstancedFormat, isMaterialXMaterial, isShapeBinaryFormat, logger, resolveInstances, version };
115812
115860
  //# sourceMappingURL=three-cad-viewer.esm.js.map