Spaces:
Running
Running
Update viewer.js
Browse files
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
|
| 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;
|