Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created May 29, 2022 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/54b480f89cb3d2d3cbdad120f6489ce6 to your computer and use it in GitHub Desktop.
Save flushpot1125/54b480f89cb3d2d3cbdad120f6489ce6 to your computer and use it in GitHub Desktop.
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