@playcanvas/supersplat-viewer 1.36.0 → 1.36.2

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/viewer.css CHANGED
@@ -893,14 +893,12 @@
893
893
  overflow-wrap: break-word;
894
894
  visibility: hidden;
895
895
  opacity: 0;
896
- translate: 0 4px;
897
- transition: visibility 0s 0.2s, opacity 0.2s ease-out, translate 0.2s ease-out;
896
+ transition: visibility 0s 0.2s, opacity 0.2s ease-out;
898
897
  }
899
898
  .sse-viewer .sse-annotations > .sse-annotation.sse-visible {
900
899
  visibility: visible;
901
900
  opacity: 1;
902
- translate: 0 0;
903
- transition: opacity 0.2s ease-out, translate 0.2s ease-out;
901
+ transition: opacity 0.2s ease-out;
904
902
  }
905
903
  .sse-viewer .sse-annotations > .sse-annotation > .sse-annotation-title {
906
904
  font-size: 13px;
package/dist/viewer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, Vec3, Script, Entity, Mat4, version as version$1, Quat, math, Pose, OrbitController as OrbitController$1, Vec2, ShaderUtils, Texture, ADDRESS_CLAMP_TO_EDGE, FILTER_LINEAR, PIXELFORMAT_RGBA8, RenderTarget, ASPECT_AUTO, BlendState, drawQuadWithShader, Vec4, Color, PROJECTION_ORTHOGRAPHIC, ShaderChunks, FILTER_NEAREST, PIXELFORMAT_RGBA16F, RenderPassPicker, BLENDEQUATION_MIN, BLENDMODE_ONE, ShaderMaterial, CULLFACE_NONE, BLEND_NONE, PIXELFORMAT_R32F, PIXELFORMAT_R16F, PROJECTION_PERSPECTIVE, GamepadSource, KeyboardMouseSource, MultiTouchSource, InputFrame, Mesh, PRIMITIVE_TRIANGLES, Layer, SORTMODE_MANUAL, CULLFACE_BACK, BLEND_NORMAL, MeshInstance, FUNC_EQUAL, StandardMaterial, FUNC_LESSEQUAL, RENDERSTYLE_WIREFRAME, PIXELFORMAT_RGBA32F, SAMPLETYPE_UNFILTERABLE_FLOAT, SHADERLANGUAGE_WGSL, Frustum, BoundingSphere, StorageBuffer, BUFFERUSAGE_COPY_DST, Compute, BUFFERUSAGE_COPY_SRC, BindGroupFormat, BindStorageBufferFormat, BindUniformBufferFormat, SHADERSTAGE_COMPUTE, Shader, UniformBufferFormat, UniformFormat, UNIFORMTYPE_UINT, BindTextureFormat, TEXTUREDIMENSION_2D, SAMPLETYPE_DEPTH, PIXELFORMAT_DEPTH, GraphNode, PIXELFORMAT_RGBA16U, PIXELFORMAT_R32U, BLEND_PREMULTIPLIED, Camera as Camera$1, UNIFORMTYPE_MAT4, UNIFORMTYPE_VEC4, UNIFORMTYPE_VEC2, UNIFORMTYPE_FLOAT, RenderPass, SHADER_FORWARD, BindStorageTextureFormat, DEVICETYPE_WEBGL2, platform, BoundingBox, GSPLAT_LODMODE_DISTANCE, GSPLAT_DEBUG_LOD, GSPLAT_DEBUG_NONE, MiniStats, CameraFrame, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_FILMIC, TONEMAP_LINEAR, TONEMAP_NONE, GSPLAT_RENDERER_RASTER_GPU_SORT, GSPLAT_RENDERER_RASTER_CPU_SORT, revision, EventHandler, createGraphicsDevice, Keyboard, TouchDevice as TouchDevice$1, Mouse } from 'playcanvas';
1
+ import { AppBase, AppOptions, CameraComponentSystem, LightComponentSystem, RenderComponentSystem, GSplatComponentSystem, ScriptComponentSystem, ContainerHandler, TextureHandler, GSplatHandler, BinaryHandler, XrManager, Asset, SEMANTIC_POSITION, INDEXFORMAT_UINT32, Vec3, PROJECTION_PERSPECTIVE, math, Script, Entity, Mat4, version as version$1, Quat, Pose, OrbitController as OrbitController$1, Vec2, ShaderUtils, Texture, ADDRESS_CLAMP_TO_EDGE, FILTER_LINEAR, PIXELFORMAT_RGBA8, RenderTarget, ASPECT_AUTO, BlendState, drawQuadWithShader, Vec4, Color, PROJECTION_ORTHOGRAPHIC, ShaderChunks, FILTER_NEAREST, PIXELFORMAT_RGBA16F, RenderPassPicker, BLENDEQUATION_MIN, BLENDMODE_ONE, ShaderMaterial, CULLFACE_NONE, BLEND_NONE, PIXELFORMAT_R32F, PIXELFORMAT_R16F, GamepadSource, KeyboardMouseSource, MultiTouchSource, InputFrame, Mesh, PRIMITIVE_TRIANGLES, Layer, SORTMODE_MANUAL, CULLFACE_BACK, BLEND_NORMAL, MeshInstance, FUNC_EQUAL, StandardMaterial, FUNC_LESSEQUAL, RENDERSTYLE_WIREFRAME, PIXELFORMAT_RGBA32F, SAMPLETYPE_UNFILTERABLE_FLOAT, SHADERLANGUAGE_WGSL, Frustum, BoundingSphere, StorageBuffer, BUFFERUSAGE_COPY_DST, Compute, BUFFERUSAGE_COPY_SRC, BindGroupFormat, BindStorageBufferFormat, BindUniformBufferFormat, SHADERSTAGE_COMPUTE, Shader, UniformBufferFormat, UniformFormat, UNIFORMTYPE_UINT, BindTextureFormat, TEXTUREDIMENSION_2D, SAMPLETYPE_DEPTH, PIXELFORMAT_DEPTH, GraphNode, PIXELFORMAT_RGBA16U, PIXELFORMAT_R32U, BLEND_PREMULTIPLIED, Camera as Camera$1, UNIFORMTYPE_MAT4, UNIFORMTYPE_VEC4, UNIFORMTYPE_VEC2, UNIFORMTYPE_FLOAT, RenderPass, SHADER_FORWARD, BindStorageTextureFormat, DEVICETYPE_WEBGL2, platform, BoundingBox, GSPLAT_LODMODE_DISTANCE, GSPLAT_DEBUG_LOD, GSPLAT_DEBUG_NONE, MiniStats, CameraFrame, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_FILMIC, TONEMAP_LINEAR, TONEMAP_NONE, GSPLAT_RENDERER_RASTER_GPU_SORT, GSPLAT_RENDERER_RASTER_CPU_SORT, revision, EventHandler, createGraphicsDevice, Keyboard, TouchDevice as TouchDevice$1, Mouse } from 'playcanvas';
2
2
  import { XrControllers } from 'playcanvas/scripts/esm/xr/xr-controllers.mjs';
