XStats.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. export default class XStats {
  2. constructor(e) {
  3. E(this, "scene");
  4. E(this, "sceneInstrumentation");
  5. E(this, "engineInstrumentation");
  6. E(this, "caps");
  7. E(this, "engine");
  8. E(this, "_canvas");
  9. E(this, "_osversion");
  10. E(this, "_scenemanager");
  11. this._scenemanager = e,
  12. this.scene = e.Scene,
  13. this._canvas = e.canvas,
  14. this.initSceneInstrument()
  15. }
  16. initSceneInstrument() {
  17. this.sceneInstrumentation = new BABYLON.SceneInstrumentation(this.scene);
  18. this.sceneInstrumentation.captureCameraRenderTime = !0;
  19. this.sceneInstrumentation.captureActiveMeshesEvaluationTime = !0;
  20. this.sceneInstrumentation.captureRenderTargetsRenderTime = !0;
  21. this.sceneInstrumentation.captureFrameTime = !0;
  22. this.sceneInstrumentation.captureRenderTime = !0;
  23. this.sceneInstrumentation.captureInterFrameTime = !0;
  24. this.sceneInstrumentation.captureParticlesRenderTime = !0;
  25. this.sceneInstrumentation.captureSpritesRenderTime = !0;
  26. this.sceneInstrumentation.capturePhysicsTime = !0;
  27. this.sceneInstrumentation.captureAnimationsTime = !0;
  28. this.engineInstrumentation = new BABYLON.EngineInstrumentation(this.scene.getEngine());
  29. this.caps = this.scene.getEngine().getCaps();
  30. this.engine = this.scene.getEngine();
  31. this._osversion = this.osVersion();
  32. }
  33. getFrameTimeCounter() {
  34. return this.sceneInstrumentation.frameTimeCounter.current
  35. }
  36. getInterFrameTimeCounter() {
  37. return this.sceneInstrumentation.interFrameTimeCounter.current
  38. }
  39. getActiveMeshEvaluationTime() {
  40. return this.sceneInstrumentation.activeMeshesEvaluationTimeCounter.current
  41. }
  42. getDrawCall() {
  43. return this.sceneInstrumentation.drawCallsCounter.current
  44. }
  45. getDrawCallTime() {
  46. return this.sceneInstrumentation.renderTimeCounter.current
  47. }
  48. getAnimationTime() {
  49. return this.sceneInstrumentation.animationsTimeCounter.current
  50. }
  51. getActiveMesh() {
  52. return this.scene.getActiveMeshes().length
  53. }
  54. getActiveFaces() {
  55. return Math.round(this.scene.getActiveIndices() / 3)
  56. }
  57. getActiveBones() {
  58. return this.scene.getActiveBones()
  59. }
  60. getActiveAnimation() {
  61. return this.scene._activeAnimatables.length
  62. }
  63. getActiveParticles() {
  64. return this.scene.getActiveParticles()
  65. }
  66. getTotalMaterials() {
  67. return this.scene.materials.length
  68. }
  69. getTotalTextures() {
  70. return this.scene.textures.length
  71. }
  72. getTotalGeometries() {
  73. return this.scene.geometries.length
  74. }
  75. getTotalMeshes() {
  76. return this.scene.meshes.length
  77. }
  78. getCameraRenderTime() {
  79. return this.sceneInstrumentation.cameraRenderTimeCounter.current
  80. }
  81. getTotalRootNodes() {
  82. return this.scene.rootNodes.length
  83. }
  84. getRenderTargetRenderTime() {
  85. const e = this.getDrawCallTime()
  86. , t = this.getActiveMeshEvaluationTime()
  87. , r = this.getCameraRenderTime() - (t + e);
  88. return this.getRTT1Time() + r
  89. }
  90. getRegisterBeforeRenderTime() {
  91. return this.sceneInstrumentation.registerBeforeTimeCounter.current
  92. }
  93. getRegisterAfterRenderTime() {
  94. return this.sceneInstrumentation.registerAfterTimeCounter.current
  95. }
  96. getRTT1Time() {
  97. return this.sceneInstrumentation.getRTT1TimeCounter.current
  98. }
  99. getRegisterBeforeRenderObserverLength() {
  100. return this.scene.onBeforeRenderObservable.observers.length
  101. }
  102. getRegisterAfterRenderObserverLength() {
  103. return this.scene.onAfterRenderObservable.observers.length
  104. }
  105. getTotalMeshByType() {
  106. const e = new Map;
  107. return this.scene.meshes.forEach(t=>{
  108. e.has(t.xtype) ? e.set(t.xtype, e.get(t.xtype) + 1) : e.set(t.xtype, 1)
  109. }
  110. ),
  111. e
  112. }
  113. getHardwareRenderInfo() {
  114. return {
  115. maxTexturesUnits: this.caps.maxTexturesImageUnits,
  116. maxVertexTextureImageUnits: this.caps.maxVertexTextureImageUnits,
  117. maxCombinedTexturesImageUnits: this.caps.maxCombinedTexturesImageUnits,
  118. maxTextureSize: this.caps.maxTextureSize,
  119. maxSamples: this.caps.maxSamples,
  120. maxCubemapTextureSize: this.caps.maxCubemapTextureSize,
  121. maxRenderTextureSize: this.caps.maxRenderTextureSize,
  122. maxVertexAttribs: this.caps.maxVertexAttribs,
  123. maxVaryingVectors: this.caps.maxVaryingVectors,
  124. maxVertexUniformVectors: this.caps.maxVertexUniformVectors,
  125. maxFragmentUniformVectors: this.caps.maxFragmentUniformVectors,
  126. standardDerivatives: this.caps.standardDerivatives,
  127. supportTextureCompress: {
  128. s3tc: this.caps.s3tc !== void 0,
  129. s3tc_srgb: this.caps.s3tc_srgb !== void 0,
  130. pvrtc: this.caps.pvrtc !== void 0,
  131. etc1: this.caps.etc1 !== void 0,
  132. etc2: this.caps.etc2 !== void 0,
  133. astc: this.caps.astc !== void 0,
  134. bptc: this.caps.bptc !== void 0
  135. },
  136. textureFloat: this.caps.textureFloat,
  137. vertexArrayObject: this.caps.vertexArrayObject,
  138. textureAnisotropicFilterExtension: this.caps.textureAnisotropicFilterExtension !== void 0,
  139. maxAnisotropy: this.caps.maxAnisotropy,
  140. instancedArrays: this.caps.instancedArrays,
  141. uintIndices: this.caps.uintIndices,
  142. highPrecisionShaders: this.caps.highPrecisionShaderSupported,
  143. fragmentDepth: this.caps.fragmentDepthSupported,
  144. textureFloatLinearFiltering: this.caps.textureFloatLinearFiltering,
  145. renderToTextureFloat: this.caps.textureFloatRender,
  146. textureHalfFloat: this.caps.textureHalfFloat,
  147. textureHalfFloatLinearFiltering: this.caps.textureHalfFloatLinearFiltering,
  148. textureHalfFloatRender: this.caps.textureHalfFloatRender,
  149. textureLOD: this.caps.textureLOD,
  150. drawBuffersExtension: this.caps.drawBuffersExtension,
  151. depthTextureExtension: this.caps.depthTextureExtension,
  152. colorBufferFloat: this.caps.colorBufferFloat,
  153. supportTimerQuery: this.caps.timerQuery !== void 0,
  154. canUseTimestampForTimerQuery: this.caps.canUseTimestampForTimerQuery,
  155. supportOcclusionQuery: this.caps.supportOcclusionQuery,
  156. multiview: this.caps.multiview,
  157. oculusMultiview: this.caps.oculusMultiview,
  158. maxMSAASamples: this.caps.maxMSAASamples,
  159. blendMinMax: this.caps.blendMinMax,
  160. canUseGLInstanceID: this.caps.canUseGLInstanceID,
  161. canUseGLVertexID: this.caps.canUseGLVertexID,
  162. supportComputeShaders: this.caps.supportComputeShaders,
  163. supportSRGBBuffers: this.caps.supportSRGBBuffers,
  164. supportStencil: this.engine.isStencilEnable
  165. }
  166. }
  167. getSystemInfo() {
  168. return {
  169. resolution: "real: " + this.engine.getRenderWidth() + "x" + this.engine.getRenderHeight() + " cavs: " + this._canvas.clientWidth + "x" + this._canvas.clientHeight,
  170. hardwareScalingLevel: this.engine.getHardwareScalingLevel().toFixed(2).toString() + "_" + this._scenemanager.initEngineScaleNumber.toFixed(2).toString(),
  171. driver: this.engine.getGlInfo().renderer,
  172. vender: this.engine.getGlInfo().vendor,
  173. version: this.engine.getGlInfo().version,
  174. os: this._osversion
  175. }
  176. }
  177. getFps() {
  178. const e = this.sceneInstrumentation.frameTimeCounter.lastSecAverage
  179. , t = this.sceneInstrumentation.interFrameTimeCounter.lastSecAverage;
  180. return 1e3 / (e + t)
  181. }
  182. osVersion() {
  183. const e = window.navigator.userAgent;
  184. let t;
  185. return /iphone|ipad|ipod/gi.test(e) ? t = e.match(/OS (\d+)_(\d+)_?(\d+)?/) : /android/gi.test(e) && (t = e.match(/Android (\d+)/)),
  186. t != null && t.length > 0 ? t[0] : null
  187. }
  188. }