Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
(function() {
|
2 |
-
// --- Outer scope variables for camera state ---
|
3 |
let cameraInstance = null;
|
4 |
let controlsInstance = null;
|
5 |
let initialCameraPosition = null;
|
6 |
let initialCameraRotation = null;
|
|
|
7 |
|
8 |
// Helper: Get query parameters from THIS script’s src URL.
|
9 |
function getScriptQueryParam(param) {
|
@@ -28,6 +29,15 @@
|
|
28 |
var minAngle = parseFloat(getScriptQueryParam("minAngle") || "0");
|
29 |
var maxAngle = parseFloat(getScriptQueryParam("maxAngle") || "360");
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
// Detect if the device is iOS.
|
32 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
33 |
|
@@ -300,6 +310,8 @@
|
|
300 |
controlsInstance = controls;
|
301 |
initialCameraPosition = camera.position.clone();
|
302 |
initialCameraRotation = camera.rotation.clone();
|
|
|
|
|
303 |
|
304 |
canvas.style.background = "#FEFEFD";
|
305 |
controls.maxZoom = maxZoom;
|
@@ -331,7 +343,22 @@
|
|
331 |
};
|
332 |
|
333 |
const frame = () => {
|
|
|
|
|
334 |
controls.update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
renderer.render(scene, camera);
|
336 |
requestAnimationFrame(frame);
|
337 |
};
|
|
|
1 |
(function() {
|
2 |
+
// --- Outer scope variables for camera state and previous position ---
|
3 |
let cameraInstance = null;
|
4 |
let controlsInstance = null;
|
5 |
let initialCameraPosition = null;
|
6 |
let initialCameraRotation = null;
|
7 |
+
let prevCameraPos = null;
|
8 |
|
9 |
// Helper: Get query parameters from THIS script’s src URL.
|
10 |
function getScriptQueryParam(param) {
|
|
|
29 |
var minAngle = parseFloat(getScriptQueryParam("minAngle") || "0");
|
30 |
var maxAngle = parseFloat(getScriptQueryParam("maxAngle") || "360");
|
31 |
|
32 |
+
// Optional parameters for translation limits.
|
33 |
+
// Defaults: for example, -10 to 10 for each axis.
|
34 |
+
var minX = parseFloat(getScriptQueryParam("minX") || "-10");
|
35 |
+
var maxX = parseFloat(getScriptQueryParam("maxX") || "10");
|
36 |
+
var minY = parseFloat(getScriptQueryParam("minY") || "-10");
|
37 |
+
var maxY = parseFloat(getScriptQueryParam("maxY") || "10");
|
38 |
+
var minZ = parseFloat(getScriptQueryParam("minZ") || "-10");
|
39 |
+
var maxZ = parseFloat(getScriptQueryParam("maxZ") || "10");
|
40 |
+
|
41 |
// Detect if the device is iOS.
|
42 |
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
43 |
|
|
|
310 |
controlsInstance = controls;
|
311 |
initialCameraPosition = camera.position.clone();
|
312 |
initialCameraRotation = camera.rotation.clone();
|
313 |
+
// Initialize previous camera position as the initial state.
|
314 |
+
prevCameraPos = camera.position.clone();
|
315 |
|
316 |
canvas.style.background = "#FEFEFD";
|
317 |
controls.maxZoom = maxZoom;
|
|
|
343 |
};
|
344 |
|
345 |
const frame = () => {
|
346 |
+
// Save the current camera position
|
347 |
+
let currentPos = camera.position.clone();
|
348 |
controls.update();
|
349 |
+
|
350 |
+
// Check if any axis exceeds its allowed limits.
|
351 |
+
if (currentPos.x < minX || currentPos.x > maxX ||
|
352 |
+
currentPos.y < minY || currentPos.y > maxY ||
|
353 |
+
currentPos.z < minZ || currentPos.z > maxZ) {
|
354 |
+
// Restore previous allowed position.
|
355 |
+
camera.position = prevCameraPos.clone();
|
356 |
+
// Optionally, you could also update controlsInstance target here if accessible.
|
357 |
+
} else {
|
358 |
+
// Otherwise, update prevCameraPos.
|
359 |
+
prevCameraPos = camera.position.clone();
|
360 |
+
}
|
361 |
+
|
362 |
renderer.render(scene, camera);
|
363 |
requestAnimationFrame(frame);
|
364 |
};
|