three-cad-viewer 5.0.2 → 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
  */
@@ -88614,11 +88614,7 @@ class Grid extends Group {
88614
88614
  this.getCamera = getCamera;
88615
88615
  this.getAxes0 = getAxes0;
88616
88616
  this.onGridChange = onGridChange || null;
88617
- // Heuristics, experimentally determined
88618
- const size = bbox.max_dist_from_center();
88619
- const canvasSize = Math.min(cadWidth, height);
88620
- const scale = Math.max(1.0, 6 - Math.log2(canvasSize / 100));
88621
- this.minFontIndex = Math.round((size < 2 ? 6 : size < 1000 ? 5 : 3) * scale);
88617
+ this.minFontIndex = this.computeMinFontIndex();
88622
88618
  this.minZoomIndex = -4;
88623
88619
  this.zoomMaxIndex = 5;
88624
88620
  this.canvasHeight = 128; // Fixed height for all label textures (higher = crisper)
@@ -88642,6 +88638,27 @@ class Grid extends Group {
88642
88638
  };
88643
88639
  this.create();
88644
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
+ }
88645
88662
  /**
88646
88663
  * Calculate text scale based on camera mode and canvas size
88647
88664
  */
@@ -97311,7 +97328,7 @@ class Tools {
97311
97328
  }
97312
97329
  }
97313
97330
 
97314
- const version = "5.0.2";
97331
+ const version = "5.0.3";
97315
97332
 
97316
97333
  /**
97317
97334
  * `PickedComponent` over a GPU id-pick result. Drives the shader
@@ -108736,20 +108753,41 @@ function isInstancedFormat(data) {
108736
108753
  "shapes" in data &&
108737
108754
  typeof data.shapes === "object");
108738
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
+ }
108739
108779
  /**
108740
108780
  * Decode the instanced format into a standard Shapes object.
108741
108781
  *
108742
108782
  * 1. Decode all instance buffers from base64 → TypedArrays
108743
108783
  * 2. Walk the shapes tree and replace { ref: N } with decoded instances
108744
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.
108745
108788
  */
108746
108789
  function decodeInstancedFormat(data) {
108747
- // Decode all instances
108748
- const decoded = data.instances.map(decodeInstance);
108749
- // Resolve all shape references
108750
- const shapes = data.shapes;
108751
- resolveRefs(shapes, decoded);
108752
- return shapes;
108790
+ return resolveInstances(data.shapes, decodeBuffers(data.instances));
108753
108791
  }
108754
108792
 
108755
108793
  // =============================================================================
@@ -112473,6 +112511,13 @@ class Viewer {
112473
112511
  // Adapt camera to new dimensions
112474
112512
  this.rendered.camera.changeDimensions(this.bb_radius, cadWidth, height);
112475
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);
112476
112521
  // Resize the post-processing composer (render targets must match viewport)
112477
112522
  this._studioManager.setSize(cadWidth, height);
112478
112523
  // update the this
@@ -115811,5 +115856,5 @@ class Display {
115811
115856
  }
115812
115857
  }
115813
115858
 
115814
- 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 };
115815
115860
  //# sourceMappingURL=three-cad-viewer.esm.js.map