mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-13 16:25:44 +02:00
clean up
This commit is contained in:
@@ -8,7 +8,7 @@ import { AxesViewer } from '@babylonjs/core/Debug/axesViewer';
|
||||
import { registerBuiltInLoaders } from '@babylonjs/loaders/dynamic';
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import tinycolor from 'tinycolor2';
|
||||
import { HorizontalCameraKeyboardMoveInput, RecyvlingTextGrid, Timer, WORLD_SCALE, camelToKebab, cm, createPlaneUvMapper, normalizeUvToSquare, randomRange } from './utility.js';
|
||||
import { RecyvlingTextGrid, Timer, WORLD_SCALE, camelToKebab, cm, createPlaneUvMapper, normalizeUvToSquare, randomRange } from './utility.js';
|
||||
import { TIME_MAP } from './utility.js';
|
||||
import { genId } from '@/utility/id.js';
|
||||
import { deepClone } from '@/utility/clone.js';
|
||||
|
||||
@@ -14,7 +14,7 @@ import { registerBuiltInLoaders } from '@babylonjs/loaders/dynamic';
|
||||
import { BoundingBoxRenderer } from '@babylonjs/core/Rendering/boundingBoxRenderer';
|
||||
import { GridMaterial } from '@babylonjs/materials';
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import { TIME_MAP, scaleMorph, HorizontalCameraKeyboardMoveInput, camelToKebab, cm, WORLD_SCALE, getMeshesBoundingBox, Timer } from '../utility.js';
|
||||
import { TIME_MAP, scaleMorph, camelToKebab, cm, WORLD_SCALE, getMeshesBoundingBox, Timer } from '../utility.js';
|
||||
import { getObjectDef } from './object-defs.js';
|
||||
import { findMaterial, ModelManager, SYSTEM_HEYA_MESH_NAMES, SYSTEM_MESH_NAMES } from './utility.js';
|
||||
import { SimpleHeyaManager } from './heya.js';
|
||||
|
||||
@@ -38,119 +38,6 @@ export const TIME_MAP = {
|
||||
23: 2,
|
||||
} as const;
|
||||
|
||||
export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointersInput {
|
||||
public camera: BABYLON.FreeCamera;
|
||||
private engine: BABYLON.AbstractEngine;
|
||||
private scene: BABYLON.Scene;
|
||||
preShift = false;
|
||||
codes = [];
|
||||
codesUp = ['KeyW'];
|
||||
codesDown = ['KeyS'];
|
||||
codesLeft = ['KeyA'];
|
||||
codesRight = ['KeyD'];
|
||||
onCanvasBlurObserver = null;
|
||||
onKeyboardObserver = null;
|
||||
public canMove = true;
|
||||
private moveSpeed = 0.1;
|
||||
|
||||
constructor(camera: BABYLON.UniversalCamera, moveSpeed = 0.1) {
|
||||
super();
|
||||
this.camera = camera;
|
||||
this.scene = this.camera.getScene();
|
||||
this.engine = this.scene.getEngine();
|
||||
this.moveSpeed = moveSpeed;
|
||||
}
|
||||
|
||||
attachControl() {
|
||||
if (this.onCanvasBlurObserver) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.onCanvasBlurObserver = this.engine.onCanvasBlurObservable.add(() => {
|
||||
this.codes = [];
|
||||
});
|
||||
|
||||
this.onKeyboardObserver = this.scene.onKeyboardObservable.add(({ event, type }) => {
|
||||
const { code, shiftKey } = event;
|
||||
this.preShift = shiftKey;
|
||||
|
||||
if (type === BABYLON.KeyboardEventTypes.KEYDOWN) {
|
||||
if (this.codesUp.indexOf(code) >= 0 ||
|
||||
this.codesDown.indexOf(code) >= 0 ||
|
||||
this.codesLeft.indexOf(code) >= 0 ||
|
||||
this.codesRight.indexOf(code) >= 0) {
|
||||
const index = this.codes.findIndex(v => v.code === code);
|
||||
if (index < 0) { // 存在しなかったら追加する
|
||||
this.codes.push({ code });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.codesUp.indexOf(code) >= 0 ||
|
||||
this.codesDown.indexOf(code) >= 0 ||
|
||||
this.codesLeft.indexOf(code) >= 0 ||
|
||||
this.codesRight.indexOf(code) >= 0) {
|
||||
const index = this.codes.findIndex(v => v.code === code);
|
||||
if (index >= 0) { // 存在したら削除する
|
||||
this.codes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
detachControl() {
|
||||
this.codes = [];
|
||||
|
||||
if (this.onKeyboardObserver) this.scene.onKeyboardObservable.remove(this.onKeyboardObserver);
|
||||
if (this.onCanvasBlurObserver) this.engine.onCanvasBlurObservable.remove(this.onCanvasBlurObserver);
|
||||
this.onKeyboardObserver = null;
|
||||
this.onCanvasBlurObserver = null;
|
||||
}
|
||||
|
||||
checkInputs() {
|
||||
if (!this.onKeyboardObserver) {
|
||||
return;
|
||||
}
|
||||
for (let index = 0; index < this.codes.length; index++) {
|
||||
const { code } = this.codes[index];
|
||||
|
||||
const local = new BABYLON.Vector3();
|
||||
if (this.codesLeft.indexOf(code) >= 0) {
|
||||
local.x += -1;
|
||||
} else if (this.codesUp.indexOf(code) >= 0) {
|
||||
local.z += this.scene.useRightHandedSystem ? -1 : 1;
|
||||
} else if (this.codesRight.indexOf(code) >= 0) {
|
||||
local.x += 1;
|
||||
} else if (this.codesDown.indexOf(code) >= 0) {
|
||||
local.z += this.scene.useRightHandedSystem ? 1 : -1;
|
||||
}
|
||||
|
||||
if (local.length() === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const dir = this.camera.getDirection(local.normalize());
|
||||
dir.y = 0;
|
||||
dir.normalize();
|
||||
const dashFactor = this.preShift ? 3 : 1;
|
||||
const moveSpeed = this.moveSpeed * this.scene.getAnimationRatio();
|
||||
const move = dir.scale(moveSpeed * dashFactor);
|
||||
|
||||
if (this.canMove) {
|
||||
this.camera.cameraDirection.addInPlace(move);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getClassName() {
|
||||
return 'HorizontalCameraKeyboardMoveInput';
|
||||
}
|
||||
|
||||
getSimpleName() {
|
||||
return 'horizontalkeyboard';
|
||||
}
|
||||
}
|
||||
|
||||
const nanasegNumberMap = [
|
||||
['a', 'b', 'c', 'd', 'e', 'f'], // 0
|
||||
['b', 'c'], // 1
|
||||
|
||||
Reference in New Issue
Block a user