@preference-sl/pref-viewer 2.17.2-beta.0 → 2.17.2-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preference-sl/pref-viewer",
3
- "version": "2.17.2-beta.0",
3
+ "version": "2.17.2-beta.2",
4
4
  "description": "Web Component to preview GLTF models with Babylon.js",
5
5
  "author": "Alex Moreno Palacio <amoreno@preference.es>",
6
6
  "scripts": {
@@ -3396,7 +3396,8 @@ export default class BabylonJSController {
3396
3396
  getViewport: () => ({ width: this.#canvas.clientWidth, height: this.#canvas.clientHeight }),
3397
3397
  getCulture: this.#viewCubeConfig.getCulture,
3398
3398
  onLayout: this.#viewCubeConfig.onLayout,
3399
- requestRender: () => this.#requestRender({ frames: 2 }),
3399
+ // A cube drag is pointer interaction like a main-canvas drag: keep the loop continuous for the same window.
3400
+ requestRender: (options) => this.#requestRender({ frames: 2, continuousMs: options?.interaction ? BabylonJSController.config.render.interactionMs : 0 }),
3400
3401
  });
3401
3402
  }
3402
3403
 
@@ -139,7 +139,7 @@ export default class BabylonJSViewCubeController {
139
139
  * @param {function(import("@babylonjs/core").Camera|null|undefined): boolean} host.isLocked - Reports whether navigation is forbidden for the supplied camera, including unavailable cameras or active XR.
140
140
  * @param {function(): (ViewCubeBounds|null)} host.getBounds - Returns current model-only world bounds and their eight corners; null when geometry is unusable. Excludes the environment.
141
141
  * @param {function(): {width: number, height: number}} host.getViewport - Returns the current scene viewport dimensions in CSS pixels.
142
- * @param {function(): void} host.requestRender - Requests rendering through the host scheduler after accepted navigation.
142
+ * @param {function(Object=): void} host.requestRender - Requests rendering through the host scheduler after accepted navigation; `{ interaction: true }` marks a pointer drag step, for which the host keeps rendering continuously as it does for its own canvas drags.
143
143
  * @param {function(): string} [host.getCulture] - Returns the current localization culture; omitted callbacks use the translator's default culture.
144
144
  * @param {function(number, number): void} [host.onLayout] - Receives the measured cube viewport height and scene viewport height, in CSS pixels; zero cube height clears the menu offset, and disposal reports (0, 0).
145
145
  * @param {function(ViewCubeRendererOptions): BabylonJSViewCubeRenderer} [host.createRenderer] - Renderer factory, mainly for tests; defaults to a BabylonJSViewCubeRenderer with its own Engine.
@@ -581,7 +581,9 @@ export default class BabylonJSViewCubeController {
581
581
  const direction = directionFromAngles(applyDragDelta(angles, dAlpha, dBeta));
582
582
  this.#writePose(camera, pose.target.add(new Vector3(direction.x, direction.y, direction.z).scale(pose.distance)), pose.target, pose.distance);
583
583
  }
584
- this.#host.requestRender();
584
+ // A drag is pointer interaction: the host keeps its loop continuous for its interaction window, as it does for a
585
+ // main-canvas drag. A plain one-frame request would let its idle throttle pace the drag (seen at ~8 fps).
586
+ this.#host.requestRender({ interaction: true });
585
587
  }
586
588
 
587
589
  /**
@@ -168,7 +168,8 @@ export default class BabylonJSViewCubeRenderer {
168
168
  /**
169
169
  * Orients the cube like the host camera and follows its projection. An orthographic host gives an orthographic
170
170
  * cube (radius 5, extents +-1.15). A perspective host gives a perspective cube with the host's vertical fov at
171
- * radius 1.15 / tan(fov / 2), so the cube keeps the same on-screen size.
171
+ * radius 0.5 + 1.15 / tan(fov / 2), so the near face and its corner knobs keep the on-screen size of the
172
+ * orthographic layout (the rest of the cube foreshortens behind it).
172
173
  * @param {{alpha: number, beta: number, mode?: number, fov?: number}} pose - Host camera angles in radians (beta is clamped away from the poles), projection mode (Camera.ORTHOGRAPHIC_CAMERA or Camera.PERSPECTIVE_CAMERA; absent keeps the last one) and vertical field of view in radians (absent or not a finite positive number keeps the last one, 0.8 initially).
173
174
  * @returns {void}
174
175
  */
@@ -393,13 +394,14 @@ export default class BabylonJSViewCubeRenderer {
393
394
  return best?.id ?? null;
394
395
  }
395
396
 
396
- // Orthographic: fixed radius and extents. Perspective: the host fov and the radius that frames the same half extent.
397
+ // Orthographic: fixed radius and extents. Perspective: the host fov and the radius that frames the same half extent
398
+ // at the near face plane (CUBE_HALF in front of the centre), where the corner knobs and the face in view are drawn.
397
399
  #applyProjection(camera) {
398
400
  if (this.#mode === Camera.PERSPECTIVE_CAMERA) {
399
401
  camera.mode = Camera.PERSPECTIVE_CAMERA;
400
402
  camera.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
401
403
  camera.fov = this.#fov;
402
- camera.radius = ORTHO_EXTENT / Math.tan(this.#fov / 2);
404
+ camera.radius = CUBE_HALF + ORTHO_EXTENT / Math.tan(this.#fov / 2);
403
405
  // A wide fov brings the camera closer than the margin: keep the near plane positive and before the nearest corner.
404
406
  camera.minZ = Math.max(camera.radius - PERSPECTIVE_DEPTH_MARGIN, Math.min(0.1, (camera.radius - CORNER_DISTANCE) / 2));
405
407
  camera.maxZ = camera.radius + PERSPECTIVE_DEPTH_MARGIN;