Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
|
@@ -284,7 +284,7 @@
|
|
| 284 |
const camera = new SPLAT.Camera();
|
| 285 |
const controls = new SPLAT.OrbitControls(camera, canvas);
|
| 286 |
|
| 287 |
-
// Store the controls
|
| 288 |
controlsInstance = controls;
|
| 289 |
cameraInstance = camera;
|
| 290 |
|
|
@@ -293,25 +293,46 @@
|
|
| 293 |
controls.minZoom = minZoom;
|
| 294 |
controls.minAngle = minAngle;
|
| 295 |
controls.maxAngle = maxAngle;
|
| 296 |
-
// Pass the new azimuth limits to the controls (for reference
|
| 297 |
controls.minAzimuth = minAzimuth;
|
| 298 |
controls.maxAzimuth = maxAzimuth;
|
| 299 |
|
| 300 |
-
// Monkey
|
| 301 |
-
|
| 302 |
-
|
| 303 |
const { Quaternion } = SPLAT;
|
| 304 |
const originalUpdate = controls.update.bind(controls);
|
| 305 |
controls.update = () => {
|
| 306 |
originalUpdate();
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
let euler = camera.rotation.toEuler();
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
camera.rotation = Quaternion.FromEuler(euler);
|
| 316 |
};
|
| 317 |
|
|
@@ -319,11 +340,6 @@
|
|
| 319 |
initialCameraRotation = camera.rotation.clone();
|
| 320 |
|
| 321 |
canvas.style.background = "#FEFEFD";
|
| 322 |
-
controls.maxZoom = maxZoom;
|
| 323 |
-
controls.minZoom = minZoom;
|
| 324 |
-
controls.minAngle = minAngle;
|
| 325 |
-
controls.maxAngle = maxAngle;
|
| 326 |
-
|
| 327 |
controls.update();
|
| 328 |
|
| 329 |
try {
|
|
|
|
| 284 |
const camera = new SPLAT.Camera();
|
| 285 |
const controls = new SPLAT.OrbitControls(camera, canvas);
|
| 286 |
|
| 287 |
+
// Store the controls and camera instances.
|
| 288 |
controlsInstance = controls;
|
| 289 |
cameraInstance = camera;
|
| 290 |
|
|
|
|
| 293 |
controls.minZoom = minZoom;
|
| 294 |
controls.minAngle = minAngle;
|
| 295 |
controls.maxAngle = maxAngle;
|
| 296 |
+
// Pass the new azimuth limits to the controls (for reference)
|
| 297 |
controls.minAzimuth = minAzimuth;
|
| 298 |
controls.maxAzimuth = maxAzimuth;
|
| 299 |
|
| 300 |
+
// --- Monkey Patch: Throttled Damping on Azimuth Rotation ---
|
| 301 |
+
let throttleCounter = 0;
|
| 302 |
+
const throttleDelta = 2; // Apply azimuth clamping every 2 frames.
|
| 303 |
const { Quaternion } = SPLAT;
|
| 304 |
const originalUpdate = controls.update.bind(controls);
|
| 305 |
controls.update = () => {
|
| 306 |
originalUpdate();
|
| 307 |
+
throttleCounter++;
|
| 308 |
+
if (throttleCounter % throttleDelta !== 0) return;
|
| 309 |
+
|
| 310 |
+
// If azimuth limits are not effectively set, skip extra work.
|
| 311 |
+
if (minAzimuth <= -360 && maxAzimuth >= 360) return;
|
| 312 |
+
|
| 313 |
+
const minAzimuthRad = (minAzimuth * Math.PI) / 180;
|
| 314 |
+
const maxAzimuthRad = (maxAzimuth * Math.PI) / 180;
|
| 315 |
+
const threshold = 0.2; // threshold (in radians) for damping
|
| 316 |
+
|
| 317 |
+
// Convert the current camera rotation (Quaternion) to Euler angles.
|
| 318 |
let euler = camera.rotation.toEuler();
|
| 319 |
+
|
| 320 |
+
// Compute the clamped target for azimuth (assumed on Y axis).
|
| 321 |
+
const clampedY = Math.min(Math.max(euler.y, minAzimuthRad), maxAzimuthRad);
|
| 322 |
+
|
| 323 |
+
// Compute damping factor when near the limits.
|
| 324 |
+
let damping = 1; // default: no damping
|
| 325 |
+
if (euler.y < minAzimuthRad + threshold) {
|
| 326 |
+
damping = (euler.y - minAzimuthRad) / threshold;
|
| 327 |
+
} else if (euler.y > maxAzimuthRad - threshold) {
|
| 328 |
+
damping = (maxAzimuthRad - euler.y) / threshold;
|
| 329 |
+
}
|
| 330 |
+
damping = Math.max(0, Math.min(1, damping));
|
| 331 |
+
|
| 332 |
+
// Blend current azimuth with the clamped target.
|
| 333 |
+
euler.y = damping * euler.y + (1 - damping) * clampedY;
|
| 334 |
+
|
| 335 |
+
// Update the camera rotation with the modified Euler angles.
|
| 336 |
camera.rotation = Quaternion.FromEuler(euler);
|
| 337 |
};
|
| 338 |
|
|
|
|
| 340 |
initialCameraRotation = camera.rotation.clone();
|
| 341 |
|
| 342 |
canvas.style.background = "#FEFEFD";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
controls.update();
|
| 344 |
|
| 345 |
try {
|