mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-18 07:35:19 +00:00
Disable pointer lock controls if we detect safari webkit (#562)
This commit is contained in:
1 parent
9cd3b493c6
commit
420a23d359
2 files changed
+27
-1
No files matched your search
@@ -9,6 +9,28 @@ import * as THREE from "three";
|
||||
import { cameras, selectedCameraId } from "~/pages/PageEnigma/signals/camera";
|
||||
import { isPromptBoxFocused } from "~/pages/PageEnigma/signals/promptBox";
|
||||
|
||||
|
||||
export const isSafariUserAgent = () => {
|
||||
const ua = navigator.userAgent;
|
||||
|
||||
const isSafari = /^((?!chrome|android|crios|fxios).)*safari/i.test(ua);
|
||||
|
||||
return isSafari;
|
||||
}
|
||||
|
||||
export const hasApplePay = () => {
|
||||
// @ts-expect-error Apple Pay is not defined in TypeScript
|
||||
return !!window.ApplePaySession;
|
||||
}
|
||||
|
||||
export const isSafari = () => {
|
||||
return isSafariUserAgent() || hasApplePay();
|
||||
}
|
||||
|
||||
export const isPointerLockSupported = () => {
|
||||
return !isSafari();
|
||||
}
|
||||
|
||||
class FreeCam extends EventDispatcher {
|
||||
object: THREE.PerspectiveCamera;
|
||||
domElement: HTMLElement | Document;
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from "three/examples/jsm/Addons.js";
|
||||
import { TransformControls } from "./TransformControls";
|
||||
import { SceneManager, SceneObject } from "./scene_manager_api";
|
||||
import { FreeCam } from "./free_cam";
|
||||
import { FreeCam, isPointerLockSupported } from "./free_cam";
|
||||
import Stats from "three/examples/jsm/libs/stats.module.js";
|
||||
import { FKHelper } from "./KinHelpers/FKHelper";
|
||||
import {
|
||||
@@ -391,6 +391,10 @@ export class MouseControls {
|
||||
this.timeline_mouse = this.mouse;
|
||||
|
||||
// this causes an issue https://discourse.threejs.org/t/unable-to-use-pointer-lock-api/11092
|
||||
if (!isPointerLockSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isMouseClicked && this.lockControls) {
|
||||
if (this.lockControls.isLocked == false) {
|
||||
this.lockControls.lock();
|
||||
|
||||
Reference in new issue
Block a user