Cesium Note13:自定义帧数

Cesium Note13:自定义帧数

自定义帧数

  • 源代码 Source\Scene\PerformanceDisplay.js

修改代码

  • 这个参数差距有些大
const getTimestamp = () => { let getTime; if ( typeof performance !== "undefined" && typeof performance.now === "function" && isFinite(performance.now()) ) { getTime = function () { return performance.now(); }; } else { getTime = function () { return Date.now(); }; } return getTime(); } class CesiumFPSUtil { constructor(containerId: any) { proxy.id = containerId || "fpsdiv"; proxy._lastFpsSampleTime = getTimestamp(); proxy._lastMsSampleTime = getTimestamp(); proxy._fpsFrameCount = 0; proxy._msFrameCount = 0; this.createDiv(); } createDiv() { const parent = document.getElementById(proxy.id)!; const fpsDiv = document.createElement("div"); fpsDiv.className = "info-content"; proxy._fpsText = document.createElement("span"); proxy._msText = document.createElement("span"); fpsDiv.append(proxy._fpsText); fpsDiv.append(proxy._msText); parent.append(fpsDiv); } update() { let time = getTimestamp(); proxy._fpsFrameCount++; let updateDisplay = true; let fpsElapsedTime = time - proxy._lastFpsSampleTime; if (fpsElapsedTime > 1000) { var fps = "N/A"; if (updateDisplay) { fps = String(((proxy._fpsFrameCount * 1000) / fpsElapsedTime) | 0); } proxy._fpsText.innerText = fps + " FPS"; proxy._lastFpsSampleTime = time; proxy._fpsFrameCount = 0; } proxy._msFrameCount++; let msElapsedTime = time - proxy._lastMsSampleTime; if (msElapsedTime > 200) { let ms = "N/A"; if (updateDisplay) { ms = (msElapsedTime / proxy._msFrameCount).toFixed(2); } proxy._msText.innerText = ms + " MS"; proxy._lastMsSampleTime = time; proxy._msFrameCount = 0; } } } const fpsInfo = new CesiumFPSUtil('fpsdiv') var fpsPostEvent = function () { fpsInfo.update() } proxy.viewer.scene.postRender.addEventListener(fpsPostEvent)
 

我的方案

  1. 打开Cesium的默认FPS和MS
proxy.viewer.scene.debugShowFramesPerSecond = true; // 获取帧数FPS
  1. js获取Cesium默认的FPS、MS的div内容
let ms = document.getElementsByClassName("cesium-performanceDisplay-ms")[0].innerHTML; let fps = document.getElementsByClassName("cesium-performanceDisplay-fps")[0].innerHTML; state.ms = ms state.fps = fps document.getElementsByName("cesium-performanceDisplay")[0].style.display = "none";//隐藏
  1. 自定义隐藏,使用css隐藏默认的FPS和MS
:deep .cesium-performanceDisplay { display: none; }
效果图
notion image