three-cad-viewer 5.0.7 → 5.1.0

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.
@@ -81835,6 +81835,45 @@ void main() {
81835
81835
  this.listeners = [];
81836
81836
  }
81837
81837
  }
81838
+ /**
81839
+ * Copy `text` to the clipboard from inside a user-initiated event handler.
81840
+ *
81841
+ * Tries the synchronous hidden-textarea `execCommand("copy")` first: it needs no
81842
+ * clipboard permission, so it also works in embedding iframes and WebKit views that
81843
+ * refuse `navigator.clipboard`. Falls back to the async Clipboard API.
81844
+ * Focus is restored to the previously focused element.
81845
+ *
81846
+ * @param text - The text to copy.
81847
+ * @param parent - Element the temporary textarea is attached to.
81848
+ * @returns true when the synchronous copy reported success.
81849
+ */
81850
+ function copyText(text, parent) {
81851
+ const previous = document.activeElement;
81852
+ const area = document.createElement("textarea");
81853
+ area.value = text;
81854
+ area.setAttribute("readonly", "");
81855
+ area.style.position = "fixed";
81856
+ area.style.left = "-9999px";
81857
+ area.style.opacity = "0";
81858
+ parent.appendChild(area);
81859
+ area.select();
81860
+ let copied;
81861
+ try {
81862
+ copied = document.execCommand("copy");
81863
+ }
81864
+ catch {
81865
+ copied = false;
81866
+ }
81867
+ parent.removeChild(area);
81868
+ if (previous instanceof HTMLElement)
81869
+ previous.focus({ preventScroll: true });
81870
+ if (!copied && navigator.clipboard !== undefined) {
81871
+ navigator.clipboard.writeText(text).catch((err) => {
81872
+ logger.debug("Clipboard write refused:", err);
81873
+ });
81874
+ }
81875
+ return copied;
81876
+ }
81838
81877
 
81839
81878
  /**
81840
81879
  * Zebra Analysis Tool for Three.js CAD Viewer
@@ -85102,7 +85141,7 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85102
85141
  * renames an anchor must fail LOUDLY here, not silently drop the highlight (build
85103
85142
  * would otherwise stay green). One guard test asserts each anchor still exists.
85104
85143
  */
85105
- function replaceOrThrow(src, anchor, replacement, where) {
85144
+ function replaceOrThrow$1(src, anchor, replacement, where) {
85106
85145
  if (!src.includes(anchor)) {
85107
85146
  throw new Error(`HighlightController.${where}: shader anchor not found: ${JSON.stringify(anchor)}`);
85108
85147
  }
@@ -85220,6 +85259,23 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85220
85259
  }
85221
85260
  this._applyHover(`s${solidPath}`, ids);
85222
85261
  }
85262
+ /**
85263
+ * HOVER every FACE at or below the tree path `prefix` (a leaf or a whole group),
85264
+ * or clear hover when `null`. Drives the tree-row hover highlight.
85265
+ */
85266
+ setHoverPath(prefix) {
85267
+ if (prefix == null) {
85268
+ this._applyHover("", []);
85269
+ return;
85270
+ }
85271
+ const sub = prefix + "/";
85272
+ const ids = [];
85273
+ for (const info of this.registry.entries()) {
85274
+ if (info.topo === "face" && info.path.startsWith(sub))
85275
+ ids.push(info.id);
85276
+ }
85277
+ this._applyHover(`p${prefix}`, ids);
85278
+ }
85223
85279
  /** Set or clear the SELECTED flag for a single component id. */
