Spaces:
Running
Running
Update js_scripts/index.js
Browse files- js_scripts/index.js +18 -20
js_scripts/index.js
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
(async function() {
|
2 |
// Retrieve the current script tag and load the JSON configuration file from the data-config attribute.
|
3 |
const scriptTag = document.currentScript;
|
@@ -16,16 +17,6 @@
|
|
16 |
return;
|
17 |
}
|
18 |
|
19 |
-
// Load external CSS if css_url is provided in the config.
|
20 |
-
if (config.css_url) {
|
21 |
-
const linkEl = document.createElement('link');
|
22 |
-
linkEl.rel = 'stylesheet';
|
23 |
-
linkEl.href = config.css_url;
|
24 |
-
document.head.appendChild(linkEl);
|
25 |
-
} else {
|
26 |
-
console.warn("No css_url provided in config; external CSS file will not be loaded.");
|
27 |
-
}
|
28 |
-
|
29 |
// --- Outer scope variables for camera state ---
|
30 |
let cameraInstance = null;
|
31 |
let controlsInstance = null;
|
@@ -40,7 +31,6 @@
|
|
40 |
// Read configuration values from the JSON file.
|
41 |
const gifUrl = config.gif_url;
|
42 |
const plyUrl = config.ply_url;
|
43 |
-
const canvasBg = config.canvas_background || "#FEFEFD";
|
44 |
const minZoom = parseFloat(config.minZoom || "0");
|
45 |
const maxZoom = parseFloat(config.maxZoom || "20");
|
46 |
const minAngle = parseFloat(config.minAngle || "0");
|
@@ -96,8 +86,10 @@
|
|
96 |
const widgetContainer = document.createElement('div');
|
97 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
98 |
widgetContainer.classList.add('ply-widget-container');
|
99 |
-
// Set
|
100 |
-
widgetContainer.style.
|
|
|
|
|
101 |
widgetContainer.innerHTML = `
|
102 |
<!-- GIF Preview Container -->
|
103 |
<div id="gif-preview-container-${instanceId}" class="gif-preview-container">
|
@@ -215,12 +207,20 @@
|
|
215 |
}
|
216 |
});
|
217 |
|
218 |
-
// Listen for native fullscreen changes.
|
|
|
|
|
219 |
document.addEventListener('fullscreenchange', function() {
|
220 |
if (document.fullscreenElement === widgetContainer) {
|
221 |
fullscreenToggle.textContent = '⇲';
|
|
|
|
|
|
|
222 |
} else {
|
223 |
fullscreenToggle.textContent = '⇱';
|
|
|
|
|
|
|
224 |
resetCamera();
|
225 |
}
|
226 |
});
|
@@ -268,13 +268,13 @@
|
|
268 |
}
|
269 |
}
|
270 |
|
271 |
-
//
|
272 |
resetCameraBtn.addEventListener('click', async function() {
|
273 |
console.log("Reset camera button clicked.");
|
274 |
resetCamera();
|
275 |
});
|
276 |
|
277 |
-
//
|
278 |
document.addEventListener('keydown', function(e) {
|
279 |
if (e.key === 'Escape' || e.key === 'Esc') {
|
280 |
let wasFullscreen = false;
|
@@ -303,10 +303,7 @@
|
|
303 |
const renderer = new SPLAT.WebGLRenderer(canvas);
|
304 |
const scene = new SPLAT.Scene();
|
305 |
|
306 |
-
//
|
307 |
-
canvas.style.background = canvasBg;
|
308 |
-
|
309 |
-
// Construct the camera (no custom position since it's no longer in the JSON).
|
310 |
const camera = new SPLAT.Camera();
|
311 |
|
312 |
// Construct OrbitControls with the chosen initial orbit parameters.
|
@@ -328,6 +325,7 @@
|
|
328 |
initialCameraPosition = camera.position.clone();
|
329 |
initialCameraRotation = camera.rotation.clone();
|
330 |
|
|
|
331 |
controlsInstance.maxZoom = maxZoom;
|
332 |
controlsInstance.minZoom = minZoom;
|
333 |
controlsInstance.minAngle = minAngle;
|
|
|
1 |
+
/* viewer.js */
|
2 |
(async function() {
|
3 |
// Retrieve the current script tag and load the JSON configuration file from the data-config attribute.
|
4 |
const scriptTag = document.currentScript;
|
|
|
17 |
return;
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
// --- Outer scope variables for camera state ---
|
21 |
let cameraInstance = null;
|
22 |
let controlsInstance = null;
|
|
|
31 |
// Read configuration values from the JSON file.
|
32 |
const gifUrl = config.gif_url;
|
33 |
const plyUrl = config.ply_url;
|
|
|
34 |
const minZoom = parseFloat(config.minZoom || "0");
|
35 |
const maxZoom = parseFloat(config.maxZoom || "20");
|
36 |
const minAngle = parseFloat(config.minAngle || "0");
|
|
|
86 |
const widgetContainer = document.createElement('div');
|
87 |
widgetContainer.id = 'ply-widget-container-' + instanceId;
|
88 |
widgetContainer.classList.add('ply-widget-container');
|
89 |
+
// Set inline style for aspect ratio.
|
90 |
+
widgetContainer.style.height = "0";
|
91 |
+
widgetContainer.style.paddingBottom = aspectPercent;
|
92 |
+
|
93 |
widgetContainer.innerHTML = `
|
94 |
<!-- GIF Preview Container -->
|
95 |
<div id="gif-preview-container-${instanceId}" class="gif-preview-container">
|
|
|
207 |
}
|
208 |
});
|
209 |
|
210 |
+
// Listen for native fullscreen changes.
|
211 |
+
// Update the widget container styles so that in fullscreen
|
212 |
+
// the aspect ratio style is removed (height = 100% and padding-bottom = 0) and then reset the camera.
|
213 |
document.addEventListener('fullscreenchange', function() {
|
214 |
if (document.fullscreenElement === widgetContainer) {
|
215 |
fullscreenToggle.textContent = '⇲';
|
216 |
+
widgetContainer.style.height = '100%';
|
217 |
+
widgetContainer.style.paddingBottom = '0';
|
218 |
+
resetCamera();
|
219 |
} else {
|
220 |
fullscreenToggle.textContent = '⇱';
|
221 |
+
// Restore the original aspect ratio style when not fullscreen.
|
222 |
+
widgetContainer.style.height = '0';
|
223 |
+
widgetContainer.style.paddingBottom = aspectPercent;
|
224 |
resetCamera();
|
225 |
}
|
226 |
});
|
|
|
268 |
}
|
269 |
}
|
270 |
|
271 |
+
// Reset button now calls the resetCamera function.
|
272 |
resetCameraBtn.addEventListener('click', async function() {
|
273 |
console.log("Reset camera button clicked.");
|
274 |
resetCamera();
|
275 |
});
|
276 |
|
277 |
+
// Add keydown listener to exit fullscreen with Esc (or Echap)
|
278 |
document.addEventListener('keydown', function(e) {
|
279 |
if (e.key === 'Escape' || e.key === 'Esc') {
|
280 |
let wasFullscreen = false;
|
|
|
303 |
const renderer = new SPLAT.WebGLRenderer(canvas);
|
304 |
const scene = new SPLAT.Scene();
|
305 |
|
306 |
+
// Construct the camera.
|
|
|
|
|
|
|
307 |
const camera = new SPLAT.Camera();
|
308 |
|
309 |
// Construct OrbitControls with the chosen initial orbit parameters.
|
|
|
325 |
initialCameraPosition = camera.position.clone();
|
326 |
initialCameraRotation = camera.rotation.clone();
|
327 |
|
328 |
+
canvas.style.background = "#FEFEFD";
|
329 |
controlsInstance.maxZoom = maxZoom;
|
330 |
controlsInstance.minZoom = minZoom;
|
331 |
controlsInstance.minAngle = minAngle;
|