Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -17,14 +17,25 @@
|
|
17 |
return params.get(param);
|
18 |
}
|
19 |
|
20 |
-
// Read required URLs
|
21 |
var gifUrl = getScriptQueryParam("gif_url");
|
22 |
var plyUrl = getScriptQueryParam("ply_url");
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
var
|
27 |
-
var
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
// Detect if the device is iOS.
|
30 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
@@ -267,7 +278,7 @@
|
|
267 |
resetCameraBtn.addEventListener('click', function() {
|
268 |
console.log("Reset camera button clicked.");
|
269 |
if (cameraInstance && initialCameraPosition && initialCameraRotation) {
|
270 |
-
//
|
271 |
cameraInstance.position = initialCameraPosition.clone();
|
272 |
cameraInstance.rotation = initialCameraRotation.clone();
|
273 |
if (typeof cameraInstance.update === 'function') {
|
@@ -330,6 +341,10 @@
|
|
330 |
|
331 |
const frame = () => {
|
332 |
controls.update();
|
|
|
|
|
|
|
|
|
333 |
renderer.render(scene, camera);
|
334 |
requestAnimationFrame(frame);
|
335 |
};
|
|
|
17 |
return params.get(param);
|
18 |
}
|
19 |
|
20 |
+
// Read required URLs.
|
21 |
var gifUrl = getScriptQueryParam("gif_url");
|
22 |
var plyUrl = getScriptQueryParam("ply_url");
|
23 |
+
|
24 |
+
// Optional parameters for zoom and rotation limits.
|
25 |
+
// Defaults: zoom from 0 to 20; rotation from 0 to 360.
|
26 |
+
var minZoom = parseFloat(getScriptQueryParam("minZoom") || "0");
|
27 |
+
var maxZoom = parseFloat(getScriptQueryParam("maxZoom") || "20");
|
28 |
+
var minAngle = parseFloat(getScriptQueryParam("minAngle") || "0");
|
29 |
+
var maxAngle = parseFloat(getScriptQueryParam("maxAngle") || "360");
|
30 |
+
|
31 |
+
// Optional parameters for translation limits.
|
32 |
+
// Defaults: no restriction.
|
33 |
+
var minX = parseFloat(getScriptQueryParam("minX") || "-Infinity");
|
34 |
+
var maxX = parseFloat(getScriptQueryParam("maxX") || "Infinity");
|
35 |
+
var minY = parseFloat(getScriptQueryParam("minY") || "-Infinity");
|
36 |
+
var maxY = parseFloat(getScriptQueryParam("maxY") || "Infinity");
|
37 |
+
var minZ = parseFloat(getScriptQueryParam("minZ") || "-Infinity");
|
38 |
+
var maxZ = parseFloat(getScriptQueryParam("maxZ") || "Infinity");
|
39 |
|
40 |
// Detect if the device is iOS.
|
41 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
|
278 |
resetCameraBtn.addEventListener('click', function() {
|
279 |
console.log("Reset camera button clicked.");
|
280 |
if (cameraInstance && initialCameraPosition && initialCameraRotation) {
|
281 |
+
// Use clone() to reset the camera's position and rotation.
|
282 |
cameraInstance.position = initialCameraPosition.clone();
|
283 |
cameraInstance.rotation = initialCameraRotation.clone();
|
284 |
if (typeof cameraInstance.update === 'function') {
|
|
|
341 |
|
342 |
const frame = () => {
|
343 |
controls.update();
|
344 |
+
// Clamp camera position to the allowed translation limits.
|
345 |
+
camera.position.x = Math.min(Math.max(camera.position.x, minX), maxX);
|
346 |
+
camera.position.y = Math.min(Math.max(camera.position.y, minY), maxY);
|
347 |
+
camera.position.z = Math.min(Math.max(camera.position.z, minZ), maxZ);
|
348 |
renderer.render(scene, camera);
|
349 |
requestAnimationFrame(frame);
|
350 |
};
|