-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcameraControls.js
More file actions
85 lines (76 loc) · 3.1 KB
/
cameraControls.js
File metadata and controls
85 lines (76 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { setupTraditionalControls } from './traditionalControls.js';
import { setupExperimentalControls } from './experimentalControls.js';
export function setupCameraControls(camera, renderer, { useExperimental = false } = {}) {
let activeControlType = 'traditional'; // Default fallback
let controlsObject = null;
if (useExperimental) {
const experimentalResult = attemptExperimentalControls(camera, renderer);
if (experimentalResult.success) {
activeControlType = 'experimental';
controlsObject = experimentalResult.controls;
console.log(`%cCONTROLS: Using experimental control scheme`, "color: #4CAF50; font-weight: bold");
} else {
console.log(`%cCONTROLS: Falling back to traditional because: ${experimentalResult.reason}`, "color: #FF9800; font-weight: bold");
}
} else {
console.log(`%cCONTROLS: Using traditional controls by configuration`, "color: #2196F3; font-weight: bold");
}
// Fallback to traditional if experimental failed or wasn't attempted
if (!controlsObject) {
controlsObject = setupTraditionalControls(camera, renderer);
}
// Return enhanced controls object with tracking
return {
...controlsObject,
getActiveControlType: () => activeControlType,
// Forward any existing getControlMode if present
getControlMode: controlsObject.getControlMode || (() => activeControlType)
};
}
function attemptExperimentalControls(camera, renderer) {
try {
// Check for basic mobile features first
if (!isLikelyMobileDevice()) {
return {
success: false,
reason: "Device doesn't appear to be mobile/touch capable",
controls: null
};
}
// Try initializing experimental controls
const controls = setupExperimentalControls(camera, renderer);
// Verify controls are working (if the implementation supports verification)
if (controls && typeof controls.update === 'function') {
return {
success: true,
reason: "",
controls: controls
};
}
return {
success: false,
reason: "Experimental controls initialized but didn't return valid controls object",
controls: null
};
} catch (e) {
return {
success: false,
reason: `Experimental controls threw an error: ${e.message}`,
controls: null
};
}
}
function isLikelyMobileDevice() {
// Check multiple indicators of mobile/touch capability
return (
// Touch events
('ontouchstart' in window ||
navigator.maxTouchPoints > 0 ||
navigator.msMaxTouchPoints > 0) &&
// Small screen (but not too small - could be hybrid device)
window.innerWidth <= 1024 &&
window.innerWidth >= 320 &&
// Mobile user agent (not perfect but helpful)
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
);
}