mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-13 22:15:41 +02:00
fps
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
// TODO: 近くのオブジェクトの原点に軸を揃えるオプション
|
||||
|
||||
const BAKE_TRANSFORM = false; // 実験的
|
||||
const SNAPSHOT_RENDERING = true; // 実験的
|
||||
const SNAPSHOT_RENDERING = false; // 実験的
|
||||
const SNAPSHOT_RENDERING_NON_SUPPORTED_OBJECTS = ['tv', 'aquarium', 'lavaLamp'];
|
||||
const IGNORE_OBJECTS: string[] = []; // for debug
|
||||
|
||||
@@ -484,6 +484,7 @@ export class RoomEngine {
|
||||
isGrabbing: false,
|
||||
isGrabbingForInstall: false,
|
||||
});
|
||||
private fps = 30;
|
||||
|
||||
constructor(roomState: RoomState, options: {
|
||||
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.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.minZ = 1/*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 frameInterval = 1000 / this.fps;
|
||||
let lastTime = performance.now();
|
||||
|
||||
this.engine.runRenderLoop(() => {
|
||||
this.scene.render();
|
||||
const currentTime = performance.now();
|
||||
const delta = currentTime - lastTime;
|
||||
|
||||
if (delta >= frameInterval) {
|
||||
this.scene.render();
|
||||
lastTime = currentTime - (delta % frameInterval);
|
||||
}
|
||||
});
|
||||
|
||||
if (SNAPSHOT_RENDERING) {
|
||||
@@ -1855,6 +1865,7 @@ export class RoomObjectPreviewEngine {
|
||||
private envMapIndoor: BABYLON.CubeTexture;
|
||||
private roomLight: BABYLON.SpotLight;
|
||||
private zGridPreviewPlane: BABYLON.Mesh;
|
||||
private fps = 60;
|
||||
|
||||
constructor(options: {
|
||||
canvas: HTMLCanvasElement;
|
||||
@@ -1921,8 +1932,17 @@ export class RoomObjectPreviewEngine {
|
||||
}
|
||||
|
||||
public async init() {
|
||||
const frameInterval = 1000 / this.fps;
|
||||
let lastTime = performance.now();
|
||||
|
||||
this.engine.runRenderLoop(() => {
|
||||
this.scene.render();
|
||||
const currentTime = performance.now();
|
||||
const delta = currentTime - lastTime;
|
||||
|
||||
if (delta >= frameInterval) {
|
||||
this.scene.render();
|
||||
lastTime = currentTime - (delta % frameInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
public camera: BABYLON.FreeCamera;
|
||||
private engine: BABYLON.AbstractEngine;
|
||||
private scene: BABYLON.Scene;
|
||||
moveSpeed = 6 / _assumedFramesPerSecond;
|
||||
preShift = false;
|
||||
codes = [];
|
||||
codesUp = ['KeyW'];
|
||||
@@ -54,12 +51,14 @@ export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointer
|
||||
onCanvasBlurObserver = null;
|
||||
onKeyboardObserver = null;
|
||||
public canMove = true;
|
||||
private fps: number;
|
||||
|
||||
constructor(camera: BABYLON.UniversalCamera) {
|
||||
constructor(camera: BABYLON.UniversalCamera, fps = 60) {
|
||||
super();
|
||||
this.camera = camera;
|
||||
this.scene = this.camera.getScene();
|
||||
this.engine = this.scene.getEngine();
|
||||
this.fps = fps;
|
||||
}
|
||||
|
||||
attachControl() {
|
||||
@@ -138,7 +137,8 @@ export class HorizontalCameraKeyboardMoveInput extends BABYLON.BaseCameraPointer
|
||||
dir.y = 0;
|
||||
dir.normalize();
|
||||
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) {
|
||||
this.camera.cameraDirection.addInPlace(move);
|
||||
|
||||
Reference in New Issue
Block a user