3
3
  import { XrNavigation } from 'playcanvas/scripts/esm/xr/xr-navigation.mjs';
4
4
 
@@ -2558,7 +2558,7 @@ const importSettings = (settings) => {
2558
2558
  return result;
2559
2559
  };
2560
2560
 
2561
- var version = "1.36.0";
2561
+ var version = "1.36.2";
2562
2562
 
2563
2563
  class Tooltip {
2564
2564
  register;
@@ -2723,6 +2723,58 @@ const initAnnotationControls = (viewer, root) => {
2723
2723
  };
2724
2724
  };
2725
2725
 
2726
+ /**
2727
+ * Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
2728
+ * pixel offsets that already scale with frame time. This factor converts
2729
+ * rate-based speed constants (tuned for degrees-per-second) to work with
2730
+ * per-frame displacements, making them frame-rate-independent.
2731
+ */
2732
+ const DISPLACEMENT_SCALE = 1 / 60;
2733
+ /** Maximum accumulated touch movement (px) to still count as a tap. */
2734
+ const TAP_EPSILON = 15;
2735
+ const tmpHalfSize = new Vec3();
2736
+ /**
2737
+ * Converts screen-space pixel deltas to a world-space pan vector at the
2738
+ * given depth.
2739
+ *
2740
+ * @param camera - The camera component.
2741
+ * @param dx - Horizontal pixel delta.
2742
+ * @param dy - Vertical pixel delta.
2743
+ * @param dz - Depth (world-space) at which to project the delta.
2744
+ * @param out - Optional output vector.
2745
+ * @returns The pan vector in world space.
2746
+ */
2747
+ const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
2748
+ const { system, fov, aspectRatio, horizontalFov, projection, orthoHeight } = camera;
2749
+ const { width, height } = system.app.graphicsDevice.clientRect;
2750
+ out.set(-(dx / width) * 2, (dy / height) * 2, 0);
2751
+ const halfSize = tmpHalfSize.set(0, 0, 0);
2752
+ if (projection === PROJECTION_PERSPECTIVE) {
2753
+ const halfSlice = dz * Math.tan(0.5 * fov * math.DEG_TO_RAD);
2754
+ if (horizontalFov) {
2755
+ halfSize.set(halfSlice, halfSlice / aspectRatio, 0);
2756
+ }
2757
+ else {
2758
+ halfSize.set(halfSlice * aspectRatio, halfSlice, 0);
2759
+ }
2760
+ }
2761
+ else {
2762
+ halfSize.set(orthoHeight * aspectRatio, orthoHeight, 0);
2763
+ }
2764
+ out.mul(halfSize);
2765
+ return out;
2766
+ };
2767
+ /**
2768
+ * The orbit camera and the fly camera disagree on the sign of the z-axis
2769
+ * for forward motion. Apply this when emitting a forward/back z-component
2770
+ * so the same wheel-style delta drives both cameras correctly.
2771
+ *
2772
+ * @param mode - The current camera mode.
2773
+ * @param z - The raw forward/back z-component.
2774
+ * @returns The z-component flipped for orbit mode, unchanged otherwise.
2775
+ */
2776
+ const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
2777
+
2726
2778
  const vec$1 = new Vec3();
