Created
May 29, 2022 04:28
-
-
Save flushpot1125/54b480f89cb3d2d3cbdad120f6489ce6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mesh,ArcRotateCamera,PointerEventTypes, KeyboardEventTypes} from "@babylonjs/core"; | |
import { fromScene } from "../tools"; | |
import { onPointerEvent, onKeyboardEvent } from "../tools"; | |
export default class MyScript extends ArcRotateCamera { | |
@fromScene("Armature") | |
private _armature: Mesh; | |
protected constructor() { } | |
public onStart(): void { | |
this.parent = this._armature; | |
} | |
/** | |
* Request pointer lock. | |
*/ | |
@onPointerEvent(PointerEventTypes.POINTERDOWN, false) | |
private _onPointerEvent(): void { | |
const engine = this.getEngine(); | |
if (!engine.isPointerLock) { | |
engine.enterPointerlock(); | |
} | |
} | |
/** | |
* Exit pointer lock. | |
*/ | |
@onKeyboardEvent(27, KeyboardEventTypes.KEYUP) | |
private _onKeyboardEvent(): void { | |
const engine = this.getEngine(); | |
if (engine.isPointerLock) { | |
engine.exitPointerlock(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment