MikaFil commited on
Commit
ca2619f
Β·
verified Β·
1 Parent(s): 59d9923

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +18 -1
viewer.js CHANGED
@@ -7,6 +7,7 @@ export let app = null;
7
  let cameraEntity = null;
8
  let modelEntity = null;
9
  let viewerInitialized = false;
 
10
 
11
  let chosenCameraX, chosenCameraY, chosenCameraZ;
12
  let minZoom, maxZoom, minAngle, maxAngle, minAzimuth, maxAzimuth, minPivotY, minY;
@@ -137,7 +138,7 @@ export async function initializeViewer(config, instanceId) {
137
  pc.GSplatHandler
138
  ];
139
 
140
- // ─── REPLACED: use pc.Application (instead of deprecated / removed AppBase) ──
141
  app = new pc.Application(canvas, createOptions);
142
 
143
  // Configure application
@@ -307,6 +308,17 @@ export async function initializeViewer(config, instanceId) {
307
  // 9f. Resize canvas one last time to fit container
308
  app.resizeCanvas(viewerContainerElem.clientWidth, viewerContainerElem.clientHeight);
309
 
 
 
 
 
 
 
 
 
 
 
 
310
  // ─── NEW: Load & initialize the tooltips module ──────────────────────
311
  try {
312
  const tooltipsModule = await import('./tooltips.js');
@@ -394,6 +406,7 @@ export function resetViewerCamera() {
394
  * cleanupViewer()
395
  *
396
  * Destroys the PlayCanvas `app` (if it exists) and clears references. Called when the user clicks β€œX”.
 
397
  */
398
  export function cleanupViewer() {
399
  if (app) {
@@ -404,6 +417,10 @@ export function cleanupViewer() {
404
  }
405
  app = null;
406
  }
 
 
 
 
407
  cameraEntity = null;
408
  modelEntity = null;
409
  viewerInitialized = false;
 
7
  let cameraEntity = null;
8
  let modelEntity = null;
9
  let viewerInitialized = false;
10
+ let resizeObserver = null; // will hold our ResizeObserver
11
 
12
  let chosenCameraX, chosenCameraY, chosenCameraZ;
13
  let minZoom, maxZoom, minAngle, maxAngle, minAzimuth, maxAzimuth, minPivotY, minY;
 
138
  pc.GSplatHandler
139
  ];
140
 
141
+ // ─── REPLACED: use pc.Application ───────────────────────────────────────────
142
  app = new pc.Application(canvas, createOptions);
143
 
144
  // Configure application
 
308
  // 9f. Resize canvas one last time to fit container
309
  app.resizeCanvas(viewerContainerElem.clientWidth, viewerContainerElem.clientHeight);
310
 
311
+ // ─── NEW: Attach ResizeObserver to keep canvas in sync ─────────────────
312
+ resizeObserver = new ResizeObserver(entries => {
313
+ for (let entry of entries) {
314
+ const { width, height } = entry.contentRect;
315
+ if (app) {
316
+ app.resizeCanvas(width, height);
317
+ }
318
+ }
319
+ });
320
+ resizeObserver.observe(viewerContainerElem);
321
+
322
  // ─── NEW: Load & initialize the tooltips module ──────────────────────
323
  try {
324
  const tooltipsModule = await import('./tooltips.js');
 
406
  * cleanupViewer()
407
  *
408
  * Destroys the PlayCanvas `app` (if it exists) and clears references. Called when the user clicks β€œX”.
409
+ * Also disconnects the ResizeObserver to prevent memory leaks.
410
  */
411
  export function cleanupViewer() {
412
  if (app) {
 
417
  }
418
  app = null;
419
  }
420
+ if (resizeObserver && viewerContainerElem) {
421
+ resizeObserver.disconnect();
422
+ resizeObserver = null;
423
+ }
424
  cameraEntity = null;
425
  modelEntity = null;
426
  viewerInitialized = false;