2727
2779
  /**
2728
2780
  * A script for creating interactive 3D annotations in a scene. Each annotation consists of:
@@ -2798,8 +2850,9 @@ class Annotation extends Script {
2798
2850
  }
2799
2851
  /**
2800
2852
  * Update the screen-space elements for this annotation. Called each frame from the
2801
- * prerender callback, and also directly from showTooltip to ensure the tooltip is positioned
2802
- * correctly even when the camera hasn't moved (e.g. annotations sharing the same camera pose).
2853
+ * prerender callback, and also directly from revealTooltip to ensure the tooltip is
2854
+ * positioned correctly even when the camera hasn't moved (e.g. annotations sharing the same
2855
+ * camera pose).
2803
2856
  * @private
2804
2857
  */
2805
2858
  _update() {
@@ -2827,16 +2880,33 @@ class Annotation extends Script {
2827
2880
  this.hotspotDom.classList.toggle('sse-occluded', occluded);
2828
2881
  }
2829
2882
  /**
2883
+ * Make this the annotation whose tooltip shows. The tooltip itself waits for the camera to
2884
+ * near the end of its move here, when `Annotations` calls `revealTooltip`, rather than
2885
+ * chasing the hotspot across the screen during the flight.
2830
2886
  * @private
2831
2887
  */
2832
2888
  showTooltip() {
2833
2889
  const ctx = this.context;
2834
2890
  ctx.activeAnnotation = this;
2835
- ctx.titleDom.textContent = this.title;
2836
- ctx.textDom.textContent = this.text;
2837
- ctx.tooltipDom.classList.add('sse-visible');
2891
+ ctx.revealed = false;
2838
2892
  this.hotspotDom.classList.add('sse-active');
2839
- // Immediately update incase the camera doesn't move
2893
+ }
2894
+ /**
2895
+ * Show the tooltip beside this annotation, the camera being at or nearly at rest.
2896
+ * @private
2897
+ */
2898
+ revealTooltip() {
2899
+ const ctx = this.context;
2900
+ ctx.revealed = true;
2901
+ if (ctx.tooltipOwner !== this) {
2902
+ // taken over only now, so the tooltip fades out with the previous annotation's text,
2903
+ // beside its hotspot; and with no side yet, rather than the one it left it on
2904
+ ctx.tooltipOwner = this;
2905
+ ctx.titleDom.textContent = this.title;
2906
+ ctx.textDom.textContent = this.text;
2907
+ ctx.tooltipDom.classList.remove('sse-arrow-left', 'sse-arrow-right');
2908
+ }
2909
+ // the camera may be still, so no prerender may follow
2840
2910
  this._update();
2841
2911
  }
2842
2912
  /**
@@ -2854,7 +2924,7 @@ class Annotation extends Script {
2854
2924
  */
2855
2925
  _hideElements() {
2856
2926
  this.hotspotDom.style.display = 'none';
2857
- if (this.context.activeAnnotation === this) {
2927
+ if (this.context.tooltipOwner === this) {
2858
2928
  this.context.tooltipDom.classList.remove('sse-visible');
2859
2929
  }
2860
2930
  }
@@ -2873,28 +2943,43 @@ class Annotation extends Script {
2873
2943
  // nearer hotspots draw over farther ones
2874
2944
  hotspot.style.zIndex = String(Math.round(100000 / (1 + distance)));
2875
2945
  const ctx = this.context;
2876
- if (ctx.activeAnnotation !== this) {
2946
+ if (ctx.tooltipOwner !== this) {
2877
2947
  return;
2878
2948
  }
2879
- // Re-show tooltip if it was hidden while behind camera
2949
+ // Shown while this annotation is selected and revealed, clamped to the canvas when the
2950
+ // hotspot is beyond it, so moving the camera yourself does not lose it. Hidden, it fades
2951
+ // out, moving with the hotspot at the offset it last had rather than standing still while
2952
+ // the camera moves on
2880
2953
  const tooltip = ctx.tooltipDom;
2881
- tooltip.classList.add('sse-visible');
2882
- // Position tooltip, clamped to the canvas (screenPos is in canvas pixels)
2954
+ const vw = ctx.canvas.clientWidth;
2955
+ const vh = ctx.canvas.clientHeight;
2956
+ const onCanvas = screenPos.x >= 0 && screenPos.x <= vw && screenPos.y >= 0 && screenPos.y <= vh;
2957
+ if (ctx.activeAnnotation !== this || !ctx.revealed) {
2958
+ tooltip.classList.remove('sse-visible');
2959
+ const offset = ctx.tooltipOffset;
2960
+ if (offset) {
2961
+ tooltip.style.transform = `translate(${screenPos.x + offset.x}px, ${screenPos.y + offset.y}px)`;
2962
+ }
2963
+ return;
2964
+ }
2965
+ // Position tooltip, clamped to the canvas (screenPos is in canvas pixels). Measured
2966
+ // before it is shown, which also lets a tooltip that was empty, and so not displayed,
2967
+ // fade in rather than appear at once
2883
2968
  const margin = 8;
2884
2969
  const arrowOffset = 24;
2885
2970
  const tw = tooltip.offsetWidth;
2886
2971
  const th = tooltip.offsetHeight;
2887
- const vw = ctx.canvas.clientWidth;
2888
- const vh = ctx.canvas.clientHeight;
2889
- // Default position: to the right of hotspot, vertically centered
2890
- let left = screenPos.x + arrowOffset;
2972
+ // Beside the hotspot, vertically centered, on the side it is already on: changing sides
2973
+ // jumps it across the hotspot, so it does only when it no longer fits there and does on
2974
+ // the other side. With no side yet, the right unless that overflows
2975
+ const onRight = screenPos.x + arrowOffset;
2976
+ const onLeft = screenPos.x - arrowOffset - tw;
2977
+ let flipped = tooltip.classList.contains('sse-arrow-left');
2978
+ if (flipped ? onLeft < margin && onRight + tw <= vw - margin : onRight + tw > vw - margin) {
2979
+ flipped = !flipped;
2980
+ }
2981
+ let left = flipped ? onLeft : onRight;
2891
2982
  let top = screenPos.y - th / 2;
2892
- let flipped = false;
2893
- // If tooltip overflows right edge, flip to left side of hotspot
2894
- if (left + tw > vw - margin) {
2895
- left = screenPos.x - arrowOffset - tw;
2896
- flipped = true;
2897
- }
2898
2983
  // Clamp horizontal
2899
2984
  left = Math.max(margin, Math.min(left, vw - tw - margin));
2900
2985
  // Clamp vertical
@@ -2905,6 +2990,8 @@ class Annotation extends Script {
2905
2990
  tooltip.classList.toggle('sse-arrow-right', !flipped);
2906
2991
  tooltip.classList.toggle('sse-arrow-left', flipped);
2907
2992
  tooltip.style.transform = `translate(${left}px, ${top}px)`;
2993
+ tooltip.classList.add('sse-visible');
2994
+ ctx.tooltipOffset = onCanvas ? { x: left - screenPos.x, y: top - screenPos.y } : null;
2908
2995
  }
2909
2996
  }
2910
2997
  /**
@@ -2923,6 +3010,15 @@ class AnnotationContext {
2923
3010
  titleDom;
2924
3011
  textDom;
2925
3012
  activeAnnotation = null;
3013
+ // whether the active annotation's tooltip has been revealed: it hides for each camera
3014
+ // transition, the move to the annotation among them, until the transition nearly ends
3015
+ revealed = false;
3016
+ // the annotation the tooltip belongs to: the active one once revealed, until then the one
3017
+ // before it, beside whose hotspot it fades out. And its offset from that hotspot when it
3018
+ // last showed, which it keeps while fading; null when it last showed clamped to the canvas
3019
+ // with the hotspot beyond it, since it is not beside the hotspot, and then it fades in place
3020
+ tooltipOwner = null;
3021
+ tooltipOffset = null;
2926
3022
  constructor(canvas, camera, parentDom) {
2927
3023
  this.parentDom = parentDom;
2928
3024
  this.canvas = canvas;
@@ -2953,6 +3049,10 @@ const OCCLUDING_OPACITY = 0.5;
2953
3049
  const OCCLUSION_TOLERANCE = 0.1;
2954
3050
  // the hotspot's radius in css pixels: the opacity in front is averaged over its whole disc
2955
3051
  const HOTSPOT_RADIUS = 13;
3052
+ // the selected annotation's tooltip starts fading in once the camera has eased this far along
3053
+ // a transition, its move there among them: the move settles slowly, so waiting for it to stop
3054
+ // shows the tooltip well after the camera looks to have arrived
3055
+ const REVEAL_PROGRESS = 0.9;
2956
3056
  // Built-in hotspot and panel presentation. Selection and camera navigation belong to the viewer.
2957
3057
  class Annotations {
2958
3058
  parentDom;
@@ -2960,7 +3060,7 @@ class Annotations {
2960
3060
  subscriptions;
2961
3061
  removeClick;
2962
3062
  removeOcclusion;
2963
- constructor(viewer, root, camera, getPicker) {
3063
+ constructor(viewer, root, camera, getPicker, getCameraProgress) {
2964
3064
  const { app, state, events, annotations } = viewer;
2965
3065
  const parentDom = document.createElement('div');
2966
3066
  parentDom.className = 'sse-annotations';
@@ -2997,7 +3097,7 @@ class Annotations {
2997
3097
  // bumped on every camera move, so a test that resolves after the camera moved again is
2998
3098
  // discarded rather than applied to a pose it was not taken from
2999
3099
  let pose = 0;
3000
- const lastView = new Mat4();
3100
+ const lastWorld = new Mat4();
3001
3101
  const lastProjection = new Mat4();
3002
3102
  const testOcclusion = async () => {
3003
3103
  settleTimer = null;
@@ -3036,12 +3136,43 @@ class Annotations {
3036
3136
  clearTimeout(settleTimer);
3037
3137
  settleTimer = setTimeout(testOcclusion, SETTLE_MS);
3038
3138
  };
3039
- // after each frame, since the hotspots' screen positions are updated in prerender
3139
+ // A new camera transition (a reset, say): the tooltip hides until it nearly ends, as on
3140
+ // the move to an annotation. Checked after the camera update but before the frame
3141
+ // renders, so the tooltip is not laid out for the transition's first frame
3142
+ let lastProgress = 1;
3143
+ const onFrameRender = () => {
3144
+ const progress = getCameraProgress();
3145
+ if (progress < lastProgress)
3146
+ context.revealed = false;
3147
+ lastProgress = progress;
3148
+ };
3149
+ app.on('framerender', onFrameRender);
3150
+ // after each frame, since the hotspots' screen positions are updated in prerender. The
3151
+ // camera entity's transform rather than its view matrix, which the engine refreshes only
3152
+ // for frames that render: the viewer skips a frame whose camera moved too little to see,
3153
+ // and a stale view matrix would pass for a camera at rest
3040
3154
  const onFrameEnd = () => {
3041
- const { viewMatrix, projectionMatrix } = camera.camera;
3042
- if (lastView.equals(viewMatrix) && lastProjection.equals(projectionMatrix))
3155
+ const world = camera.getWorldTransform();
3156
+ const { projectionMatrix } = camera.camera;
3157
+ const still = lastWorld.equals(world) && lastProjection.equals(projectionMatrix);
3158
+ const progress = getCameraProgress();
3159
+ // Show the selected annotation's tooltip once the camera is nearly there with the
3160
+ // hotspot on the canvas, fading in as the camera lands, or once the camera is at rest.
3161
+ // A hotspot that ends beyond the canvas gets its tooltip at rest, clamped to the edge,
3162
+ // rather than one that shows and then hides again as the hotspot slides off
3163
+ const { activeAnnotation } = context;
3164
+ const screen = activeAnnotation?.screen;
3165
+ const onCanvas = screen &&
3166
+ screen.x >= 0 &&
3167
+ screen.x <= canvas.clientWidth &&
3168
+ screen.y >= 0 &&
3169
+ screen.y <= canvas.clientHeight;
3170
+ if (activeAnnotation && !context.revealed && (still || (progress >= REVEAL_PROGRESS && onCanvas))) {
3171
+ activeAnnotation.revealTooltip();
3172
+ }
3173
+ if (still)
3043
3174
  return;
3044
- lastView.copy(viewMatrix);
3175
+ lastWorld.copy(world);
3045
3176
  lastProjection.copy(projectionMatrix);
3046
3177
  pose++;
3047
3178
  scheduleOcclusion();
@@ -3067,6 +3198,7 @@ class Annotations {
3067
3198
  destroyed = true;
3068
3199
  if (settleTimer)
3069
3200
  clearTimeout(settleTimer);
3201
+ app.off('framerender', onFrameRender);
3070
3202
  app.off('frameend', onFrameEnd);
3071
3203
  gsplatSystem.off('frame:ready', onFrameReady);
3072
3204
  };
@@ -3094,12 +3226,32 @@ class Annotations {
3094
3226
  events.on('gamingControls:changed', update)
3095
3227
  ];
3096
3228
  update();
3229
+ // A click deselects, but a drag ends in a click too, so releasing an orbit would close
3230
+ // the tooltip. A press that moved farther than a tap may is a drag, as the navigation
3231
+ // clicks count it
3232
+ let pressMovement = 0;
3233
+ const onPointerDown = () => {
3234
+ pressMovement = 0;
3235
+ };
3236
+ const onPointerMove = (event) => {
3237
+ if (event.buttons)
3238
+ pressMovement += Math.abs(event.movementX) + Math.abs(event.movementY);
3239
+ };
3097
3240
  const onClick = () => {
3098
- if (state.loaded && state.selectedAnnotation !== null)
3241
+ // consumed, so a later click from the keyboard is not taken for the drag
3242
+ const dragged = pressMovement >= TAP_EPSILON;
3243
+ pressMovement = 0;
3244
+ if (!dragged && state.loaded && state.selectedAnnotation !== null)
3099
3245
  viewer.selectAnnotation(null);
3100
3246
  };
3247
+ root.addEventListener('pointerdown', onPointerDown);
3248
+ root.addEventListener('pointermove', onPointerMove);
3101
3249
  root.addEventListener('click', onClick);
3102
- this.removeClick = () => root.removeEventListener('click', onClick);
3250
+ this.removeClick = () => {
3251
+ root.removeEventListener('pointerdown', onPointerDown);
3252
+ root.removeEventListener('pointermove', onPointerMove);
3253
+ root.removeEventListener('click', onClick);
3254
+ };
3103
3255
  }
3104
3256
  destroy() {
3105
3257
  for (const subscription of this.subscriptions)
@@ -3784,8 +3936,9 @@ const getGpuName = (device) => {
3784
3936
  // document, screen) and cancels pending timers. Listeners on the subtree's own elements are
3785
3937
  // released with the elements.
3786
3938
  // `getPicker` returns the viewer's picker once the scene has loaded, for the annotation
3787
- // occlusion test
3788
- const initUI = (global, viewer, getPicker) => {
3939
+ // occlusion test; `getCameraProgress` how far the camera's current move has eased, 1 when there
3940
+ // is none, for the annotation tooltip's timing
3941
+ const initUI = (global, viewer, getPicker, getCameraProgress) => {
3789
3942
  const { root, localize } = global;
3790
3943
  const { events, state } = viewer;
3791
3944
  const disposers = [];
@@ -4149,7 +4302,7 @@ const initUI = (global, viewer, getPicker) => {
4149
4302
  disposers.push(initJoystick(viewer, root));
4150
4303
  disposers.push(initAnnotationControls(viewer, root));
4151
4304
  if (viewer.annotations.length > 0) {
4152
- const annotations = new Annotations(viewer, root, global.camera, getPicker);
4305
+ const annotations = new Annotations(viewer, root, global.camera, getPicker, getCameraProgress);
4153
4306
  disposers.push(() => annotations.destroy());
4154
4307
  }
4155
4308
  // tooltips
@@ -6149,6 +6302,9 @@ class CameraManager {
6149
6302
  // mutating `camera` and/or `state.cameraMode` to make the change
6150
6303
  // visible instantly.
6151
6304
  snap;
6305
+ // How far the current transition has eased toward its destination, from 0 to 1; 1 when
6306
+ // there is none. The annotations time their tooltip to the camera's arrival with it.
6307
+ transitionProgress;
6152
6308
  // Attach (or clear) collision after construction. The viewer reveals the scene without
6153
6309
  // waiting for collision data, which can be larger than the splats themselves, so this
6154
6310
  // arrives late. It re-tests whether walk mode is allowed, which gates the walk toggle
@@ -6242,6 +6398,7 @@ class CameraManager {
6242
6398
  transitionEase = ease;
6243
6399
  transitionTurnEase = turnEase;
6244
6400
  };
6401
+ this.transitionProgress = () => (transitionTimer < 1 ? transitionEase(transitionTimer) : 1);
6245
6402
  this.setCollision = (value) => {
6246
6403
  controllers.fly.collision = value;
6247
6404
  controllers.walk.collision = value;
@@ -8626,58 +8783,6 @@ class ModeShortcuts {
8626
8783
  }
8627
8784
  }
8628
8785
 
8629
- /**
8630
- * Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
8631
- * pixel offsets that already scale with frame time. This factor converts
8632
- * rate-based speed constants (tuned for degrees-per-second) to work with
8633
- * per-frame displacements, making them frame-rate-independent.
8634
- */
8635
- const DISPLACEMENT_SCALE = 1 / 60;
8636
- /** Maximum accumulated touch movement (px) to still count as a tap. */
8637
- const TAP_EPSILON = 15;
8638
- const tmpHalfSize = new Vec3();
8639
- /**
8640
- * Converts screen-space pixel deltas to a world-space pan vector at the
8641
- * given depth.
8642
- *
8643
- * @param camera - The camera component.
8644
- * @param dx - Horizontal pixel delta.
8645
- * @param dy - Vertical pixel delta.
8646
- * @param dz - Depth (world-space) at which to project the delta.
8647
- * @param out - Optional output vector.
8648
- * @returns The pan vector in world space.
8649
- */
8650
- const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
8651
- const { system, fov, aspectRatio, horizontalFov, projection, orthoHeight } = camera;
8652
- const { width, height } = system.app.graphicsDevice.clientRect;
8653
- out.set(-(dx / width) * 2, (dy / height) * 2, 0);
8654
- const halfSize = tmpHalfSize.set(0, 0, 0);
8655
- if (projection === PROJECTION_PERSPECTIVE) {
8656
- const halfSlice = dz * Math.tan(0.5 * fov * math.DEG_TO_RAD);
8657
- if (horizontalFov) {
8658
- halfSize.set(halfSlice, halfSlice / aspectRatio, 0);
8659
- }
8660
- else {
8661
- halfSize.set(halfSlice * aspectRatio, halfSlice, 0);
8662
- }
8663
- }
8664
- else {
8665
- halfSize.set(orthoHeight * aspectRatio, orthoHeight, 0);
8666
- }
8667
- out.mul(halfSize);
8668
- return out;
8669
- };
8670
- /**
8671
- * The orbit camera and the fly camera disagree on the sign of the z-axis
8672
- * for forward motion. Apply this when emitting a forward/back z-component
8673
- * so the same wheel-style delta drives both cameras correctly.
8674
- *
8675
- * @param mode - The current camera mode.
8676
- * @param z - The raw forward/back z-component.
8677
- * @returns The z-component flipped for orbit mode, unchanged otherwise.
8678
- */
8679
- const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
8680
-
8681
8786
  const tmpV$4 = new Vec3();
8682
8787
  const canTargetFly = (global) => global.state.cameraMode === 'fly' && !(global.state.inputMode === 'desktop' && global.state.gamingControls);
8683
8788
  // Mirror gaming-controls speed modifiers: shift = run/boost, ctrl = crawl/slow.
@@ -15703,7 +15808,9 @@ const createViewer = async (options) => {
15703
15808
  destroy: () => viewer.destroy()
15704
15809
  };
15705
15810
  // The built-in controls use the same handle returned to an embedding host.
15706
- const disposeUI = config.ui ? initUI(global, handle, () => viewer.picker) : null;
15811
+ const disposeUI = config.ui
15812
+ ? initUI(global, handle, () => viewer.picker, () => viewer.cameraManager?.transitionProgress() ?? 1)
15813
+ : null;
15707
15814
  viewer.onDestroy(() => {
15708
15815
  destroyed = true;
15709
15816
  });