85224
85280
  setSelected(id, flag) {
85225
85281
  this._setBit(id, HighlightFlag.SELECTED, flag);
@@ -85322,7 +85378,7 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85322
85378
  shader.vertexShader =
85323
85379
  HL_VERTEX_HEADER +
85324
85380
  "\n" +
85325
- replaceOrThrow(shader.vertexShader, "void main() {", `void main() {\n ${HL_VERTEX_ASSIGN}`, where);
85381
+ replaceOrThrow$1(shader.vertexShader, "void main() {", `void main() {\n ${HL_VERTEX_ASSIGN}`, where);
85326
85382
  shader.fragmentShader = HL_FRAGMENT_HEADER + "\n" + shader.fragmentShader;
85327
85383
  // Topo-specific color / size injection.
85328
85384
  customize(shader);
@@ -85337,7 +85393,7 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85337
85393
  */
85338
85394
  patchFaceMaterial(material) {
85339
85395
  this._install(material, "patchFaceMaterial", (shader) => {
85340
- shader.fragmentShader = replaceOrThrow(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${HL_COLOR_OVERRIDE}`, "patchFaceMaterial");
85396
+ shader.fragmentShader = replaceOrThrow$1(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${HL_COLOR_OVERRIDE}`, "patchFaceMaterial");
85341
85397
  });
85342
85398
  }
85343
85399
  /**
@@ -85349,9 +85405,9 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85349
85405
  */
85350
85406
  patchEdgeMaterial(material) {
85351
85407
  this._install(material, "patchEdgeMaterial", (shader) => {
85352
- shader.vertexShader = replaceOrThrow(shader.vertexShader, "offset *= linewidth;", `uint hlEdgeState = highlightState();
85408
+ shader.vertexShader = replaceOrThrow$1(shader.vertexShader, "offset *= linewidth;", `uint hlEdgeState = highlightState();
85353
85409
  offset *= ${focusSizeExpr("hlEdgeState", EDGE_FOCUS_WIDTH, EDGE_FOCUS_WIDTH - 2, "linewidth")};`, "patchEdgeMaterial");
85354
- shader.fragmentShader = replaceOrThrow(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${HL_COLOR_OVERRIDE}`, "patchEdgeMaterial");
85410
+ shader.fragmentShader = replaceOrThrow$1(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${HL_COLOR_OVERRIDE}`, "patchEdgeMaterial");
85355
85411
  });
85356
85412
  }
85357
85413
  /**
@@ -85366,12 +85422,12 @@ uniform vec3 ${U_HIGHLIGHT_HOVER_COLOR};`;
85366
85422
  const cull = options.cullUnhighlighted === true;
85367
85423
  const none = cull ? "0.0" : "size";
85368
85424
  this._install(material, "patchVertexMaterial", (shader) => {
85369
- shader.vertexShader = replaceOrThrow(shader.vertexShader, "gl_PointSize = size;", `uint hlPtState = highlightState();
85425
+ shader.vertexShader = replaceOrThrow$1(shader.vertexShader, "gl_PointSize = size;", `uint hlPtState = highlightState();
85370
85426
  gl_PointSize = ${focusSizeExpr("hlPtState", VERTEX_FOCUS_SIZE, VERTEX_FOCUS_SIZE - 2, none)};`, "patchVertexMaterial");
85371
85427
  const discard = cull
85372
85428
  ? "\n if (highlightState() == 0u) discard;"
85373
85429
  : "";
85374
- shader.fragmentShader = replaceOrThrow(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${discard}${HL_COLOR_OVERRIDE}`, "patchVertexMaterial");
85430
+ shader.fragmentShader = replaceOrThrow$1(shader.fragmentShader, "#include <color_fragment>", `#include <color_fragment>${discard}${HL_COLOR_OVERRIDE}`, "patchVertexMaterial");
85375
85431
  },
85376
85432
  // The cull discard is the variant that must NOT share a program with the
85377
85433
  // standalone (always-visible) vertex cloud — the ghost-vertex bug.
@@ -90164,8 +90220,9 @@ float metalnessFactor = metalness;
90164
90220
  * @param theme - The UI theme ('light' or 'dark').
90165
90221
  * @param linkIcons - Whether icon 0 and 1 are linked.
90166
90222
  * @param debug - Enable debug logging.
90223
+ * @param hoverHandler - Callback for label hover (node path, or null on leave).
90167
90224
  */
90168
- constructor(tree, scrollContainer, objectHandler, pickHandler, updateHandler, notificationHandler, colorGetter, theme, linkIcons, debug = false) {
90225
+ constructor(tree, scrollContainer, objectHandler, pickHandler, updateHandler, notificationHandler, colorGetter, theme, linkIcons, debug = false, hoverHandler = null) {
90169
90226
  /************************************************************************************
90170
90227
  * Handlers
90171
90228
  ************************************************************************************/
@@ -90280,6 +90337,7 @@ float metalnessFactor = metalness;
90280
90337
  this.theme = theme;
90281
90338
  this.linkIcons = linkIcons;
90282
90339
  this.debug = debug;
90340
+ this.hoverHandler = hoverHandler;
90283
90341
  this.model = null;
90284
90342
  this.container = null;
90285
90343
  this.lastLabel = null;
@@ -90477,6 +90535,12 @@ float metalnessFactor = metalness;
90477
90535
  e.stopPropagation();
90478
90536
  this.handleLabelClick(node, e);
90479
90537
  };
90538
+ label.onmouseenter = () => {
90539
+ this.hoverHandler?.(this.getNodePath(node));
90540
+ };
90541
+ label.onmouseleave = () => {
90542
+ this.hoverHandler?.(null);
90543
+ };
90480
90544
  nodeContent.appendChild(label);
90481
90545
  let childrenContainer = null;
90482
90546
  if (node.children) {
@@ -90968,6 +91032,357 @@ float metalnessFactor = metalness;
90968
91032
  }
90969
91033
  };
90970
91034
 
91035
+ /**
91036
+ * Section hatching for clip caps (CAD mode, shader-only). The per-solid cap quads
91037
+ * draw hatch lines anchored to the plane (stable while rotating/panning) whose
91038
+ * spacing is kept at a constant pixel distance by a per-frame world-per-pixel
91039
+ * uniform. The outline of the caps is drawn separately (see cap-outline.ts); for its
91040
+ * id pass the same cap shader can output the cap's id instead of its color.
91041
+ *
91042
+ * All shared uniforms are plain `{ value }` objects held by reference, so a single
91043
+ * write (e.g. the per-frame hatch spacing) updates every patched material without a
91044
+ * recompile.
91045
+ */
91046
+ /** Distance between hatch lines in pixels. */
91047
+ const HATCH_SPACING_PX = 8;
91048
+ /** Width of a hatch line in pixels. */
91049
+ const HATCH_LINE_WIDTH_PX = 1;
91050
+ /**
91051
+ * Hatch angle (radians) and spacing factor per solid, cycled by the solid's index
91052
+ * so that neighbouring solids are told apart (drawing convention: alternate the
91053
+ * hatch direction between adjacent parts).
91054
+ */
91055
+ const HATCH_VARIANTS = [
91056
+ { angle: Math.PI / 4, scale: 1.0 },
91057
+ { angle: (3 * Math.PI) / 4, scale: 1.0 },
91058
+ { angle: Math.PI / 4, scale: 1.6 },
91059
+ { angle: (3 * Math.PI) / 4, scale: 1.6 },
91060
+ ];
91061
+ function createHatchUniforms(capHalfSize) {
91062
+ return {
91063
+ uHatchSpacing: { value: 1 },
91064
+ uCapHalfSize: { value: capHalfSize },
91065
+ uHatchLineWidth: { value: HATCH_LINE_WIDTH_PX },
91066
+ uHatchOn: { value: 1 },
91067
+ uCapIdPass: { value: 0 },
91068
+ };
91069
+ }
91070
+ /**
91071
+ * World units covered by one screen pixel at the given point (exact for an
91072
+ * orthographic camera; at the point's distance for a perspective camera).
91073
+ */
91074
+ function worldPerPixel(camera, point, height) {
91075
+ if (height <= 0)
91076
+ return 1;
91077
+ if (camera instanceof OrthographicCamera) {
91078
+ return (camera.top - camera.bottom) / camera.zoom / height;
91079
+ }
91080
+ if (camera instanceof PerspectiveCamera) {
91081
+ const dist = camera.position.distanceTo(point);
91082
+ const halfFov = MathUtils.degToRad(camera.fov) / 2;
91083
+ return (2 * dist * Math.tan(halfFov)) / camera.zoom / height;
91084
+ }
91085
+ return 1;
91086
+ }
91087
+ function replaceOrThrow(source, anchor, replacement, where) {
91088
+ if (!source.includes(anchor)) {
91089
+ throw new Error(`${where}: shader anchor "${anchor}" not found`);
91090
+ }
91091
+ return source.replace(anchor, replacement);
91092
+ }
91093
+ /**
91094
+ * Patch a cap quad material to draw section hatching. `index` is the solid's index
91095
+ * among the caps of its plane; it selects the hatch direction and spacing. `capId`
91096
+ * is the cap's unique id color for the outline id pass (see `capIdColor`).
91097
+ */
91098
+ function patchHatchMaterial(material, uniforms, index, capId) {
91099
+ if (material.userData.hatchPatched === true)
91100
+ return;
91101
+ material.userData.hatchPatched = true;
91102
+ const variant = HATCH_VARIANTS[index % HATCH_VARIANTS.length];
91103
+ const uHatchAngle = { value: variant.angle };
91104
+ const uHatchScale = { value: variant.scale };
91105
+ const uCapId = { value: capId };
91106
+ const prev = material.onBeforeCompile;
91107
+ material.onBeforeCompile = (shader, renderer) => {
91108
+ prev.call(material, shader, renderer);
91109
+ shader.uniforms.uHatchSpacing = uniforms.uHatchSpacing;
91110
+ shader.uniforms.uCapHalfSize = uniforms.uCapHalfSize;
91111
+ shader.uniforms.uHatchLineWidth = uniforms.uHatchLineWidth;
91112
+ shader.uniforms.uHatchOn = uniforms.uHatchOn;
91113
+ shader.uniforms.uHatchAngle = uHatchAngle;
91114
+ shader.uniforms.uHatchScale = uHatchScale;
91115
+ shader.uniforms.uCapIdPass = uniforms.uCapIdPass;
91116
+ shader.uniforms.uCapId = uCapId;
91117
+ shader.vertexShader =
91118
+ "uniform float uCapHalfSize;\nvarying vec2 vTcvCapUV;\n" +
91119
+ replaceOrThrow(shader.vertexShader, "#include <begin_vertex>", "#include <begin_vertex>\n vTcvCapUV = position.xy * uCapHalfSize;", "patchHatchMaterial");
91120
+ shader.fragmentShader =
91121
+ "uniform float uHatchSpacing;\nuniform float uHatchLineWidth;\nuniform float uHatchOn;\n" +
91122
+ "uniform float uHatchAngle;\nuniform float uHatchScale;\nvarying vec2 vTcvCapUV;\n" +
91123
+ "uniform float uCapIdPass;\nuniform vec3 uCapId;\n" +
91124
+ shader.fragmentShader;
91125
+ // Hatch the unlit base color, before lighting: the ink (dark lines on light
91126
+ // parts, light lines on dark parts) is then fixed per part, and lines and cap
91127
+ // darken together when the cap turns away from the light.
91128
+ shader.fragmentShader = replaceOrThrow(shader.fragmentShader, "#include <color_fragment>",
91129
+ /* glsl */ `#include <color_fragment>
91130
+ if ( uHatchOn > 0.5 ) {
91131
+ vec2 tcvAcross = vec2( - sin( uHatchAngle ), cos( uHatchAngle ) );
91132
+ float t = dot( vTcvCapUV, tcvAcross ) / max( uHatchSpacing * uHatchScale, 1e-9 );
91133
+ float tw = max( fwidth( t ), 1e-6 );
91134
+ float dpx = ( 0.5 - abs( fract( t ) - 0.5 ) ) / tw;
91135
+ float line = 1.0 - smoothstep( 0.5 * uHatchLineWidth - 0.5, 0.5 * uHatchLineWidth + 0.5, dpx );
91136
+ // Seen edge-on the lines crowd below a few pixels apart and would merge into
91137
+ // solid ink: fade them out between 4 and 2 px spacing (1 / tw = px per line).
91138
+ line *= smoothstep( 2.0, 4.0, 1.0 / tw );
91139
+ float lum = dot( diffuseColor.rgb, vec3( 0.2126, 0.7152, 0.0722 ) );
91140
+ vec3 ink = lum > 0.2 ? diffuseColor.rgb * 0.3 : mix( diffuseColor.rgb, vec3( 1.0 ), 0.6 );
91141
+ diffuseColor.rgb = mix( diffuseColor.rgb, ink, line );
91142
+ }`, "patchHatchMaterial");
91143
+ shader.fragmentShader = replaceOrThrow(shader.fragmentShader, "#include <opaque_fragment>", `#include <opaque_fragment>
91144
+ if ( uCapIdPass > 0.5 ) gl_FragColor = vec4( uCapId, 1.0 );`, "patchHatchMaterial");
91145
+ };
91146
+ material.needsUpdate = true;
91147
+ }
91148
+
91149
+ /**
91150
+ * Screen-space outline of the clip caps (CAD mode).
91151
+ *
91152
+ * The caps carry no geometry of their own outline, and the faces next to a cut may
91153
+ * face away from the camera or belong to a touching solid, so the outline is found
91154
+ * in screen space instead:
91155
+ *
91156
+ * 1. Id pass into an offscreen target (color + depth + stencil):
91157
+ * - visible faces as black occluders (face pick layer + override material), so a
91158
+ * cap hidden behind another part gets no outline; face pixels within the line
91159
+ * width of a clip plane write {@link CUT_EDGE_ID} instead, which draws the cut
91160
+ * contour on the faces themselves (needed when the caps are behind the faces),
91161
+ * - the stencil meshes and caps (on {@link CAP_LAYER}) with each cap writing its
91162
+ * own id instead of its shaded color — the same stencil sequence as the main
91163
+ * render, since three orders them identically (material creation order).
91164
+ * 2. Composite over the canvas: a pixel is drawn in the edge color when its id is
91165
+ * larger than a neighbour's id, which yields a line on one side of every boundary
91166
+ * cap↔cap, cap↔surface and cap↔background. Cut-edge pixels are the largest id, so
91167
+ * where they meet a cap only they are drawn — one line, not two.
91168
+ */
91169
+ /** Render layer of the clip stencil meshes and cap quads (pick layers use 1-3). */
91170
+ const CAP_LAYER = 4;
91171
+ /** Id of face pixels on the cut contour (larger than any cap id). */
91172
+ const CUT_EDGE_ID = 0xffffff;
91173
+ /** Encode a cap id (1..2^24-1) as an exact 8-bit RGB color (0 = no cap). */
91174
+ function capIdColor(id) {
91175
+ return new Vector3((id & 0xff) / 255, ((id >> 8) & 0xff) / 255, ((id >> 16) & 0xff) / 255);
91176
+ }
91177
+ // Occluder: a face fragment lies on the cut contour when it is within uCutWidth
91178
+ // pixels of a clip plane that bounds the visible part, mirroring three's
91179
+ // clipping_planes_fragment (kept fragments have d >= 0). Skipped where the face is
91180
+ // (nearly) parallel to the plane: there d barely changes across the pixel, and a
91181
+ // face lying in the plane would otherwise become one big edge.
91182
+ const CUT_EDGE_GLSL = /* glsl */ `
91183
+ bool tcvCut = false;
91184
+ #if NUM_CLIPPING_PLANES > 0
91185
+ {
91186
+ float tcvPosGrad = length( fwidth( vClipPosition ) );
91187
+ float tcvD[ NUM_CLIPPING_PLANES ];
91188
+ bool tcvNear[ NUM_CLIPPING_PLANES ];
91189
+ for ( int i = 0; i < NUM_CLIPPING_PLANES; i ++ ) {
91190
+ vec4 p = clippingPlanes[ i ];
91191
+ float d = p.w - dot( vClipPosition, p.xyz );
91192
+ // Step of d per pixel along the dominant screen axis — the same 1-pixel
91193
+ // convention as the composite's horizontal/vertical neighbour test.
91194
+ float g = max( abs( dFdx( d ) ), abs( dFdy( d ) ) );
91195
+ tcvD[ i ] = d;
91196
+ tcvNear[ i ] = g > 0.05 * tcvPosGrad && d >= 0.0 && d < uCutWidth * g;
91197
+ }
91198
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
91199
+ tcvCut = tcvCut || tcvNear[ i ];
91200
+ }
91201
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
91202
+ // Intersection planes: plane i bounds the visible part only where every
91203
+ // other intersection plane clips.
91204
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
91205
+ bool othersClip = true;
91206
+ for ( int j = UNION_CLIPPING_PLANES; j < NUM_CLIPPING_PLANES; j ++ ) {
91207
+ if ( j != i && tcvD[ j ] >= 0.0 ) othersClip = false;
91208
+ }
91209
+ if ( othersClip && tcvNear[ i ] ) tcvCut = true;
91210
+ }
91211
+ #endif
91212
+ }
91213
+ #endif
91214
+ `;
91215
+ const COMPOSITE_VERTEX = /* glsl */ `
91216
+ varying vec2 vUv;
91217
+ void main() {
91218
+ vUv = uv;
91219
+ gl_Position = vec4( position.xy, 0.0, 1.0 );
91220
+ }
91221
+ `;
91222
+ const COMPOSITE_FRAGMENT = /* glsl */ `
91223
+ uniform sampler2D tId;
91224
+ uniform vec2 uTexel;
91225
+ uniform float uWidth;
91226
+ uniform vec3 uColor;
91227
+ varying vec2 vUv;
91228
+
91229
+ float idAt( vec2 uv ) {
91230
+ vec3 c = floor( texture2D( tId, uv ).rgb * 255.0 + 0.5 );
91231
+ return c.r + 256.0 * c.g + 65536.0 * c.b;
91232
+ }
91233
+
91234
+ void main() {
91235
+ float c = idAt( vUv );
91236
+ bool edge = c == ${CUT_EDGE_ID.toFixed(1)};
91237
+ for ( int k = 1; k <= 4; k ++ ) {
91238
+ if ( float( k ) > uWidth ) break;
91239
+ vec2 o = uTexel * float( k );
91240
+ edge = edge
91241
+ || c > idAt( vUv + vec2( o.x, 0.0 ) ) || c > idAt( vUv - vec2( o.x, 0.0 ) )
91242
+ || c > idAt( vUv + vec2( 0.0, o.y ) ) || c > idAt( vUv - vec2( 0.0, o.y ) );
91243
+ }
91244
+ if ( ! edge ) discard;
91245
+ gl_FragColor = vec4( uColor, 1.0 );
91246
+ #include <colorspace_fragment>
91247
+ }
91248
+ `;
91249
+ class CapOutlinePass {
91250
+ constructor() {
91251
+ this.target = null;
91252
+ /** Width of the cut contour on the faces, in device pixels (= outline width). */
91253
+ this.cutWidth = { value: 1 };
91254
+ this.size = new Vector2();
91255
+ this.savedClearColor = new Color();
91256
+ this.savedViewport = new Vector4();
91257
+ // One depth unit behind the caps (polygonOffset 1/1), so a face coplanar with a
91258
+ // cap does not hide it; same slope factor, so steep faces in front still occlude.
91259
+ this.occluder = new MeshBasicMaterial({
91260
+ color: 0x000000,
91261
+ side: DoubleSide,
91262
+ polygonOffset: true,
91263
+ polygonOffsetFactor: 1,
91264
+ polygonOffsetUnits: 2,
91265
+ });
91266
+ this.occluder.onBeforeCompile = (shader) => {
91267
+ const clipAnchor = "#include <clipping_planes_fragment>";
91268
+ const opaqueAnchor = "#include <opaque_fragment>";
91269
+ for (const anchor of [clipAnchor, opaqueAnchor]) {
91270
+ if (!shader.fragmentShader.includes(anchor)) {
91271
+ throw new Error(`CapOutlinePass: shader anchor "${anchor}" not found`);
91272
+ }
91273
+ }
91274
+ shader.uniforms.uCutWidth = this.cutWidth;
91275
+ shader.fragmentShader =
91276
+ "uniform float uCutWidth;\n" +
91277
+ shader.fragmentShader
91278
+ .replace(clipAnchor, `${clipAnchor}\n${CUT_EDGE_GLSL}`)
91279
+ .replace(opaqueAnchor, `${opaqueAnchor}\n if ( tcvCut ) gl_FragColor = vec4( 1.0 );`);
91280
+ };
91281
+ this.composite = new ShaderMaterial({
91282
+ uniforms: {
91283
+ tId: { value: null },
91284
+ uTexel: { value: new Vector2(1, 1) },
91285
+ uWidth: { value: 1 },
91286
+ uColor: { value: new Color() },
91287
+ },
91288
+ vertexShader: COMPOSITE_VERTEX,
91289
+ fragmentShader: COMPOSITE_FRAGMENT,
91290
+ depthTest: false,
91291
+ depthWrite: false,
91292
+ });
91293
+ this.quad = new Mesh(new PlaneGeometry(2, 2), this.composite);
91294
+ this.quad.frustumCulled = false;
91295
+ this.quadScene = new Scene();
91296
+ this.quadScene.add(this.quad);
91297
+ this.quadCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
91298
+ }
91299
+ ensureTarget(width, height) {
91300
+ if (this.target === null) {
91301
+ this.target = new WebGLRenderTarget(width, height, {
91302
+ minFilter: NearestFilter,
91303
+ magFilter: NearestFilter,
91304
+ generateMipmaps: false,
91305
+ depthBuffer: true,
91306
+ stencilBuffer: true,
91307
+ });
91308
+ }
91309
+ else if (this.target.width !== width || this.target.height !== height) {
91310
+ this.target.setSize(width, height);
91311
+ }
91312
+ return this.target;
91313
+ }
91314
+ /**
91315
+ * Render the id pass and draw the outline over the current (canvas) framebuffer.
91316
+ * Call right after the main scene render.
91317
+ */
91318
+ render(renderer, scene, camera, options) {
91319
+ renderer.getDrawingBufferSize(this.size);
91320
+ const width = Math.floor(this.size.x);
91321
+ const height = Math.floor(this.size.y);
91322
+ if (width < 1 || height < 1)
91323
+ return;
91324
+ const target = this.ensureTarget(width, height);
91325
+ // Line width in device pixels, shared by the cut contour and the cap outline.
91326
+ const lineWidth = Math.max(1, Math.round(renderer.getPixelRatio()));
91327
+ this.cutWidth.value = lineWidth;
91328
+ const savedMask = camera.layers.mask;
91329
+ const savedOverride = scene.overrideMaterial;
91330
+ const savedBackground = scene.background;
91331
+ const savedTarget = renderer.getRenderTarget();
91332
+ const savedAutoClear = renderer.autoClear;
91333
+ const savedAlpha = renderer.getClearAlpha();
91334
+ renderer.getClearColor(this.savedClearColor);
91335
+ renderer.getViewport(this.savedViewport);
91336
+ try {
91337
+ renderer.autoClear = false;
91338
+ scene.background = null;
91339
+ renderer.setRenderTarget(target);
91340
+ renderer.setClearColor(0x000000, 0); // id 0 = no cap
91341
+ renderer.clear(true, true, true);
91342
+ if (options.occlude) {
91343
+ this.occluder.clippingPlanes = options.planes;
91344
+ this.occluder.clipIntersection = options.intersection;
91345
+ camera.layers.set(PICK_LAYER.FACE);
91346
+ scene.overrideMaterial = this.occluder;
91347
+ renderer.render(scene, camera);
91348
+ scene.overrideMaterial = savedOverride;
91349
+ }
91350
+ options.setCapIdPass(true);
91351
+ try {
91352
+ camera.layers.set(CAP_LAYER);
91353
+ renderer.render(scene, camera);
91354
+ }
91355
+ finally {
91356
+ options.setCapIdPass(false);
91357
+ }
91358
+ renderer.setRenderTarget(savedTarget);
91359
+ renderer.setViewport(this.savedViewport);
91360
+ const u = this.composite.uniforms;
91361
+ u.tId.value = target.texture;
91362
+ u.uTexel.value.set(1 / width, 1 / height);
91363
+ u.uWidth.value = lineWidth;
91364
+ u.uColor.value.set(options.color);
91365
+ renderer.render(this.quadScene, this.quadCamera);
91366
+ }
91367
+ finally {
91368
+ camera.layers.mask = savedMask;
91369
+ scene.overrideMaterial = savedOverride;
91370
+ scene.background = savedBackground;
91371
+ renderer.setRenderTarget(savedTarget);
91372
+ renderer.setClearColor(this.savedClearColor, savedAlpha);
91373
+ renderer.setViewport(this.savedViewport);
91374
+ renderer.autoClear = savedAutoClear;
91375
+ }
91376
+ }
91377
+ dispose() {
91378
+ this.target?.dispose();
91379
+ this.target = null;
91380
+ this.occluder.dispose();
91381
+ this.composite.dispose();
91382
+ this.quad.geometry.dispose();
91383
+ }
91384
+ }
91385
+
90971
91386
  // ============================================================================
90972
91387
  // Constants
90973
91388
  // ============================================================================
@@ -91220,6 +91635,9 @@ float metalnessFactor = metalness;
91220
91635
  super();
91221
91636
  /** Per-solid stencil/cap units, the unit of screen-size culling. */
91222
91637
  this._capUnits = [];
91638
+ /** Shared uniforms of the section hatching on all cap quads. */
91639
+ this._hatchUniforms = createHatchUniforms(1);
91640
+ this._hatchCenter = new Vector3();
91223
91641
  /**
91224
91642
  * Whether {@link cull} last ran with clipping active. Lets the inactive path
91225
91643
  * gate stencils/caps off exactly once, then early-return on later still frames.
@@ -91283,6 +91701,10 @@ float metalnessFactor = metalness;
91283
91701
  mesh.material.visible = flag;
91284
91702
  }
91285
91703
  };
91704
+ /** Switch all cap materials between shaded output and outline id output. */
91705
+ this.setCapIdPass = (flag) => {
91706
+ this._hatchUniforms.uCapIdPass.value = flag ? 1 : 0;
91707
+ };
91286
91708
  this.center = center;
91287
91709
  this.distance = size / 2;
91288
91710
  this.onNormalChange = options.onNormalChange || null;
@@ -91345,11 +91767,16 @@ float metalnessFactor = metalness;
91345
91767
  _createStencils(center, size, theme) {
91346
91768
  this._planeMeshGroup = new PlaneMeshGroup();
91347
91769
  this._planeMeshGroup.name = "PlaneMeshes";
91770
+ // Cap quads are PlaneGeometry(2, 2) scaled by size/2 (PlaneMesh.updateMatrixWorld).
91771
+ this._hatchUniforms.uCapHalfSize.value = 0.5 * size;
91772
+ this._hatchCenter.set(center[0], center[1], center[2]);
91348
91773
  // Group the per-(solid,plane) units by solid for screen-size culling. The
91349
91774
  // loop below is plane-major (and `objectColors`/`_planeMeshGroup` order must
91350
91775
  // stay plane-major for setObjectColorCaps), so accumulate into a Map keyed by
91351
91776
  // solid and flatten afterwards — without touching the plane-major structures.
91352
91777
  const unitsBySolid = new Map();
91778
+ // Unique id per cap quad (plane × solid) for the cap outline id pass; 0 = none.
91779
+ let capId = 0;
91353
91780
  for (let i = 0; i < 3; i++) {
91354
91781
  const plane = this.clipPlanes[i];
91355
91782
  const otherPlanes = this.clipPlanes.filter((_, j) => j !== i);
@@ -91369,9 +91796,16 @@ float metalnessFactor = metalness;
91369
91796
  clippingGroup.add(createStencil(`frontStencil-${i}-${j}`, ClippingMaterials.createFrontStencilMaterial(), group.shapeGeometry, plane));
91370
91797
  clippingGroup.add(createStencil(`backStencil-${i}-${j}`, ClippingMaterials.createBackStencilMaterial(), group.shapeGeometry, plane));
91371
91798
  group.addClipping(clippingGroup, i);
91799
+ // The outline id pass renders the stencil sequence + caps on CAP_LAYER.
91800
+ for (const stencil of clippingGroup.children) {
91801
+ stencil.layers.enable(CAP_LAYER);
91802
+ }
91372
91803
  // Create stencil plane mesh
91373
91804
  const planeMaterial = ClippingMaterials.createStencilPlaneMaterial(PLANE_COLORS[theme][i], otherPlanes);
91805
+ capId++;
91806
+ patchHatchMaterial(planeMaterial, this._hatchUniforms, j, capIdColor(capId));
91374
91807
  const capMesh = new PlaneMesh(i, plane, center, size, planeMaterial, PLANE_COLORS[theme][i], `StencilPlane-${i}-${j}`);
91808
+ capMesh.layers.enable(CAP_LAYER);
91375
91809
  this._planeMeshGroup.add(capMesh);
91376
91810
  // Record the cull unit for this solid (one entry per solid, holding
91377
91811
  // its up-to-3 per-plane stencil groups + cap quads).
@@ -91436,6 +91870,10 @@ float metalnessFactor = metalness;
91436
91870
  this.clipPlanes[index].setConstant(value);
91437
91871
  this.reverseClipPlanes[index].setConstant(-value);
91438
91872
  }
91873
+ /** Whether any solid has clip caps (the cap outline pass has work to do). */
91874
+ get hasCaps() {
91875
+ return this._capUnits.length > 0;
91876
+ }
91439
91877
  /**
91440
91878
  * Bound the per-frame stencil/cap draw work to keep large assemblies from
91441
91879
  * overrunning the GPU watchdog on clip+rotate (see {@link CAP_CULL_MIN_PX}).
@@ -91470,6 +91908,9 @@ float metalnessFactor = metalness;
91470
91908
  return;
91471
91909
  }
91472
91910
  this._cullActive = true;
91911
+ // Keep the hatch spacing constant on screen (planes pass near the model center).
91912
+ this._hatchUniforms.uHatchSpacing.value =
91913
+ HATCH_SPACING_PX * worldPerPixel(camera, this._hatchCenter, height);
91473
91914
  // Camera right vector in world space = column 0 of the camera world matrix.
91474
91915
  camera.updateMatrixWorld();
91475
91916
  const e = camera.matrixWorld.elements;
@@ -97399,7 +97840,7 @@ float metalnessFactor = metalness;
97399
97840
  }
97400
97841
  }
97401
97842
 
97402
- const version = "5.0.7";
97843
+ const version = "5.1.0";
97403
97844
 
97404
97845
  /**
97405
97846
  * `PickedComponent` over a GPU id-pick result. Drives the shader
@@ -97625,6 +98066,58 @@ float metalnessFactor = metalness;
97625
98066
  this.setSelectionInput(false);
97626
98067
  this.setPickHandler(false);
97627
98068
  }
98069
+ /**
98070
+ * Pick the visible component under the cursor with the current topo filter, or
98071
+ * `null` when the cursor is off the canvas or over background.
98072
+ */
98073
+ pickUnderCursor() {
98074
+ if (this.host.idPicker === null || !this.idHoverInside)
98075
+ return null;
98076
+ const rect = this.host.renderer.domElement.getBoundingClientRect();
98077
+ const x = this.idHoverClientX - rect.left;
98078
+ const y = this.idHoverClientY - rect.top;
98079
+ if (x < 0 || y < 0 || x > rect.width || y > rect.height)
98080
+ return null;
98081
+ const topoFilter = pickerTopoFilter(this.host.display.shapeFilterDropDownMenu.currentFilter);
98082
+ const hit = this.host.idPicker.pickAt(x, y, topoFilter === undefined ? {} : { topoFilter });
98083
+ // The vertex/edge pick layers stay active even when the owning solid is hidden
98084
+ // (visibility lives on the mesh material, not the pick layer), so gate the pick on
98085
+ // visibility — otherwise a hidden component could be hovered AND selected.
98086
+ if (hit === null || !this.pickVisible(hit.info))
98087
+ return null;
98088
+ return hit;
98089
+ }
98090
+ /**
98091
+ * World-space point on the visible component under the cursor (same pick as the
98092
+ * hover), or `null` when there is none or the GPU lacks the position attachment.
98093
+ */
98094
+ pointUnderCursor() {
98095
+ if (!this.host.ready)
98096
+ return null;
98097
+ const hit = this.pickUnderCursor();
98098
+ if (hit === null || hit.point === null)
98099
+ return null;
98100
+ return hit.point.clone();
98101
+ }
98102
+ /**
98103
+ * Tree-row hover: HOVER the faces of the tree node at `path` (leaf or group), or
98104
+ * clear when `null`. Drops the canvas hover target first — otherwise the next
98105
+ * render's {@link handleIdHover} (cursor outside the canvas) would release that
98106
+ * stale target and wipe the tree hover with it.
98107
+ */
98108
+ setTreeHover(path) {
98109
+ if (!this.host.ready || this.host.studioActive)
98110
+ return;
98111
+ const highlight = this.host.rendered.nestedGroup?.highlight ?? null;
98112
+ if (highlight === null)
98113
+ return;
98114
+ this.releaseLastSelected();
98115
+ this.lastObject = null;
98116
+ this.host.display.setStatusLine("");
98117
+ highlight.setHoverPath(path);
98118
+ if (!this.host.hasAnimationLoop)
98119
+ this.host.update(true, false);
98120
+ }
97628
98121
  /**
97629
98122
  * Whether hover preselection (highlight + status line) is active. Disabled for GDS:
97630
98123
  * dense, stacked, instance-unrolled layout data where per-pixel hover flickers
@@ -97662,28 +98155,12 @@ float metalnessFactor = metalness;
97662
98155
  this.lastObject = null;
97663
98156
  this.host.display.setStatusLine("");
97664
98157
  };
97665
- if (!this.idHoverInside) {
97666
- release();
97667
- return;
97668
- }
97669
- const rect = this.host.renderer.domElement.getBoundingClientRect();
97670
- const x = this.idHoverClientX - rect.left;
97671
- const y = this.idHoverClientY - rect.top;
97672
- if (x < 0 || y < 0 || x > rect.width || y > rect.height) {
97673
- release();
97674
- return;
97675
- }
97676
- const filter = this.host.display.shapeFilterDropDownMenu.currentFilter;
97677
- const fromSolid = filter.includes(TopoFilter.solid);
97678
- const topoFilter = pickerTopoFilter(filter);
97679
- const hit = this.host.idPicker.pickAt(x, y, topoFilter === undefined ? {} : { topoFilter });
97680
- // The vertex/edge pick layers stay active even when the owning solid is hidden
97681
- // (visibility lives on the mesh material, not the pick layer), so gate the pick on
97682
- // visibility — otherwise a hidden component could be hovered AND selected.
97683
- if (hit === null || !this.pickVisible(hit.info)) {
98158
+ const hit = this.pickUnderCursor();
98159
+ if (hit === null) {
97684
98160
  release();
97685
98161
  return;
97686
98162
  }
98163
+ const fromSolid = this.host.display.shapeFilterDropDownMenu.currentFilter.includes(TopoFilter.solid);
97687
98164
  const picked = new IdPicked(hit.info, fromSolid, hit.point, highlight);
97688
98165
  if (!picked.equals(this.lastObject)) {
97689
98166
  this.releaseLastSelected();
@@ -108864,6 +109341,10 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
108864
109341
  // =============================================================================
108865
109342
  // IMPORTS
108866
109343
  // =============================================================================
109344
+ /** Decimals of a point copied with Ctrl/Cmd-C ({@link Viewer.copyPointUnderCursor}). */
109345
+ const COPY_POINT_DECIMALS = 4;
109346
+ /** Delay after the last camera change before the clip cap outline is drawn again. */
109347
+ const CAP_OUTLINE_SETTLE_MS = 150;
108867
109348
  /**
108868
109349
  * Type guard to check if an Object3D is an IndexedMesh.
108869
109350
  */
@@ -108974,6 +109455,14 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
108974
109455
  // GPU id-based picker. Created/attached per render() once the scene + compact
108975
109456
  // registry exist; drives hover, selection, measure and double-click pick.
108976
109457
  this.idPicker = null;
109458
+ /** Outline of the clip caps; created on first use, kept across renders. */
109459
+ this._capOutline = null;
109460
+ /** Camera world + projection matrix of the previous outline frame (motion test). */
109461
+ this._capOutlineCamera = [];
109462
+ /** Pending redraw that adds the outline once the camera has settled. */
109463
+ this._capOutlineSettle = null;
109464
+ /** Whether the attached animation has moved parts (Play pressed or time slider moved). */
109465
+ this._animationStarted = false;
108977
109466
  // ---------------------------------------------------------------------------
108978
109467
  // Render Loop & Scene Updates
108979
109468
  // ---------------------------------------------------------------------------
@@ -109122,6 +109611,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
109122
109611
  }
109123
109612
  else {
109124
109613
  this.renderer.render(this.rendered.scene, this.rendered.camera.getCamera());
109614
+ this._renderCapOutline();
109125
109615
  }
109126
109616
  this.cadTools.update();
109127
109617
  this.rendered.directLight.position.copy(this.rendered.camera.getCamera().position);
@@ -109375,6 +109865,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
109375
109865
  return;
109376
109866
  switch (btn) {
109377
109867
  case "play":
109868
+ this._animationStarted = true;
109378
109869
  if (this.clipAction.paused) {
109379
109870
  this.clipAction.paused = false;
109380
109871
  }
@@ -109508,6 +109999,10 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
109508
109999
  return;
109509
110000
  }
109510
110001
  };
110002
+ /** Tree-row hover: highlight the faces of the node at `path`, or clear on `null`. */
110003
+ this.handleTreeHover = (path) => {
110004
+ this.pickingController.setTreeHover(path);
110005
+ };
109511
110006
  /** Clear the current selection (and reset the select tool). */
109512
110007
  this.clearSelection = () => {
109513
110008
  this.pickingController.clearSelection();
@@ -110696,6 +111191,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110696
111191
  this.toggleAnimationLoop(true);
110697
111192
  }
110698
111193
  this.state.set("animationMode", label === "E" ? "explode" : "animation");
111194
+ this._animationStarted = false;
110699
111195
  this.clipAction = this.animation.animate(this.rendered.nestedGroup.rootGroup, duration, speed, repeat);
110700
111196
  // Reset animation slider to start
110701
111197
  this.state.set("animationSliderValue", 0);
@@ -110714,6 +111210,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110714
111210
  deepDispose(this.animation);
110715
111211
  }
110716
111212
  this.state.set("animationMode", "none");
111213
+ this._animationStarted = false;
110717
111214
  this.toggleAnimationLoop(false);
110718
111215
  }
110719
111216
  /**
@@ -110722,6 +111219,8 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110722
111219
  * @param fraction - relative time between 0 and 1.
110723
111220
  */
110724
111221
  setRelativeTime(fraction) {
111222
+ if (fraction !== 0)
111223
+ this._animationStarted = true;
110725
111224
  this.animation.setRelativeTime(fraction);
110726
111225
  this.state.set("animationSliderValue", fraction * 1000);
110727
111226
  }
@@ -110753,6 +111252,60 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110753
111252
  setTimeout(() => this.update(true, true), 50);
110754
111253
  }
110755
111254
  }
111255
+ /**
111256
+ * Draw the outline of the clip caps over the frame (Clip tab active only). Skipped
111257
+ * while the camera moves (drag, wheel, damping, preset views): the outline pass
111258
+ * renders faces and caps a second time, so it is drawn once the camera has been
111259
+ * still for {@link CAP_OUTLINE_SETTLE_MS}.
111260
+ */
111261
+ _renderCapOutline() {
111262
+ const clipping = this.rendered.clipping;
111263
+ if (!this.renderer.localClippingEnabled || !clipping.hasCaps)
111264
+ return;
111265
+ const camera = this.rendered.camera.getCamera();
111266
+ if (this._cameraMovedSinceLastOutline(camera)) {
111267
+ this._scheduleCapOutline();
111268
+ return;
111269
+ }
111270
+ if (this._capOutline === null)
111271
+ this._capOutline = new CapOutlinePass();
111272
+ const blackEdges = this.state.get("blackEdges") === true;
111273
+ this._capOutline.render(this.renderer, this.rendered.scene, camera, {
111274
+ planes: clipping.clipPlanes,
111275
+ intersection: this.state.get("clipIntersection") === true,
111276
+ occlude: this.state.get("transparent") !== true,
111277
+ color: blackEdges ? 0x000000 : this.state.get("edgeColor"),
111278
+ setCapIdPass: clipping.setCapIdPass,
111279
+ });
111280
+ }
111281
+ /** Whether the camera's world or projection matrix changed since the last call. */
111282
+ _cameraMovedSinceLastOutline(camera) {
111283
+ const now = [
111284
+ ...camera.matrixWorld.elements,
111285
+ ...camera.projectionMatrix.elements,
111286
+ ];
111287
+ const last = this._capOutlineCamera;
111288
+ const moved = last.length !== now.length || now.some((value, i) => value !== last[i]);
111289
+ this._capOutlineCamera = now;
111290
+ return moved;
111291
+ }
111292
+ /** Redraw once the camera has settled, so the skipped outline appears. */
111293
+ _scheduleCapOutline() {
111294
+ if (this._capOutlineSettle !== null)
111295
+ clearTimeout(this._capOutlineSettle);
111296
+ this._capOutlineSettle = setTimeout(() => {
111297
+ this._capOutlineSettle = null;
111298
+ if (this.ready)
111299
+ this.update(true, false);
111300
+ }, CAP_OUTLINE_SETTLE_MS);
111301
+ }
111302
+ /** Cancel a pending outline redraw. */
111303
+ _cancelCapOutline() {
111304
+ if (this._capOutlineSettle !== null)
111305
+ clearTimeout(this._capOutlineSettle);
111306
+ this._capOutlineSettle = null;
111307
+ this._capOutlineCamera = [];
111308
+ }
110756
111309
  // ---------------------------------------------------------------------------
110757
111310
  // Cleanup & Disposal
110758
111311
  // ---------------------------------------------------------------------------
@@ -110771,6 +111324,8 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110771
111324
  */
110772
111325
  dispose() {
110773
111326
  this.clear();
111327
+ this._capOutline?.dispose();
111328
+ this._capOutline = null;
110774
111329
  // Remove all picking listeners (they hold a strong ref to this Viewer via the
110775
111330
  // controller's arrow-field handlers; in external-canvas mode the caller owns the
110776
111331
  // canvas, so not removing them would leak the disposed Viewer).
@@ -110816,6 +111371,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110816
111371
  * @public
110817
111372
  */
110818
111373
  clear() {
111374
+ this._cancelCapOutline();
110819
111375
  if (this._rendered) {
110820
111376
  // Drop selection state + hover cache + status line — a PickedComponent may hold
110821
111377
  // a HighlightController / ObjectGroup that this clear() disposes; a stale
@@ -110937,7 +111493,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
110937
111493
  if (!this.tree) {
110938
111494
  throw new Error("Tree not initialized");
110939
111495
  }
110940
- const treeview = new TreeView(this.tree, this.display.cadTreeScrollContainer, this.setObject, this.handlePick, this.update, this.notifyStates, this.getNodeColor, this.state.get("theme"), this.state.get("newTreeBehavior"), false);
111496
+ const treeview = new TreeView(this.tree, this.display.cadTreeScrollContainer, this.setObject, this.handlePick, this.update, this.notifyStates, this.getNodeColor, this.state.get("theme"), this.state.get("newTreeBehavior"), false, this.handleTreeHover);
110941
111497
  this.display.clearCadTree();
110942
111498
  const t = treeview.create();
110943
111499
  timer.split("created tree");
@@ -111403,6 +111959,40 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
111403
111959
  get lastSelection() {
111404
111960
  return this.pickingController.lastSelection;
111405
111961
  }
111962
+ /**
111963
+ * Copy the world-space point under the cursor as `"x, y, z"` to the clipboard and
111964
+ * send it to the host as a `copiedPoint` notification (for hosts that block the
111965
+ * browser clipboard). Does nothing while parts may be displaced from their model
111966
+ * positions — explode mode, an animation once started (Play or time slider), a
111967
+ * z-scale other than 1 — or when no visible component is under the cursor.
111968
+ * @returns true when a point was copied (the caller then consumes the key event).
111969
+ */
111970
+ copyPointUnderCursor() {
111971
+ if (!this.ready)
111972
+ return false;
111973
+ const mode = this.state.get("animationMode");
111974
+ if (mode === "explode")
111975
+ return false;
111976
+ if (mode === "animation" && this._animationStarted)
111977
+ return false;
111978
+ if (this.zScale !== undefined && this.zScale !== 1)
111979
+ return false;
111980
+ const point = this.pickingController.pointUnderCursor();
111981
+ if (point === null)
111982
+ return false;
111983
+ const coords = toVector3Tuple(point.toArray());
111984
+ const fmt = (v) => {
111985
+ const s = v.toFixed(COPY_POINT_DECIMALS);
111986
+ return Number(s) === 0 ? (0).toFixed(COPY_POINT_DECIMALS) : s;
111987
+ };
111988
+ const text = coords.map(fmt).join(", ");
111989
+ copyText(text, this.display.container);
111990
+ if (this.notifyCallback !== null) {
111991
+ this.notifyCallback({ copiedPoint: { old: null, new: coords } });
111992
+ }
111993
+ this.display.setStatusLine(`copied: ${text}`);
111994
+ return true;
111995
+ }
111406
111996
  /** Enable/disable the double-click pick handler (on when no tool is active). */
111407
111997
  setPickHandler(flag) {
111408
111998
  this.pickingController.setPickHandler(flag);
@@ -111817,7 +112407,7 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
111817
112407
  this.tree = this.compactTree;
111818
112408
  // Dispose old treeview and create new one
111819
112409
  deepDispose(this.rendered.treeview);
111820
- const treeview = new TreeView(this.tree, this.display.cadTreeScrollContainer, this.setObject, this.handlePick, this.update, this.notifyStates, this.getNodeColor, this.state.get("theme"), this.state.get("newTreeBehavior"), false);
112410
+ const treeview = new TreeView(this.tree, this.display.cadTreeScrollContainer, this.setObject, this.handlePick, this.update, this.notifyStates, this.getNodeColor, this.state.get("theme"), this.state.get("newTreeBehavior"), false, this.handleTreeHover);
111821
112411
  this.rendered.treeview = treeview;
111822
112412
  this.display.clearCadTree();
111823
112413
  const t = treeview.create();
@@ -113376,6 +113966,33 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
113376
113966
  this._matEditorDragAbort = null;
113377
113967
  this._matEditorInputAbort = null;
113378
113968
  this._animWasVisible = false;
113969
+ /**
113970
+ * Ctrl/Cmd-C while the cursor is over the canvas copies the point under it.
113971
+ * Text-entry fields and selected text keep the normal copy.
113972
+ */
113973
+ this._handleCopyPoint = (e) => {
113974
+ if (!(e instanceof KeyboardEvent))
113975
+ return;
113976
+ if (!(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey)
113977
+ return;
113978
+ if (e.key.toLowerCase() !== "c")
113979
+ return;
113980
+ const target = e.target;
113981
+ if ((target instanceof HTMLInputElement &&
113982
+ target.type !== "button" &&
113983
+ target.type !== "checkbox") ||
113984
+ target instanceof HTMLTextAreaElement ||
113985
+ (target instanceof HTMLElement && target.isContentEditable)) {
113986
+ return;
113987
+ }
113988
+ const selection = window.getSelection();
113989
+ if (selection !== null && selection.toString() !== "")
113990
+ return;
113991
+ if (this.viewer.copyPointUnderCursor()) {
113992
+ e.preventDefault();
113993
+ e.stopPropagation();
113994
+ }
113995
+ };
113379
113996
  // ---------------------------------------------------------------------------
113380
113997
  // Toolbar Button Handlers: View Settings
113381
113998
  // ---------------------------------------------------------------------------
@@ -114698,6 +115315,10 @@ void mainImage(const in vec4 inputColor, const in vec2 uv, const in float depth,
114698
115315
  // Focus handling for keyboard shortcuts
114699
115316
  listeners.add(this.container, "mousedown", () => this.container.focus());
114700
115317
  listeners.add(this.container, "keydown", this._handleKeyboardShortcut);
115318
+ // Ctrl/Cmd-C acts on the point under the cursor, so it must not depend on the
115319
+ // viewer having focus (e.g. after using a host dropdown). Capture phase: runs
115320
+ // before host shortcuts; the key is consumed only when a point was copied.
115321
+ listeners.add(document, "keydown", this._handleCopyPoint, true);
114701
115322
  }
114702
115323
  /**
114703
115324
  * Subscribe to ViewerState changes to keep UI in sync.