1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-06-05 09:24:10 +02:00
This commit is contained in:
syuilo
2026-04-14 15:50:06 +09:00
parent 28030ea3fa
commit 7e0b5ff8be
2 changed files with 29 additions and 9 deletions

View File

@@ -36,7 +36,7 @@
// TODO: 近くのオブジェクトの原点に軸を揃えるオプション // TODO: 近くのオブジェクトの原点に軸を揃えるオプション
const BAKE_TRANSFORM = false; // 実験的 const BAKE_TRANSFORM = false; // 実験的
const SNAPSHOT_RENDERING = true; // 実験的 const SNAPSHOT_RENDERING = false; // 実験的
const SNAPSHOT_RENDERING_NON_SUPPORTED_OBJECTS = ['tv', 'aquarium', 'lavaLamp']; const SNAPSHOT_RENDERING_NON_SUPPORTED_OBJECTS = ['tv', 'aquarium', 'lavaLamp'];
const IGNORE_OBJECTS: string[] = []; // for debug const IGNORE_OBJECTS: string[] = []; // for debug
@@ -484,6 +484,7 @@ export class RoomEngine {
isGrabbing: false, isGrabbing: false,
isGrabbingForInstall: false, isGrabbingForInstall: false,
}); });
private fps = 30;
constructor(roomState: RoomState, options: { constructor(roomState: RoomState, options: {
canvas: HTMLCanvasElement; canvas: HTMLCanvasElement;
@@ -534,7 +535,7 @@ export class RoomEngine {
this.camera = new BABYLON.UniversalCamera('camera', new BABYLON.Vector3(0, 130/*cm*/, 0/*cm*/), this.scene); this.camera = new BABYLON.UniversalCamera('camera', new BABYLON.Vector3(0, 130/*cm*/, 0/*cm*/), this.scene);
this.camera.inputs.removeByType('FreeCameraKeyboardMoveInput'); this.camera.inputs.removeByType('FreeCameraKeyboardMoveInput');
this.camera.inputs.add(new HorizontalCameraKeyboardMoveInput(this.camera)); this.camera.inputs.add(new HorizontalCameraKeyboardMoveInput(this.camera, this.fps));
this.camera.attachControl(this.canvas); this.camera.attachControl(this.canvas);
this.camera.minZ = 1/*cm*/; this.camera.minZ = 1/*cm*/;
this.camera.maxZ = 100000/*cm*/; this.camera.maxZ = 100000/*cm*/;
@@ -784,8 +785,17 @@ export class RoomEngine {
//const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', { diameter: 1/*cm*/ }, this.scene); //const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', { diameter: 1/*cm*/ }, this.scene);
const frameInterval = 1000 / this.fps;
let lastTime = performance.now();
this.engine.runRenderLoop(() => { this.engine.runRenderLoop(() => {
const currentTime = performance.now();
const delta = currentTime - lastTime;
if (delta >= frameInterval) {
this.scene.render(); this.scene.render();
lastTime = currentTime - (delta % frameInterval);
}
}); });
if (SNAPSHOT_RENDERING) { if (SNAPSHOT_RENDERING) {
@@ -1855,6 +1865,7 @@ export class RoomObjectPreviewEngine {
private envMapIndoor: BABYLON.CubeTexture; private envMapIndoor: BABYLON.CubeTexture;
private roomLight: BABYLON.SpotLight; private roomLight: BABYLON.SpotLight;
private zGridPreviewPlane: BABYLON.Mesh; private zGridPreviewPlane: BABYLON.Mesh;
private fps = 60;
constructor(options: { constructor(options: {
canvas: HTMLCanvasElement; canvas: HTMLCanvasElement;
@@ -1921,8 +1932,17 @@ export class RoomObjectPreviewEngine {
} }
public async init() { public async init() {
const frameInterval = 1000 / this.fps;
let lastTime = performance.now();
this.engine.runRenderLoop(() => { this.engine.runRenderLoop(() => {
const currentTime = performance.now();
const delta = currentTime - lastTime;
if (delta >= frameInterval) {
this.scene.render(); this.scene.render();
lastTime = currentTime - (delta % frameInterval);
}
}); });
} }

View File

@@ -38,13 +38,10 @@ export function yuge(scene: BABYLON.Scene, mesh: BABYLON.Mesh, offset: BABYLON.V
}; };
} }
const _assumedFramesPerSecond = 60;
export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointersInput { export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointersInput {
public camera: BABYLON.FreeCamera; public camera: BABYLON.FreeCamera;
private engine: BABYLON.AbstractEngine; private engine: BABYLON.AbstractEngine;
private scene: BABYLON.Scene; private scene: BABYLON.Scene;
moveSpeed = 6 / _assumedFramesPerSecond;
preShift = false; preShift = false;
codes = []; codes = [];
codesUp = ['KeyW']; codesUp = ['KeyW'];
@@ -54,12 +51,14 @@ export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointer
onCanvasBlurObserver = null; onCanvasBlurObserver = null;
onKeyboardObserver = null; onKeyboardObserver = null;
public canMove = true; public canMove = true;
private fps: number;
constructor(camera: BABYLON.UniversalCamera) { constructor(camera: BABYLON.UniversalCamera, fps = 60) {
super(); super();
this.camera = camera; this.camera = camera;
this.scene = this.camera.getScene(); this.scene = this.camera.getScene();
this.engine = this.scene.getEngine(); this.engine = this.scene.getEngine();
this.fps = fps;
} }
attachControl() { attachControl() {
@@ -138,7 +137,8 @@ export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointer
dir.y = 0; dir.y = 0;
dir.normalize(); dir.normalize();
const rate = this.preShift ? 3 : 1; const rate = this.preShift ? 3 : 1;
const move = dir.scale(this.moveSpeed * rate); const moveSpeed = 6 / this.fps;
const move = dir.scale(moveSpeed * rate);
if (this.canMove) { if (this.canMove) {
this.camera.cameraDirection.addInPlace(move); this.camera.cameraDirection.addInPlace(move);