MikaFil commited on
Commit
4b2f119
Β·
verified Β·
1 Parent(s): e50b47f

Update viewer.js

Browse files
Files changed (1) hide show
  1. viewer.js +6 -23
viewer.js CHANGED
@@ -7,7 +7,6 @@ export let app = null;
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,7 +137,7 @@ export async function initializeViewer(config, instanceId) {
138
  pc.GSplatHandler
139
  ];
140
 
141
- // ─── REPLACED: use pc.Application ───────────────────────────────────────────
142
  app = new pc.Application(canvas, createOptions);
143
 
144
  // Configure application
@@ -166,7 +165,7 @@ export async function initializeViewer(config, instanceId) {
166
  hdr: new pc.Asset(
167
  'hdr',
168
  'texture',
169
- { url: `https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png` },
170
  { type: pc.TEXTURETYPE_RGBP, mipmaps: false }
171
  )
172
  };
@@ -179,7 +178,7 @@ export async function initializeViewer(config, instanceId) {
179
  });
180
  assets.model.on('error', (err) => {
181
  console.error("Error loading PLY file:", err);
182
- progressDialog.innerHTML = `<p style="color: red">Error loading model: ${err}</p>`;
183
  });
184
 
185
  const checkProgress = () => {
@@ -308,17 +307,6 @@ export async function initializeViewer(config, instanceId) {
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');
@@ -340,7 +328,7 @@ export async function initializeViewer(config, instanceId) {
340
 
341
  } catch (error) {
342
  console.error("Error initializing PlayCanvas viewer:", error);
343
- progressDialog.innerHTML = `<p style="color: red">Error loading viewer: ${error.message}</p>`;
344
  }
345
  }
346
 
@@ -405,8 +393,7 @@ export function resetViewerCamera() {
405
  /**
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,11 +404,7 @@ export function cleanupViewer() {
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;
427
- }
 
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
  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
 
165
  hdr: new pc.Asset(
166
  'hdr',
167
  'texture',
168
+ { url: https://huggingface.co/datasets/bilca/ply_files/resolve/main/galeries/blanc.png },
169
  { type: pc.TEXTURETYPE_RGBP, mipmaps: false }
170
  )
171
  };
 
178
  });
179
  assets.model.on('error', (err) => {
180
  console.error("Error loading PLY file:", err);
181
+ progressDialog.innerHTML = <p style="color: red">Error loading model: ${err}</p>;
182
  });
183
 
184
  const checkProgress = () => {
 
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');
 
328
 
329
  } catch (error) {
330
  console.error("Error initializing PlayCanvas viewer:", error);
331
+ progressDialog.innerHTML = <p style="color: red">Error loading viewer: ${error.message}</p>;
332
  }
333
  }
334
 
 
393
  /**
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
  }
405
  app = null;
406
  }
 
 
 
 
407
  cameraEntity = null;
408
  modelEntity = null;
409
  viewerInitialized = false;
410
+ }