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 +1 -1
- package/dist/scene/grid.d.ts +12 -0
- package/dist/three-cad-viewer.esm.js +58 -13
- package/dist/three-cad-viewer.esm.js.map +1 -1
- package/dist/three-cad-viewer.esm.min.js +3 -3
- package/dist/three-cad-viewer.js +59 -12
- package/dist/three-cad-viewer.min.js +2 -2
- package/dist/utils/decode-instances.d.ts +23 -2
- package/package.json +1 -1
package/dist/three-cad-viewer.js
CHANGED
|
@@ -88620,11 +88620,7 @@ float metalnessFactor = metalness;
|
|
|
88620
88620
|
this.getCamera = getCamera;
|
|
88621
88621
|
this.getAxes0 = getAxes0;
|
|
88622
88622
|
this.onGridChange = onGridChange || null;
|
|
88623
|
-
|
|
88624
|
-
const size = bbox.max_dist_from_center();
|
|
88625
|
-
const canvasSize = Math.min(cadWidth, height);
|
|
88626
|
-
const scale = Math.max(1.0, 6 - Math.log2(canvasSize / 100));
|
|
88627
|
-
this.minFontIndex = Math.round((size < 2 ? 6 : size < 1000 ? 5 : 3) * scale);
|
|
88623
|
+
this.minFontIndex = this.computeMinFontIndex();
|
|
88628
88624
|
this.minZoomIndex = -4;
|
|
88629
88625
|
this.zoomMaxIndex = 5;
|
|
88630
88626
|
this.canvasHeight = 128; // Fixed height for all label textures (higher = crisper)
|
|
@@ -88648,6 +88644,27 @@ float metalnessFactor = metalness;
|
|
|
88648
88644
|
};
|
|
88649
88645
|
this.create();
|
|
88650
88646
|
}
|
|
88647
|
+
/**
|
|
88648
|
+
* Heuristics, experimentally determined
|
|
88649
|
+
*/
|
|
88650
|
+
computeMinFontIndex() {
|
|
88651
|
+
const size = this.bbox.max_dist_from_center();
|
|
88652
|
+
const canvasSize = Math.min(this.cadWidth, this.height);
|
|
88653
|
+
const scale = Math.max(1.0, 6 - Math.log2(canvasSize / 100));
|
|
88654
|
+
return Math.round((size < 2 ? 6 : size < 1000 ? 5 : 3) * scale);
|
|
88655
|
+
}
|
|
88656
|
+
/**
|
|
88657
|
+
* Update the cached canvas dimensions after the CAD view was resized.
|
|
88658
|
+
* The label scale is derived from these (see calculateTextScale), so the
|
|
88659
|
+
* caller must rescale afterwards via scaleLabels() / update(zoom, true).
|
|
88660
|
+
* @param cadWidth - New width of the CAD view in pixels
|
|
88661
|
+
* @param height - New height of the CAD view in pixels
|
|
88662
|
+
*/
|
|
88663
|
+
resize(cadWidth, height) {
|
|
88664
|
+
this.cadWidth = cadWidth;
|
|
88665
|
+
this.height = height;
|
|
88666
|
+
this.minFontIndex = this.computeMinFontIndex();
|
|
88667
|
+
}
|
|
88651
88668
|
/**
|
|
88652
88669
|
* Calculate text scale based on camera mode and canvas size
|
|
88653
88670
|
*/
|
|
@@ -97317,7 +97334,7 @@ float metalnessFactor = metalness;
|
|
|
97317
97334
|
}
|
|
97318
97335
|
}
|
|
97319
97336
|
|
|
97320
|
-
const version = "5.0.
|
|
97337
|
+
const version = "5.0.3";
|
|
97321
97338
|
|
|
97322
97339
|
/**
|
|
97323
97340
|
* `PickedComponent` over a GPU id-pick result. Drives the shader
|
|
@@ -108742,20 +108759,41 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
|
|
|
108742
108759
|
"shapes" in data &&
|
|
108743
108760
|
typeof data.shapes === "object");
|
|
108744
108761
|
}
|
|
108762
|
+
/**
|
|
108763
|
+
* Decode every instance's buffers from base64 into TypedArrays.
|
|
108764
|
+
*
|
|
108765
|
+
* This is the leaf half of the instanced format: it knows the encoding and
|
|
108766
|
+
* nothing about the shapes tree. A host that receives its geometry as raw
|
|
108767
|
+
* binary rather than base64 skips this step and builds the `Shape[]` itself.
|
|
108768
|
+
*/
|
|
108769
|
+
function decodeBuffers(instances) {
|
|
108770
|
+
return instances.map(decodeInstance);
|
|
108771
|
+
}
|
|
108772
|
+
/**
|
|
108773
|
+
* Resolve `{ ref: N }` entries in the shapes tree against decoded instances,
|
|
108774
|
+
* and return the tree.
|
|
108775
|
+
*
|
|
108776
|
+
* This is the structural half: the same geometry referenced N times - twenty
|
|
108777
|
+
* identical bolts - which every host needs whatever encoding it received the
|
|
108778
|
+
* buffers in. Held separate from `decodeBuffers` so that a host holding
|
|
108779
|
+
* TypedArrays already does not have to reimplement the walk.
|
|
108780
|
+
*/
|
|
108781
|
+
function resolveInstances(shapes, decoded) {
|
|
108782
|
+
resolveRefs(shapes, decoded);
|
|
108783
|
+
return shapes;
|
|
108784
|
+
}
|
|
108745
108785
|
/**
|
|
108746
108786
|
* Decode the instanced format into a standard Shapes object.
|
|
108747
108787
|
*
|
|
108748
108788
|
* 1. Decode all instance buffers from base64 → TypedArrays
|
|
108749
108789
|
* 2. Walk the shapes tree and replace { ref: N } with decoded instances
|
|
108750
108790
|
* 3. Return the unwrapped Shapes object
|
|
108791
|
+
*
|
|
108792
|
+
* Kept as the composition of the two halves above, so existing callers see
|
|
108793
|
+
* no change.
|
|
108751
108794
|
*/
|
|
108752
108795
|
function decodeInstancedFormat(data) {
|
|
108753
|
-
|
|
108754
|
-
const decoded = data.instances.map(decodeInstance);
|
|
108755
|
-
// Resolve all shape references
|
|
108756
|
-
const shapes = data.shapes;
|
|
108757
|
-
resolveRefs(shapes, decoded);
|
|
108758
|
-
return shapes;
|
|
108796
|
+
return resolveInstances(data.shapes, decodeBuffers(data.instances));
|
|
108759
108797
|
}
|
|
108760
108798
|
|
|
108761
108799
|
// =============================================================================
|
|
@@ -112479,6 +112517,13 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
|
|
|
112479
112517
|
// Adapt camera to new dimensions
|
|
112480
112518
|
this.rendered.camera.changeDimensions(this.bb_radius, cadWidth, height);
|
|
112481
112519
|
this.controls.handleResize();
|
|
112520
|
+
// Rescale the grid labels explicitly: their size is derived from the
|
|
112521
|
+
// canvas height (and, for ortho, the frustum), both of which just
|
|
112522
|
+
// changed — but a resize alone never trips the zoom-based rescale gate
|
|
112523
|
+
// in Grid.update().
|
|
112524
|
+
this.rendered.gridHelper.resize(cadWidth, height);
|
|
112525
|
+
this.rendered.gridHelper.scaleLabels();
|
|
112526
|
+
this.rendered.gridHelper.update(this.rendered.camera.getZoom(), true);
|
|
112482
112527
|
// Resize the post-processing composer (render targets must match viewport)
|
|
112483
112528
|
this._studioManager.setSize(cadWidth, height);
|
|
112484
112529
|
// update the this
|
|
@@ -115824,6 +115869,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
|
|
|
115824
115869
|
exports.MATERIAL_PRESET_NAMES = MATERIAL_PRESET_NAMES;
|
|
115825
115870
|
exports.Timer = Timer$1;
|
|
115826
115871
|
exports.Viewer = Viewer;
|
|
115872
|
+
exports.decodeBuffers = decodeBuffers;
|
|
115827
115873
|
exports.decodeInstancedFormat = decodeInstancedFormat;
|
|
115828
115874
|
exports.gpuTracker = gpuTracker;
|
|
115829
115875
|
exports.hasSegmentsPerEdge = hasSegmentsPerEdge;
|
|
@@ -115833,6 +115879,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
|
|
|
115833
115879
|
exports.isMaterialXMaterial = isMaterialXMaterial;
|
|
115834
115880
|
exports.isShapeBinaryFormat = isShapeBinaryFormat;
|
|
115835
115881
|
exports.logger = logger;
|
|
115882
|
+
exports.resolveInstances = resolveInstances;
|
|
115836
115883
|
exports.version = version;
|
|
115837
115884
|
|
|
115838
115885
|
}));
|