Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -25,12 +25,17 @@
|
|
25 |
var plyUrl = getScriptQueryParam("ply_url");
|
26 |
|
27 |
// Optional parameters for zoom and rotation limits.
|
28 |
-
// Defaults: zoom from 0 to 20; rotation from 0 to 360.
|
29 |
var minZoom = parseFloat(getScriptQueryParam("minZoom") || "0");
|
30 |
var maxZoom = parseFloat(getScriptQueryParam("maxZoom") || "20");
|
31 |
var minAngle = parseFloat(getScriptQueryParam("minAngle") || "0");
|
32 |
var maxAngle = parseFloat(getScriptQueryParam("maxAngle") || "360");
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
// Detect if the device is iOS.
|
35 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
36 |
|
@@ -278,9 +283,38 @@
|
|
278 |
const scene = new SPLAT.Scene();
|
279 |
const camera = new SPLAT.Camera();
|
280 |
const controls = new SPLAT.OrbitControls(camera, canvas);
|
281 |
-
|
282 |
-
|
283 |
controlsInstance = controls;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
initialCameraPosition = camera.position.clone();
|
285 |
initialCameraRotation = camera.rotation.clone();
|
286 |
|
|
|
25 |
var plyUrl = getScriptQueryParam("ply_url");
|
26 |
|
27 |
// Optional parameters for zoom and rotation limits.
|
28 |
+
// Defaults: zoom from 0 to 20; rotation (vertical) from 0 to 360.
|
29 |
var minZoom = parseFloat(getScriptQueryParam("minZoom") || "0");
|
30 |
var maxZoom = parseFloat(getScriptQueryParam("maxZoom") || "20");
|
31 |
var minAngle = parseFloat(getScriptQueryParam("minAngle") || "0");
|
32 |
var maxAngle = parseFloat(getScriptQueryParam("maxAngle") || "360");
|
33 |
|
34 |
+
// New optional parameters for horizontal (azimuth) rotation.
|
35 |
+
// Defaults: azimuth from -360 to 360.
|
36 |
+
var minAzimuth = parseFloat(getScriptQueryParam("minAzimuth") || "-360");
|
37 |
+
var maxAzimuth = parseFloat(getScriptQueryParam("maxAzimuth") || "360");
|
38 |
+
|
39 |
// Detect if the device is iOS.
|
40 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
41 |
|
|
|
283 |
const scene = new SPLAT.Scene();
|
284 |
const camera = new SPLAT.Camera();
|
285 |
const controls = new SPLAT.OrbitControls(camera, canvas);
|
286 |
+
|
287 |
+
// Store the controls instance if needed.
|
288 |
controlsInstance = controls;
|
289 |
+
cameraInstance = camera;
|
290 |
+
|
291 |
+
// Set camera controls parameters.
|
292 |
+
controls.maxZoom = maxZoom;
|
293 |
+
controls.minZoom = minZoom;
|
294 |
+
controls.minAngle = minAngle;
|
295 |
+
controls.maxAngle = maxAngle;
|
296 |
+
// Pass the new azimuth limits to the controls (for reference, though the library doesn’t natively use them)
|
297 |
+
controls.minAzimuth = minAzimuth;
|
298 |
+
controls.maxAzimuth = maxAzimuth;
|
299 |
+
|
300 |
+
// Monkey patch the update method to clamp horizontal (azimuth) rotation.
|
301 |
+
// We assume that camera.rotation is a Quaternion that can be converted to Euler angles.
|
302 |
+
// The azimuth (horizontal rotation) is assumed to be the Y component in Euler angles.
|
303 |
+
const { Quaternion } = SPLAT;
|
304 |
+
const originalUpdate = controls.update.bind(controls);
|
305 |
+
controls.update = () => {
|
306 |
+
originalUpdate();
|
307 |
+
// Convert current rotation to Euler angles.
|
308 |
+
let euler = camera.rotation.toEuler();
|
309 |
+
// Convert the azimuth limits from degrees to radians.
|
310 |
+
let minAzimuthRad = (minAzimuth * Math.PI) / 180;
|
311 |
+
let maxAzimuthRad = (maxAzimuth * Math.PI) / 180;
|
312 |
+
// Clamp the horizontal angle (euler.y).
|
313 |
+
euler.y = Math.min(Math.max(euler.y, minAzimuthRad), maxAzimuthRad);
|
314 |
+
// Update the camera rotation based on the clamped Euler.
|
315 |
+
camera.rotation = Quaternion.FromEuler(euler);
|
316 |
+
};
|
317 |
+
|
318 |
initialCameraPosition = camera.position.clone();
|
319 |
initialCameraRotation = camera.rotation.clone();
|
320 |
|