1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-21 20:25:36 +02:00
This commit is contained in:
syuilo
2026-04-28 16:22:08 +09:00
parent dcb834ed41
commit e88188cd6d
4 changed files with 25 additions and 110 deletions

View File

@@ -185,6 +185,7 @@ export class RoomController {
private onCanvasPointerdown(ev: PointerEvent) {
this.pointerDownPosition = { x: ev.offsetX, y: ev.offsetY };
this.canvas!.setPointerCapture(ev.pointerId);
}
private onCanvasPointerup(ev: PointerEvent) {
@@ -201,6 +202,7 @@ export class RoomController {
}
}
this.pointerDownPosition = null;
this.canvas!.releasePointerCapture(ev.pointerId);
}
public async reset(roomState?: RoomState | null, options?: RoomControllerOptions | null, canvas?: HTMLCanvasElement | null) {
@@ -256,14 +258,6 @@ export class RoomController {
}
}
public setCameraJoystickRotateVector(vec: { x: number; y: number }) {
if (this.worker != null) {
this.worker.postMessage({ type: 'call', fn: 'cameraJoystickRotate', args: [vec] });
} else if (this.engine != null) {
this.engine.cameraJoystickRotate(vec);
}
}
public enterEditMode() {
if (this.worker != null) {
this.worker.postMessage({ type: 'call', fn: 'enterEditMode' });

View File

@@ -14,7 +14,7 @@
import * as BABYLON from '@babylonjs/core';
import { registerBuiltInLoaders } from '@babylonjs/loaders/dynamic';
import { EventEmitter } from 'eventemitter3';
import { TIME_MAP, scaleMorph, camelToKebab, cm, WORLD_SCALE, getMeshesBoundingBox, Timer, getYRotationDirection, FreeCameraVirtualJoystickInput, FreeCameraManualInput } from '../utility.js';
import { TIME_MAP, scaleMorph, camelToKebab, cm, WORLD_SCALE, getMeshesBoundingBox, Timer, getYRotationDirection, FreeCameraManualInput } 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';
@@ -301,9 +301,9 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
this.camera.inputs.clear();
if (options.useVirtualJoystick) {
this.camera.inputs.add(new FreeCameraVirtualJoystickInput({
this.camera.inputs.add(new FreeCameraManualInput({
moveSensitivity: 0.015 * WORLD_SCALE,
rotationSensitivity: 0.01,
rotationSensitivity: 0.0005,
}));
this.camera.inertia = 0.75;
} else {
@@ -612,11 +612,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
}
public cameraJoystickMove(vector: { x: number; y: number; }) {
(this.camera.inputs.attached.joystick as FreeCameraVirtualJoystickInput).setJoystickMoveVector(vector);
}
public cameraJoystickRotate(vector: { x: number; y: number; }) {
(this.camera.inputs.attached.joystick as FreeCameraVirtualJoystickInput).setJoystickRotationVector(vector);
(this.camera.inputs.attached.manual as FreeCameraManualInput).setMoveVector(vector);
}
public selectObject(objectId: string | null) {

View File

@@ -618,55 +618,6 @@ export function getRgb(hex: string | number): [number, number, number] | null {
return m.map(x => parseInt(x, 16) / 255) as [number, number, number];
}
export class FreeCameraVirtualJoystickInput implements BABYLON.ICameraInput<BABYLON.FreeCamera> {
public camera: BABYLON.FreeCamera;
private moveSensitivity: number;
private rotationSensitivity: number;
private moveVector = BABYLON.Vector3.Zero();
private rotationVecX = 0;
private rotationVecY = 0;
constructor(options: {
moveSensitivity?: number;
rotationSensitivity?: number;
}) {
this.moveSensitivity = options.moveSensitivity ?? 0.01;
this.rotationSensitivity = options.rotationSensitivity ?? 0.01;
}
getClassName = () => this.constructor.name;
getSimpleName = () => 'joystick';
attachControl(noPreventDefault) {
}
detachControl() {
}
public setJoystickMoveVector(vec: { x: number; y: number }) {
this.moveVector = new BABYLON.Vector3(vec.x, 0, -vec.y).scale(this.moveSensitivity);
}
public setJoystickRotationVector(vec: { x: number; y: number }) {
let directionAdjust = 1;
if (this.camera.getScene().useRightHandedSystem) directionAdjust *= -1;
if (this.camera.parent && this.camera.parent._getWorldMatrixDeterminant() < 0) directionAdjust *= -1;
this.rotationVecX = vec.y * this.rotationSensitivity * directionAdjust;
this.rotationVecY = vec.x * this.rotationSensitivity * directionAdjust;
}
checkInputs() {
this.camera.cameraRotation.y += this.rotationVecY;
this.camera.cameraRotation.x += this.rotationVecX;
this.camera.cameraDirection.addInPlace(
BABYLON.Vector3.TransformCoordinates(this.moveVector, BABYLON.Matrix.RotationY(this.camera.rotation.y)),
);
}
}
export class FreeCameraManualInput implements BABYLON.ICameraInput<BABYLON.FreeCamera> {
public camera: BABYLON.FreeCamera;
private moveSensitivity: number;