5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Three.jsのFPS表示(TypeScript版)

Last updated at Posted at 2020-02-01

Three.jsのTypeScript環境で stats.js のセットアップに少しハマったのでそのメモです。
stats.jsはFPSを表示するライブラリです。
ChromeのDevToolsのRenderingタブでFPS表示しても良いけど、毎回手間だったので。
スクリーンショット 2020-02-01 16.48.06.png

開発環境

Three.js: v0.113.2
states.js: 0.17.0

セットアップ手順

以下のパッケージを入れればOK!
npm i stats.js @types/stats.js

すいません、勘違いしてました。もうthree.jsにデフォルトで入ってました。

以下の感じにimportしてあげれば、型チェックもやってくれます

import Stats from 'three/examples/jsm/libs/stats.module';

const stats = new Stats();
stats.showPanel(0);
document.body.appendChild(stats.dom);

あとはループする処理にbegin()end()を入れてあげればFPSの測定ができます(参考ソース

function tick() {
  stats.begin();
  mesh.rotation.y += 0.01;
  stats.end();
  renderer.render(scene, camera);
  renderer.setAnimationLoop(tick);
}

fps.gif

類似した型定義に @types/stats があるけど、そちらでは上手く動かせなくてハマった

2020/02/27追記
以下のThree.js TutorialsはTypeScriptで書かれているので参考になると思う
Three.js Tutorials - Stats Panel

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?