@2112-lab/central-plant 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/index.js +33146 -1
- package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
- package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
- package/dist/cjs/src/analysis/analysis.js +560 -1
- package/dist/cjs/src/analysis/testing.js +958 -1
- package/dist/cjs/src/core/centralPlant.js +1149 -1
- package/dist/cjs/src/core/debugLogger.js +175 -1
- package/dist/cjs/src/core/mathUtils.js +574 -1
- package/dist/cjs/src/core/nameUtils.js +93 -1
- package/dist/cjs/src/data/export.js +716 -1
- package/dist/cjs/src/data/import.js +380 -1
- package/dist/cjs/src/data/numerics.js +522 -1
- package/dist/cjs/src/helpers/sceneHelper.js +572 -1
- package/dist/cjs/src/index.js +69 -1
- package/dist/cjs/src/managers/components/animationManager.js +123 -1
- package/dist/cjs/src/managers/components/componentManager.js +332 -1
- package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
- package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
- package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
- package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
- package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
- package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
- package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
- package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
- package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
- package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
- package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
- package/dist/cjs/src/managers/system/disposalManager.js +444 -1
- package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
- package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
- package/dist/cjs/src/rendering/modelPreloader.js +369 -1
- package/dist/cjs/src/rendering/rendering2D.js +631 -1
- package/dist/cjs/src/rendering/rendering3D.js +685 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
- package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
- package/dist/esm/src/analysis/analysis.js +536 -1
- package/dist/esm/src/analysis/testing.js +954 -1
- package/dist/esm/src/core/centralPlant.js +1144 -1
- package/dist/esm/src/core/debugLogger.js +167 -1
- package/dist/esm/src/core/mathUtils.js +570 -1
- package/dist/esm/src/core/nameUtils.js +87 -1
- package/dist/esm/src/data/export.js +712 -1
- package/dist/esm/src/data/import.js +356 -1
- package/dist/esm/src/data/numerics.js +518 -1
- package/dist/esm/src/helpers/sceneHelper.js +547 -1
- package/dist/esm/src/index.js +35 -1
- package/dist/esm/src/managers/components/animationManager.js +119 -1
- package/dist/esm/src/managers/components/componentManager.js +328 -1
- package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
- package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
- package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
- package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
- package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
- package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
- package/dist/esm/src/managers/environment/environmentManager.js +690 -1
- package/dist/esm/src/managers/environment/textureConfig.js +202 -1
- package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
- package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
- package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
- package/dist/esm/src/managers/system/disposalManager.js +440 -1
- package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
- package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
- package/dist/esm/src/rendering/modelPreloader.js +364 -1
- package/dist/esm/src/rendering/rendering2D.js +627 -1
- package/dist/esm/src/rendering/rendering3D.js +661 -1
- package/package.json +1 -1
|
@@ -1 +1,863 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"t",{value:!0});var t=require("../../../_virtual/_rollupPluginBabelHelpers.js"),e=function(){return t.createClass(function e(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;t.classCallCheck(this,e),this.renderer=i,this.stats={fps:{current:0,average:0,min:1/0,max:0,history:[]},frameTime:{current:0,average:0,min:1/0,max:0,history:[]},memory:{geometries:0,textures:0,programs:0,heapUsed:0,heapTotal:0},drawCalls:{current:0,average:0,triangles:0,points:0,lines:0},gpu:{memoryUsage:0,extensions:[]},scene:{objects:0,lights:0,meshes:0,materials:0,visible:0}},this.frameCount=0,this.lastTime=performance.now(),this.updateInterval=100,this.maxHistoryLength=300,this.thresholds={fps:{good:55,warning:45,critical:30},frameTime:{good:16.67,warning:22.22,critical:33.33},memory:{warning:200,critical:300},drawCalls:{warning:500,critical:1e3}},this.callbacks=new Map,this.isMonitoring=!1,this.update=this.update.bind(this),this.getGPUInfo=this.getGPUInfo.bind(this)},[{key:"start",value:function(){this.isMonitoring=!0,this.lastTime=performance.now(),this.getGPUInfo()}},{key:"stop",value:function(){this.isMonitoring=!1}},{key:"update",value:function(){if(this.isMonitoring){var t=performance.now(),e=t-this.lastTime;this.frameCount++;var i=1e3/e,s=e;this.stats.fps.current=i,this.stats.frameTime.current=s,this.addToHistory(this.stats.fps,i),this.addToHistory(this.stats.frameTime,s),this.frameCount%this.updateInterval===0&&(this.updateAverages(),this.updateMemoryStats(),this.updateDrawCallStats(),this.updateSceneStats(),this.checkThresholds()),this.lastTime=t}}},{key:"addToHistory",value:function(t,e){t.history.push(e),t.history.length>this.maxHistoryLength&&t.history.shift(),t.min=Math.min(t.min,e),t.max=Math.max(t.max,e)}},{key:"updateAverages",value:function(){this.stats.fps.history.length>0&&(this.stats.fps.average=this.stats.fps.history.reduce(function(t,e){return t+e},0)/this.stats.fps.history.length),this.stats.frameTime.history.length>0&&(this.stats.frameTime.average=this.stats.frameTime.history.reduce(function(t,e){return t+e},0)/this.stats.frameTime.history.length)}},{key:"updateMemoryStats",value:function(){var t;if(this.renderer){var e=this.renderer.info;this.stats.memory.geometries=e.memory.geometries,this.stats.memory.textures=e.memory.textures,this.stats.memory.programs=(null===(t=e.programs)||void 0===t?void 0:t.length)||0,performance.memory&&(this.stats.memory.heapUsed=Math.round(performance.memory.usedJSHeapSize/1024/1024),this.stats.memory.heapTotal=Math.round(performance.memory.totalJSHeapSize/1024/1024))}}},{key:"updateDrawCallStats",value:function(){if(this.renderer){var t=this.renderer.info.render;this.stats.drawCalls.current=t.calls,this.stats.drawCalls.triangles=t.triangles,this.stats.drawCalls.points=t.points,this.stats.drawCalls.lines=t.lines,this.stats.drawCalls.history||(this.stats.drawCalls.history=[]),this.addToHistory(this.stats.drawCalls,t.calls),this.stats.drawCalls.history.length>0&&(this.stats.drawCalls.average=this.stats.drawCalls.history.reduce(function(t,e){return t+e},0)/this.stats.drawCalls.history.length)}}},{key:"updateSceneStats",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(e){var i,s=0,n=0,a=0,r=new Set,o=0,l=t.createForOfIteratorHelper(e.children);try{for(l.s();!(i=l.n()).done;){var h=i.value;s++,h.visible&&o++,h.isLight&&n++,h.isMesh&&(a++,h.material&&(Array.isArray(h.material)?h.material.forEach(function(t){return r.add(t.uuid)}):r.add(h.material.uuid)))}}catch(t){l.e(t)}finally{l.f()}this.stats.scene={objects:s,lights:n,meshes:a,materials:r.size,visible:o}}}},{key:"getGPUInfo",value:function(){if(this.renderer){var t=this.renderer.getContext();this.stats.gpu.extensions=t.getSupportedExtensions()||[];var e=t.getExtension("WEBGL_debug_renderer_info");e&&(this.stats.gpu.renderer=t.getParameter(e.UNMASKED_RENDERER_WEBGL),this.stats.gpu.vendor=t.getParameter(e.UNMASKED_VENDOR_WEBGL))}}},{key:"checkThresholds",value:function(){var t=[];this.stats.fps.average<this.thresholds.fps.critical?t.push({type:"critical",category:"FPS",value:this.stats.fps.average.toFixed(1),threshold:this.thresholds.fps.critical}):this.stats.fps.average<this.thresholds.fps.warning&&t.push({type:"warning",category:"FPS",value:this.stats.fps.average.toFixed(1),threshold:this.thresholds.fps.warning}),this.stats.frameTime.average>this.thresholds.frameTime.critical?t.push({type:"critical",category:"Frame Time",value:this.stats.frameTime.average.toFixed(2)+"ms",threshold:this.thresholds.frameTime.critical+"ms"}):this.stats.frameTime.average>this.thresholds.frameTime.warning&&t.push({type:"warning",category:"Frame Time",value:this.stats.frameTime.average.toFixed(2)+"ms",threshold:this.thresholds.frameTime.warning+"ms"}),this.stats.memory.heapUsed>this.thresholds.memory.critical?t.push({type:"critical",category:"Memory",value:this.stats.memory.heapUsed+"MB",threshold:this.thresholds.memory.critical+"MB"}):this.stats.memory.heapUsed>this.thresholds.memory.warning&&t.push({type:"warning",category:"Memory",value:this.stats.memory.heapUsed+"MB",threshold:this.thresholds.memory.warning+"MB"}),this.stats.drawCalls.average>this.thresholds.drawCalls.critical?t.push({type:"critical",category:"Draw Calls",value:Math.round(this.stats.drawCalls.average),threshold:this.thresholds.drawCalls.critical}):this.stats.drawCalls.average>this.thresholds.drawCalls.warning&&t.push({type:"warning",category:"Draw Calls",value:Math.round(this.stats.drawCalls.average),threshold:this.thresholds.drawCalls.warning}),t.length>0&&this.triggerCallback("warning",t)}},{key:"on",value:function(t,e){this.callbacks.has(t)||this.callbacks.set(t,[]),this.callbacks.get(t).push(e)}},{key:"off",value:function(t,e){if(this.callbacks.has(t)){var i=this.callbacks.get(t),s=i.indexOf(e);s>-1&&i.splice(s,1)}}},{key:"triggerCallback",value:function(t,e){this.callbacks.has(t)&&this.callbacks.get(t).forEach(function(t){return t(e)})}},{key:"getSummary",value:function(){return{fps:{current:Math.round(this.stats.fps.current),average:Math.round(this.stats.fps.average),min:Math.round(this.stats.fps.min),max:Math.round(this.stats.fps.max)},frameTime:{current:this.stats.frameTime.current.toFixed(2)+"ms",average:this.stats.frameTime.average.toFixed(2)+"ms"},memory:{geometries:this.stats.memory.geometries,textures:this.stats.memory.textures,heapUsed:this.stats.memory.heapUsed+"MB",heapTotal:this.stats.memory.heapTotal+"MB"},drawCalls:{current:this.stats.drawCalls.current,average:Math.round(this.stats.drawCalls.average),triangles:this.stats.drawCalls.triangles.toLocaleString()},scene:this.stats.scene}}},{key:"logSummary",value:function(){this.getSummary()}},{key:"reset",value:function(){var t=this;Object.keys(this.stats).forEach(function(e){t.stats[e].history&&(t.stats[e].history=[]),void 0!==t.stats[e].min&&(t.stats[e].min=1/0,t.stats[e].max=0,t.stats[e].average=0)}),this.frameCount=0}},{key:"exportData",value:function(){return{timestamp:(new Date).toISOString(),stats:JSON.parse(JSON.stringify(this.stats)),thresholds:this.thresholds,frameCount:this.frameCount}}}])}(),i=function(){return t.createClass(function e(i){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document.body,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"dark";t.classCallCheck(this,e),this.monitor=i,this.container=s,this.element=null,this.isVisible=!1,this.updateInterval=null,this.theme=n},[{key:"show",value:function(){var t=this;this.cleanupExistingElements(),this.element&&this.hide(),this.element=document.createElement("div"),this.element.id="performance-monitor-ui",this.element.innerHTML=this.getHTML(),this.addStyles(),this.container.appendChild(this.element),this.isVisible=!0,this.startUpdating(),this.element.querySelector("#perf-toggle").addEventListener("click",function(){return t.toggleDetails()}),this.toggleDetails()}},{key:"cleanupExistingElements",value:function(){document.querySelectorAll("#performance-monitor-ui").forEach(function(t){try{t.parentNode&&t.parentNode.removeChild(t)}catch(t){}})}},{key:"hide",value:function(){this.stopUpdating(),this.removeDOMElement(),this.isVisible=!1}},{key:"dispose",value:function(){this.hide(),this.cleanupExistingElements(),this.monitor=null,this.container=null,this.element=null}},{key:"stopUpdating",value:function(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=null)}},{key:"removeDOMElement",value:function(){if(this.element){try{this.element.parentNode&&this.container&&this.container.contains(this.element)?this.container.removeChild(this.element):this.element.parentNode&&this.element.parentNode.removeChild(this.element)}catch(t){try{this.element.remove&&this.element.remove()}catch(t){}}this.element=null}}},{key:"toggleDetails",value:function(){var t=this.element.querySelector("#perf-details"),e="none"===t.style.display;t.style.display=e?"block":"none",this.element.querySelector("#perf-toggle").textContent=e?"▼":"▲"}},{key:"startUpdating",value:function(){var t=this;this.updateInterval=setInterval(function(){t.isVisible&&t.element&&t.updateContent()},500)}},{key:"updateContent",value:function(){var t=this.monitor.getSummary();this.updateElement("#fps-value",t.fps.current),this.updateElement("#frametime-value",t.frameTime.current),this.updateElement("#memory-value",t.memory.heapUsed),this.updateElement("#drawcalls-value",t.drawCalls.current),this.updateElement("#fps-avg",t.fps.average),this.updateElement("#fps-min",t.fps.min),this.updateElement("#fps-max",t.fps.max),this.updateElement("#geometries-value",t.memory.geometries),this.updateElement("#textures-value",t.memory.textures),this.updateElement("#triangles-value",t.drawCalls.triangles),this.updateElement("#objects-value",t.scene.objects),this.updateElement("#meshes-value",t.scene.meshes),this.updatePerformanceIndicators(t)}},{key:"updateElement",value:function(t,e){var i=this.element.querySelector(t);i&&(i.textContent=e)}},{key:"updatePerformanceIndicators",value:function(t){var e=this.element.querySelector("#fps-value"),i=this.element.querySelector("#frametime-value");if(e){var s=t.fps.current;e.className=this.getPerformanceClass("fps",s)}if(i){var n=parseFloat(t.frameTime.current);i.className=this.getPerformanceClass("frameTime",n)}}},{key:"getPerformanceClass",value:function(t,e){var i=this.monitor.thresholds[t];return"fps"===t?e>=i.good?"perf-good":e>=i.warning?"perf-warning":"perf-critical":"frameTime"===t?e<=i.good?"perf-good":e<=i.warning?"perf-warning":"perf-critical":""}},{key:"getHTML",value:function(){return'\n <div class="perf-header">\n <span class="perf-title">Performance</span>\n <button id="perf-toggle">▼</button>\n </div>\n <div class="perf-main">\n <div class="perf-stat">\n <span class="perf-label">FPS:</span>\n <span id="fps-value" class="perf-value">0</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Frame:</span>\n <span id="frametime-value" class="perf-value">0ms</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Memory:</span>\n <span id="memory-value" class="perf-value">0MB</span>\n </div>\n <div class="perf-stat">\n <span class="perf-label">Calls:</span>\n <span id="drawcalls-value" class="perf-value">0</span>\n </div>\n </div>\n <div id="perf-details" class="perf-details">\n <div class="perf-section">\n <div class="perf-section-title">FPS Stats</div>\n <div class="perf-detail">Avg: <span id="fps-avg">0</span></div>\n <div class="perf-detail">Min: <span id="fps-min">0</span></div>\n <div class="perf-detail">Max: <span id="fps-max">0</span></div>\n </div>\n <div class="perf-section">\n <div class="perf-section-title">Memory</div>\n <div class="perf-detail">Geometries: <span id="geometries-value">0</span></div>\n <div class="perf-detail">Textures: <span id="textures-value">0</span></div>\n </div>\n <div class="perf-section">\n <div class="perf-section-title">Rendering</div>\n <div class="perf-detail">Triangles: <span id="triangles-value">0</span></div>\n <div class="perf-detail">Objects: <span id="objects-value">0</span></div>\n <div class="perf-detail">Meshes: <span id="meshes-value">0</span></div>\n </div>\n </div>\n '}},{key:"addStyles",value:function(){if(!document.getElementById("performance-monitor-styles")){var t=document.createElement("style");t.id="performance-monitor-styles";var e={dark:{background:"rgba(0, 0, 0, 0.8)",color:"white",borderColor:"rgba(255, 255, 255, 0.1)",separatorColor:"rgba(255, 255, 255, 0.2)",sectionTitleColor:"#FFC107",goodColor:"#4CAF50",warningColor:"#FF9800",criticalColor:"#F44336"},light:{background:"rgba(255, 255, 255, 0.95)",color:"#333333",borderColor:"rgba(0, 0, 0, 0.15)",separatorColor:"rgba(0, 0, 0, 0.1)",sectionTitleColor:"#1565C0",goodColor:"#2E7D32",warningColor:"#E65100",criticalColor:"#C62828"}},i=e[this.theme]||e.dark;t.textContent=" #performance-monitor-ui {\n position: fixed;\n bottom: 10px;\n right: 10px;\n background: ".concat(i.background,";\n color: ").concat(i.color,";\n font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n font-size: 12px;\n padding: 10px;\n border-radius: 5px;\n z-index: 10000;\n min-width: 150px;\n backdrop-filter: blur(5px);\n border: 1px solid ").concat(i.borderColor,";\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n }\n\n .perf-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 8px;\n border-bottom: 1px solid ").concat(i.separatorColor,";\n padding-bottom: 5px;\n }\n\n .perf-title {\n font-weight: bold;\n font-size: 14px;\n }\n\n #perf-toggle {\n background: none;\n border: none;\n color: ").concat(i.color,";\n cursor: pointer;\n font-size: 12px;\n padding: 0;\n width: 20px;\n height: 20px;\n }\n\n .perf-main {\n display: grid;\n grid-template-columns: 1fr;\n gap: 4px;\n }\n\n .perf-stat {\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n\n .perf-label {\n opacity: 0.8;\n }\n\n .perf-value {\n font-weight: bold;\n text-align: right;\n min-width: 50px;\n } .perf-good {\n color: ").concat(i.goodColor,";\n }\n\n .perf-warning {\n color: ").concat(i.warningColor,";\n }\n\n .perf-critical {\n color: ").concat(i.criticalColor,";\n }\n\n .perf-details {\n margin-top: 10px;\n padding-top: 8px;\n border-top: 1px solid ").concat(i.separatorColor,";\n }\n\n .perf-section {\n margin-bottom: 8px;\n }\n\n .perf-section-title {\n font-weight: bold;\n font-size: 11px;\n margin-bottom: 3px;\n color: ").concat(i.sectionTitleColor,";\n }\n\n .perf-detail {\n font-size: 10px;\n display: flex;\n justify-content: space-between;\n margin-bottom: 2px;\n opacity: 0.9;\n }\n "),document.head.appendChild(t)}}},{key:"setTheme",value:function(t){if("light"===t||"dark"===t){this.theme=t;var e=document.getElementById("performance-monitor-styles");e&&e.remove(),this.addStyles()}}}],[{key:"cleanupAllInstances",value:function(){var t=document.querySelectorAll("#performance-monitor-ui"),e=0;if(t.forEach(function(t){try{t.parentNode&&(t.parentNode.removeChild(t),e++)}catch(t){}}),0===document.querySelectorAll("#performance-monitor-ui").length){var i=document.getElementById("performance-monitor-styles");i&&i.remove()}return e}}])}();exports.PerformanceMonitor=e,exports.PerformanceUI=i;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Performance Monitor for Three.js Applications
|
|
9
|
+
* Tracks rendering performance across multiple categories
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var PerformanceMonitor = /*#__PURE__*/function () {
|
|
13
|
+
function PerformanceMonitor() {
|
|
14
|
+
var renderer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
15
|
+
_rollupPluginBabelHelpers.classCallCheck(this, PerformanceMonitor);
|
|
16
|
+
this.renderer = renderer;
|
|
17
|
+
this.stats = {
|
|
18
|
+
fps: {
|
|
19
|
+
current: 0,
|
|
20
|
+
average: 0,
|
|
21
|
+
min: Infinity,
|
|
22
|
+
max: 0,
|
|
23
|
+
history: []
|
|
24
|
+
},
|
|
25
|
+
frameTime: {
|
|
26
|
+
current: 0,
|
|
27
|
+
average: 0,
|
|
28
|
+
min: Infinity,
|
|
29
|
+
max: 0,
|
|
30
|
+
history: []
|
|
31
|
+
},
|
|
32
|
+
memory: {
|
|
33
|
+
geometries: 0,
|
|
34
|
+
textures: 0,
|
|
35
|
+
programs: 0,
|
|
36
|
+
heapUsed: 0,
|
|
37
|
+
heapTotal: 0
|
|
38
|
+
},
|
|
39
|
+
drawCalls: {
|
|
40
|
+
current: 0,
|
|
41
|
+
average: 0,
|
|
42
|
+
triangles: 0,
|
|
43
|
+
points: 0,
|
|
44
|
+
lines: 0
|
|
45
|
+
},
|
|
46
|
+
gpu: {
|
|
47
|
+
memoryUsage: 0,
|
|
48
|
+
extensions: []
|
|
49
|
+
},
|
|
50
|
+
scene: {
|
|
51
|
+
objects: 0,
|
|
52
|
+
lights: 0,
|
|
53
|
+
meshes: 0,
|
|
54
|
+
materials: 0,
|
|
55
|
+
visible: 0
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.frameCount = 0;
|
|
59
|
+
this.lastTime = performance.now();
|
|
60
|
+
this.updateInterval = 100; // Update stats every 100 frames
|
|
61
|
+
this.maxHistoryLength = 300; // Keep 5 seconds of history at 60fps
|
|
62
|
+
|
|
63
|
+
// Performance thresholds
|
|
64
|
+
this.thresholds = {
|
|
65
|
+
fps: {
|
|
66
|
+
good: 55,
|
|
67
|
+
warning: 45,
|
|
68
|
+
critical: 30
|
|
69
|
+
},
|
|
70
|
+
frameTime: {
|
|
71
|
+
good: 16.67,
|
|
72
|
+
warning: 22.22,
|
|
73
|
+
critical: 33.33
|
|
74
|
+
},
|
|
75
|
+
// ms
|
|
76
|
+
memory: {
|
|
77
|
+
warning: 200,
|
|
78
|
+
critical: 300
|
|
79
|
+
},
|
|
80
|
+
// MB
|
|
81
|
+
drawCalls: {
|
|
82
|
+
warning: 500,
|
|
83
|
+
critical: 1000
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.callbacks = new Map();
|
|
87
|
+
this.isMonitoring = false;
|
|
88
|
+
|
|
89
|
+
// Bind methods
|
|
90
|
+
this.update = this.update.bind(this);
|
|
91
|
+
this.getGPUInfo = this.getGPUInfo.bind(this);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Start monitoring performance
|
|
96
|
+
*/
|
|
97
|
+
return _rollupPluginBabelHelpers.createClass(PerformanceMonitor, [{
|
|
98
|
+
key: "start",
|
|
99
|
+
value: function start() {
|
|
100
|
+
this.isMonitoring = true;
|
|
101
|
+
this.lastTime = performance.now();
|
|
102
|
+
console.log('🔍 Performance monitoring started');
|
|
103
|
+
|
|
104
|
+
// Get initial GPU info
|
|
105
|
+
this.getGPUInfo();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Stop monitoring performance
|
|
110
|
+
*/
|
|
111
|
+
}, {
|
|
112
|
+
key: "stop",
|
|
113
|
+
value: function stop() {
|
|
114
|
+
this.isMonitoring = false;
|
|
115
|
+
console.log('⏹️ Performance monitoring stopped');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Update performance stats - call this in your animation loop
|
|
120
|
+
*/
|
|
121
|
+
}, {
|
|
122
|
+
key: "update",
|
|
123
|
+
value: function update() {
|
|
124
|
+
if (!this.isMonitoring) return;
|
|
125
|
+
var currentTime = performance.now();
|
|
126
|
+
var deltaTime = currentTime - this.lastTime;
|
|
127
|
+
this.frameCount++;
|
|
128
|
+
|
|
129
|
+
// Update FPS and frame time
|
|
130
|
+
var fps = 1000 / deltaTime;
|
|
131
|
+
var frameTime = deltaTime;
|
|
132
|
+
this.stats.fps.current = fps;
|
|
133
|
+
this.stats.frameTime.current = frameTime;
|
|
134
|
+
|
|
135
|
+
// Update history
|
|
136
|
+
this.addToHistory(this.stats.fps, fps);
|
|
137
|
+
this.addToHistory(this.stats.frameTime, frameTime);
|
|
138
|
+
|
|
139
|
+
// Update averages and min/max every updateInterval frames
|
|
140
|
+
if (this.frameCount % this.updateInterval === 0) {
|
|
141
|
+
this.updateAverages();
|
|
142
|
+
this.updateMemoryStats();
|
|
143
|
+
this.updateDrawCallStats();
|
|
144
|
+
this.updateSceneStats();
|
|
145
|
+
this.checkThresholds();
|
|
146
|
+
}
|
|
147
|
+
this.lastTime = currentTime;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Add value to history and update min/max
|
|
152
|
+
*/
|
|
153
|
+
}, {
|
|
154
|
+
key: "addToHistory",
|
|
155
|
+
value: function addToHistory(statObject, value) {
|
|
156
|
+
statObject.history.push(value);
|
|
157
|
+
if (statObject.history.length > this.maxHistoryLength) {
|
|
158
|
+
statObject.history.shift();
|
|
159
|
+
}
|
|
160
|
+
statObject.min = Math.min(statObject.min, value);
|
|
161
|
+
statObject.max = Math.max(statObject.max, value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Update average values
|
|
166
|
+
*/
|
|
167
|
+
}, {
|
|
168
|
+
key: "updateAverages",
|
|
169
|
+
value: function updateAverages() {
|
|
170
|
+
// FPS average
|
|
171
|
+
if (this.stats.fps.history.length > 0) {
|
|
172
|
+
this.stats.fps.average = this.stats.fps.history.reduce(function (a, b) {
|
|
173
|
+
return a + b;
|
|
174
|
+
}, 0) / this.stats.fps.history.length;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Frame time average
|
|
178
|
+
if (this.stats.frameTime.history.length > 0) {
|
|
179
|
+
this.stats.frameTime.average = this.stats.frameTime.history.reduce(function (a, b) {
|
|
180
|
+
return a + b;
|
|
181
|
+
}, 0) / this.stats.frameTime.history.length;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Update memory statistics
|
|
187
|
+
*/
|
|
188
|
+
}, {
|
|
189
|
+
key: "updateMemoryStats",
|
|
190
|
+
value: function updateMemoryStats() {
|
|
191
|
+
var _info$programs;
|
|
192
|
+
if (!this.renderer) return;
|
|
193
|
+
var info = this.renderer.info;
|
|
194
|
+
this.stats.memory.geometries = info.memory.geometries;
|
|
195
|
+
this.stats.memory.textures = info.memory.textures;
|
|
196
|
+
this.stats.memory.programs = ((_info$programs = info.programs) === null || _info$programs === void 0 ? void 0 : _info$programs.length) || 0;
|
|
197
|
+
|
|
198
|
+
// Get JavaScript heap usage if available
|
|
199
|
+
if (performance.memory) {
|
|
200
|
+
this.stats.memory.heapUsed = Math.round(performance.memory.usedJSHeapSize / 1024 / 1024);
|
|
201
|
+
this.stats.memory.heapTotal = Math.round(performance.memory.totalJSHeapSize / 1024 / 1024);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Update draw call statistics
|
|
207
|
+
*/
|
|
208
|
+
}, {
|
|
209
|
+
key: "updateDrawCallStats",
|
|
210
|
+
value: function updateDrawCallStats() {
|
|
211
|
+
if (!this.renderer) return;
|
|
212
|
+
var info = this.renderer.info.render;
|
|
213
|
+
this.stats.drawCalls.current = info.calls;
|
|
214
|
+
this.stats.drawCalls.triangles = info.triangles;
|
|
215
|
+
this.stats.drawCalls.points = info.points;
|
|
216
|
+
this.stats.drawCalls.lines = info.lines;
|
|
217
|
+
|
|
218
|
+
// Calculate draw calls average
|
|
219
|
+
if (!this.stats.drawCalls.history) {
|
|
220
|
+
this.stats.drawCalls.history = [];
|
|
221
|
+
}
|
|
222
|
+
this.addToHistory(this.stats.drawCalls, info.calls);
|
|
223
|
+
if (this.stats.drawCalls.history.length > 0) {
|
|
224
|
+
this.stats.drawCalls.average = this.stats.drawCalls.history.reduce(function (a, b) {
|
|
225
|
+
return a + b;
|
|
226
|
+
}, 0) / this.stats.drawCalls.history.length;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Update scene statistics
|
|
232
|
+
*/
|
|
233
|
+
}, {
|
|
234
|
+
key: "updateSceneStats",
|
|
235
|
+
value: function updateSceneStats() {
|
|
236
|
+
var scene = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
237
|
+
if (!scene) return;
|
|
238
|
+
var objects = 0;
|
|
239
|
+
var lights = 0;
|
|
240
|
+
var meshes = 0;
|
|
241
|
+
var materials = new Set();
|
|
242
|
+
var visible = 0;
|
|
243
|
+
var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(scene.children),
|
|
244
|
+
_step;
|
|
245
|
+
try {
|
|
246
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
247
|
+
var child = _step.value;
|
|
248
|
+
objects++;
|
|
249
|
+
if (child.visible) {
|
|
250
|
+
visible++;
|
|
251
|
+
}
|
|
252
|
+
if (child.isLight) {
|
|
253
|
+
lights++;
|
|
254
|
+
}
|
|
255
|
+
if (child.isMesh) {
|
|
256
|
+
meshes++;
|
|
257
|
+
if (child.material) {
|
|
258
|
+
if (Array.isArray(child.material)) {
|
|
259
|
+
child.material.forEach(function (mat) {
|
|
260
|
+
return materials.add(mat.uuid);
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
materials.add(child.material.uuid);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} catch (err) {
|
|
269
|
+
_iterator.e(err);
|
|
270
|
+
} finally {
|
|
271
|
+
_iterator.f();
|
|
272
|
+
}
|
|
273
|
+
this.stats.scene = {
|
|
274
|
+
objects: objects,
|
|
275
|
+
lights: lights,
|
|
276
|
+
meshes: meshes,
|
|
277
|
+
materials: materials.size,
|
|
278
|
+
visible: visible
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Get GPU information
|
|
284
|
+
*/
|
|
285
|
+
}, {
|
|
286
|
+
key: "getGPUInfo",
|
|
287
|
+
value: function getGPUInfo() {
|
|
288
|
+
if (!this.renderer) return;
|
|
289
|
+
var gl = this.renderer.getContext();
|
|
290
|
+
|
|
291
|
+
// Get GPU extensions
|
|
292
|
+
this.stats.gpu.extensions = gl.getSupportedExtensions() || [];
|
|
293
|
+
|
|
294
|
+
// Try to get GPU memory info (Chrome only)
|
|
295
|
+
var memInfo = gl.getExtension('WEBGL_debug_renderer_info');
|
|
296
|
+
if (memInfo) {
|
|
297
|
+
this.stats.gpu.renderer = gl.getParameter(memInfo.UNMASKED_RENDERER_WEBGL);
|
|
298
|
+
this.stats.gpu.vendor = gl.getParameter(memInfo.UNMASKED_VENDOR_WEBGL);
|
|
299
|
+
}
|
|
300
|
+
console.log('🎮 GPU Info:', {
|
|
301
|
+
renderer: this.stats.gpu.renderer,
|
|
302
|
+
vendor: this.stats.gpu.vendor,
|
|
303
|
+
extensions: this.stats.gpu.extensions.length
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Check performance thresholds and trigger warnings
|
|
309
|
+
*/
|
|
310
|
+
}, {
|
|
311
|
+
key: "checkThresholds",
|
|
312
|
+
value: function checkThresholds() {
|
|
313
|
+
var warnings = [];
|
|
314
|
+
|
|
315
|
+
// Check FPS
|
|
316
|
+
if (this.stats.fps.average < this.thresholds.fps.critical) {
|
|
317
|
+
warnings.push({
|
|
318
|
+
type: 'critical',
|
|
319
|
+
category: 'FPS',
|
|
320
|
+
value: this.stats.fps.average.toFixed(1),
|
|
321
|
+
threshold: this.thresholds.fps.critical
|
|
322
|
+
});
|
|
323
|
+
} else if (this.stats.fps.average < this.thresholds.fps.warning) {
|
|
324
|
+
warnings.push({
|
|
325
|
+
type: 'warning',
|
|
326
|
+
category: 'FPS',
|
|
327
|
+
value: this.stats.fps.average.toFixed(1),
|
|
328
|
+
threshold: this.thresholds.fps.warning
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Check frame time
|
|
333
|
+
if (this.stats.frameTime.average > this.thresholds.frameTime.critical) {
|
|
334
|
+
warnings.push({
|
|
335
|
+
type: 'critical',
|
|
336
|
+
category: 'Frame Time',
|
|
337
|
+
value: this.stats.frameTime.average.toFixed(2) + 'ms',
|
|
338
|
+
threshold: this.thresholds.frameTime.critical + 'ms'
|
|
339
|
+
});
|
|
340
|
+
} else if (this.stats.frameTime.average > this.thresholds.frameTime.warning) {
|
|
341
|
+
warnings.push({
|
|
342
|
+
type: 'warning',
|
|
343
|
+
category: 'Frame Time',
|
|
344
|
+
value: this.stats.frameTime.average.toFixed(2) + 'ms',
|
|
345
|
+
threshold: this.thresholds.frameTime.warning + 'ms'
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Check memory
|
|
350
|
+
if (this.stats.memory.heapUsed > this.thresholds.memory.critical) {
|
|
351
|
+
warnings.push({
|
|
352
|
+
type: 'critical',
|
|
353
|
+
category: 'Memory',
|
|
354
|
+
value: this.stats.memory.heapUsed + 'MB',
|
|
355
|
+
threshold: this.thresholds.memory.critical + 'MB'
|
|
356
|
+
});
|
|
357
|
+
} else if (this.stats.memory.heapUsed > this.thresholds.memory.warning) {
|
|
358
|
+
warnings.push({
|
|
359
|
+
type: 'warning',
|
|
360
|
+
category: 'Memory',
|
|
361
|
+
value: this.stats.memory.heapUsed + 'MB',
|
|
362
|
+
threshold: this.thresholds.memory.warning + 'MB'
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Check draw calls
|
|
367
|
+
if (this.stats.drawCalls.average > this.thresholds.drawCalls.critical) {
|
|
368
|
+
warnings.push({
|
|
369
|
+
type: 'critical',
|
|
370
|
+
category: 'Draw Calls',
|
|
371
|
+
value: Math.round(this.stats.drawCalls.average),
|
|
372
|
+
threshold: this.thresholds.drawCalls.critical
|
|
373
|
+
});
|
|
374
|
+
} else if (this.stats.drawCalls.average > this.thresholds.drawCalls.warning) {
|
|
375
|
+
warnings.push({
|
|
376
|
+
type: 'warning',
|
|
377
|
+
category: 'Draw Calls',
|
|
378
|
+
value: Math.round(this.stats.drawCalls.average),
|
|
379
|
+
threshold: this.thresholds.drawCalls.warning
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Trigger callbacks for warnings
|
|
384
|
+
if (warnings.length > 0) {
|
|
385
|
+
this.triggerCallback('warning', warnings);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Add callback for specific events
|
|
391
|
+
*/
|
|
392
|
+
}, {
|
|
393
|
+
key: "on",
|
|
394
|
+
value: function on(event, callback) {
|
|
395
|
+
if (!this.callbacks.has(event)) {
|
|
396
|
+
this.callbacks.set(event, []);
|
|
397
|
+
}
|
|
398
|
+
this.callbacks.get(event).push(callback);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Remove callback
|
|
403
|
+
*/
|
|
404
|
+
}, {
|
|
405
|
+
key: "off",
|
|
406
|
+
value: function off(event, callback) {
|
|
407
|
+
if (this.callbacks.has(event)) {
|
|
408
|
+
var callbacks = this.callbacks.get(event);
|
|
409
|
+
var index = callbacks.indexOf(callback);
|
|
410
|
+
if (index > -1) {
|
|
411
|
+
callbacks.splice(index, 1);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Trigger callbacks
|
|
418
|
+
*/
|
|
419
|
+
}, {
|
|
420
|
+
key: "triggerCallback",
|
|
421
|
+
value: function triggerCallback(event, data) {
|
|
422
|
+
if (this.callbacks.has(event)) {
|
|
423
|
+
this.callbacks.get(event).forEach(function (callback) {
|
|
424
|
+
return callback(data);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Get performance summary
|
|
431
|
+
*/
|
|
432
|
+
}, {
|
|
433
|
+
key: "getSummary",
|
|
434
|
+
value: function getSummary() {
|
|
435
|
+
return {
|
|
436
|
+
fps: {
|
|
437
|
+
current: Math.round(this.stats.fps.current),
|
|
438
|
+
average: Math.round(this.stats.fps.average),
|
|
439
|
+
min: Math.round(this.stats.fps.min),
|
|
440
|
+
max: Math.round(this.stats.fps.max)
|
|
441
|
+
},
|
|
442
|
+
frameTime: {
|
|
443
|
+
current: this.stats.frameTime.current.toFixed(2) + 'ms',
|
|
444
|
+
average: this.stats.frameTime.average.toFixed(2) + 'ms'
|
|
445
|
+
},
|
|
446
|
+
memory: {
|
|
447
|
+
geometries: this.stats.memory.geometries,
|
|
448
|
+
textures: this.stats.memory.textures,
|
|
449
|
+
heapUsed: this.stats.memory.heapUsed + 'MB',
|
|
450
|
+
heapTotal: this.stats.memory.heapTotal + 'MB'
|
|
451
|
+
},
|
|
452
|
+
drawCalls: {
|
|
453
|
+
current: this.stats.drawCalls.current,
|
|
454
|
+
average: Math.round(this.stats.drawCalls.average),
|
|
455
|
+
triangles: this.stats.drawCalls.triangles.toLocaleString()
|
|
456
|
+
},
|
|
457
|
+
scene: this.stats.scene
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Log performance summary to console
|
|
463
|
+
*/
|
|
464
|
+
}, {
|
|
465
|
+
key: "logSummary",
|
|
466
|
+
value: function logSummary() {
|
|
467
|
+
var summary = this.getSummary();
|
|
468
|
+
console.group('📊 Performance Summary');
|
|
469
|
+
console.log('🎯 FPS:', summary.fps);
|
|
470
|
+
console.log('⏱️ Frame Time:', summary.frameTime);
|
|
471
|
+
console.log('💾 Memory:', summary.memory);
|
|
472
|
+
console.log('🎨 Draw Calls:', summary.drawCalls);
|
|
473
|
+
console.log('🏗️ Scene:', summary.scene);
|
|
474
|
+
console.groupEnd();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Reset all statistics
|
|
479
|
+
*/
|
|
480
|
+
}, {
|
|
481
|
+
key: "reset",
|
|
482
|
+
value: function reset() {
|
|
483
|
+
var _this = this;
|
|
484
|
+
Object.keys(this.stats).forEach(function (category) {
|
|
485
|
+
if (_this.stats[category].history) {
|
|
486
|
+
_this.stats[category].history = [];
|
|
487
|
+
}
|
|
488
|
+
if (_this.stats[category].min !== undefined) {
|
|
489
|
+
_this.stats[category].min = Infinity;
|
|
490
|
+
_this.stats[category].max = 0;
|
|
491
|
+
_this.stats[category].average = 0;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
this.frameCount = 0;
|
|
495
|
+
console.log('🔄 Performance stats reset');
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Export performance data for analysis
|
|
500
|
+
*/
|
|
501
|
+
}, {
|
|
502
|
+
key: "exportData",
|
|
503
|
+
value: function exportData() {
|
|
504
|
+
return {
|
|
505
|
+
timestamp: new Date().toISOString(),
|
|
506
|
+
stats: JSON.parse(JSON.stringify(this.stats)),
|
|
507
|
+
thresholds: this.thresholds,
|
|
508
|
+
frameCount: this.frameCount
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}]);
|
|
512
|
+
}();
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Performance UI overlay for real-time monitoring
|
|
516
|
+
*/
|
|
517
|
+
var PerformanceUI = /*#__PURE__*/function () {
|
|
518
|
+
function PerformanceUI(monitor) {
|
|
519
|
+
var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
|
|
520
|
+
var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'dark';
|
|
521
|
+
_rollupPluginBabelHelpers.classCallCheck(this, PerformanceUI);
|
|
522
|
+
this.monitor = monitor;
|
|
523
|
+
this.container = container;
|
|
524
|
+
this.element = null;
|
|
525
|
+
this.isVisible = false;
|
|
526
|
+
this.updateInterval = null;
|
|
527
|
+
this.theme = theme;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Create and show the performance UI overlay
|
|
531
|
+
*/
|
|
532
|
+
return _rollupPluginBabelHelpers.createClass(PerformanceUI, [{
|
|
533
|
+
key: "show",
|
|
534
|
+
value: function show() {
|
|
535
|
+
var _this2 = this;
|
|
536
|
+
// First, clean up any existing performance monitor UI elements globally
|
|
537
|
+
this.cleanupExistingElements();
|
|
538
|
+
if (this.element) {
|
|
539
|
+
this.hide();
|
|
540
|
+
}
|
|
541
|
+
this.element = document.createElement('div');
|
|
542
|
+
this.element.id = 'performance-monitor-ui';
|
|
543
|
+
this.element.innerHTML = this.getHTML();
|
|
544
|
+
this.addStyles();
|
|
545
|
+
this.container.appendChild(this.element);
|
|
546
|
+
this.isVisible = true;
|
|
547
|
+
this.startUpdating();
|
|
548
|
+
|
|
549
|
+
// Add toggle functionality
|
|
550
|
+
var toggleBtn = this.element.querySelector('#perf-toggle');
|
|
551
|
+
toggleBtn.addEventListener('click', function () {
|
|
552
|
+
return _this2.toggleDetails();
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// Start in collapsed state
|
|
556
|
+
this.toggleDetails();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Clean up any existing performance monitor UI elements in the document
|
|
561
|
+
*/
|
|
562
|
+
}, {
|
|
563
|
+
key: "cleanupExistingElements",
|
|
564
|
+
value: function cleanupExistingElements() {
|
|
565
|
+
// Remove all existing performance monitor UI elements
|
|
566
|
+
var existingElements = document.querySelectorAll('#performance-monitor-ui');
|
|
567
|
+
existingElements.forEach(function (element) {
|
|
568
|
+
try {
|
|
569
|
+
if (element.parentNode) {
|
|
570
|
+
element.parentNode.removeChild(element);
|
|
571
|
+
}
|
|
572
|
+
} catch (error) {
|
|
573
|
+
console.warn('⚠️ Error removing existing performance monitor element:', error);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
console.log("\uD83E\uDDF9 Cleaned up ".concat(existingElements.length, " existing performance monitor elements"));
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Hide the performance UI overlay
|
|
581
|
+
*/
|
|
582
|
+
}, {
|
|
583
|
+
key: "hide",
|
|
584
|
+
value: function hide() {
|
|
585
|
+
this.stopUpdating();
|
|
586
|
+
this.removeDOMElement();
|
|
587
|
+
this.isVisible = false;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Proper disposal method for complete cleanup
|
|
592
|
+
*/
|
|
593
|
+
}, {
|
|
594
|
+
key: "dispose",
|
|
595
|
+
value: function dispose() {
|
|
596
|
+
console.log('🧹 Disposing PerformanceUI...');
|
|
597
|
+
this.hide();
|
|
598
|
+
|
|
599
|
+
// Clean up any remaining elements globally
|
|
600
|
+
this.cleanupExistingElements();
|
|
601
|
+
|
|
602
|
+
// Clean up all references
|
|
603
|
+
this.monitor = null;
|
|
604
|
+
this.container = null;
|
|
605
|
+
this.element = null;
|
|
606
|
+
console.log('✅ PerformanceUI disposed');
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Stop the update interval
|
|
611
|
+
*/
|
|
612
|
+
}, {
|
|
613
|
+
key: "stopUpdating",
|
|
614
|
+
value: function stopUpdating() {
|
|
615
|
+
if (this.updateInterval) {
|
|
616
|
+
clearInterval(this.updateInterval);
|
|
617
|
+
this.updateInterval = null;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Safely remove DOM element
|
|
623
|
+
*/
|
|
624
|
+
}, {
|
|
625
|
+
key: "removeDOMElement",
|
|
626
|
+
value: function removeDOMElement() {
|
|
627
|
+
if (this.element) {
|
|
628
|
+
try {
|
|
629
|
+
// Check if element is still in the DOM and container exists
|
|
630
|
+
if (this.element.parentNode && this.container && this.container.contains(this.element)) {
|
|
631
|
+
this.container.removeChild(this.element);
|
|
632
|
+
} else if (this.element.parentNode) {
|
|
633
|
+
// Element exists but container reference is stale, remove from current parent
|
|
634
|
+
this.element.parentNode.removeChild(this.element);
|
|
635
|
+
}
|
|
636
|
+
} catch (error) {
|
|
637
|
+
console.warn('⚠️ Error removing performance UI element:', error);
|
|
638
|
+
// Try alternative removal method
|
|
639
|
+
try {
|
|
640
|
+
if (this.element.remove) {
|
|
641
|
+
this.element.remove();
|
|
642
|
+
}
|
|
643
|
+
} catch (fallbackError) {
|
|
644
|
+
console.warn('⚠️ Fallback removal also failed:', fallbackError);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
this.element = null;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Toggle visibility of detailed stats
|
|
653
|
+
*/
|
|
654
|
+
}, {
|
|
655
|
+
key: "toggleDetails",
|
|
656
|
+
value: function toggleDetails() {
|
|
657
|
+
var details = this.element.querySelector('#perf-details');
|
|
658
|
+
var isHidden = details.style.display === 'none';
|
|
659
|
+
details.style.display = isHidden ? 'block' : 'none';
|
|
660
|
+
var toggleBtn = this.element.querySelector('#perf-toggle');
|
|
661
|
+
toggleBtn.textContent = isHidden ? '▼' : '▲';
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Start updating the UI
|
|
666
|
+
*/
|
|
667
|
+
}, {
|
|
668
|
+
key: "startUpdating",
|
|
669
|
+
value: function startUpdating() {
|
|
670
|
+
var _this3 = this;
|
|
671
|
+
this.updateInterval = setInterval(function () {
|
|
672
|
+
if (_this3.isVisible && _this3.element) {
|
|
673
|
+
_this3.updateContent();
|
|
674
|
+
}
|
|
675
|
+
}, 500); // Update every 500ms
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Update the UI content
|
|
680
|
+
*/
|
|
681
|
+
}, {
|
|
682
|
+
key: "updateContent",
|
|
683
|
+
value: function updateContent() {
|
|
684
|
+
var summary = this.monitor.getSummary();
|
|
685
|
+
|
|
686
|
+
// Update main stats
|
|
687
|
+
this.updateElement('#fps-value', summary.fps.current);
|
|
688
|
+
this.updateElement('#frametime-value', summary.frameTime.current);
|
|
689
|
+
this.updateElement('#memory-value', summary.memory.heapUsed);
|
|
690
|
+
this.updateElement('#drawcalls-value', summary.drawCalls.current);
|
|
691
|
+
|
|
692
|
+
// Update detailed stats
|
|
693
|
+
this.updateElement('#fps-avg', summary.fps.average);
|
|
694
|
+
this.updateElement('#fps-min', summary.fps.min);
|
|
695
|
+
this.updateElement('#fps-max', summary.fps.max);
|
|
696
|
+
this.updateElement('#geometries-value', summary.memory.geometries);
|
|
697
|
+
this.updateElement('#textures-value', summary.memory.textures);
|
|
698
|
+
this.updateElement('#triangles-value', summary.drawCalls.triangles);
|
|
699
|
+
this.updateElement('#objects-value', summary.scene.objects);
|
|
700
|
+
this.updateElement('#meshes-value', summary.scene.meshes);
|
|
701
|
+
|
|
702
|
+
// Update performance indicators
|
|
703
|
+
this.updatePerformanceIndicators(summary);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Update individual element
|
|
708
|
+
*/
|
|
709
|
+
}, {
|
|
710
|
+
key: "updateElement",
|
|
711
|
+
value: function updateElement(selector, value) {
|
|
712
|
+
var element = this.element.querySelector(selector);
|
|
713
|
+
if (element) {
|
|
714
|
+
element.textContent = value;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Update performance indicators (colors)
|
|
720
|
+
*/
|
|
721
|
+
}, {
|
|
722
|
+
key: "updatePerformanceIndicators",
|
|
723
|
+
value: function updatePerformanceIndicators(summary) {
|
|
724
|
+
var fpsElement = this.element.querySelector('#fps-value');
|
|
725
|
+
var frameTimeElement = this.element.querySelector('#frametime-value');
|
|
726
|
+
|
|
727
|
+
// FPS indicator
|
|
728
|
+
if (fpsElement) {
|
|
729
|
+
var fps = summary.fps.current;
|
|
730
|
+
fpsElement.className = this.getPerformanceClass('fps', fps);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// Frame time indicator
|
|
734
|
+
if (frameTimeElement) {
|
|
735
|
+
var frameTime = parseFloat(summary.frameTime.current);
|
|
736
|
+
frameTimeElement.className = this.getPerformanceClass('frameTime', frameTime);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Get CSS class based on performance thresholds
|
|
742
|
+
*/
|
|
743
|
+
}, {
|
|
744
|
+
key: "getPerformanceClass",
|
|
745
|
+
value: function getPerformanceClass(metric, value) {
|
|
746
|
+
var thresholds = this.monitor.thresholds[metric];
|
|
747
|
+
if (metric === 'fps') {
|
|
748
|
+
if (value >= thresholds.good) return 'perf-good';
|
|
749
|
+
if (value >= thresholds.warning) return 'perf-warning';
|
|
750
|
+
return 'perf-critical';
|
|
751
|
+
} else if (metric === 'frameTime') {
|
|
752
|
+
if (value <= thresholds.good) return 'perf-good';
|
|
753
|
+
if (value <= thresholds.warning) return 'perf-warning';
|
|
754
|
+
return 'perf-critical';
|
|
755
|
+
}
|
|
756
|
+
return '';
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Get HTML for the UI
|
|
760
|
+
*/
|
|
761
|
+
}, {
|
|
762
|
+
key: "getHTML",
|
|
763
|
+
value: function getHTML() {
|
|
764
|
+
return "\n <div class=\"perf-header\">\n <span class=\"perf-title\">Performance</span>\n <button id=\"perf-toggle\">\u25BC</button>\n </div>\n <div class=\"perf-main\">\n <div class=\"perf-stat\">\n <span class=\"perf-label\">FPS:</span>\n <span id=\"fps-value\" class=\"perf-value\">0</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Frame:</span>\n <span id=\"frametime-value\" class=\"perf-value\">0ms</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Memory:</span>\n <span id=\"memory-value\" class=\"perf-value\">0MB</span>\n </div>\n <div class=\"perf-stat\">\n <span class=\"perf-label\">Calls:</span>\n <span id=\"drawcalls-value\" class=\"perf-value\">0</span>\n </div>\n </div>\n <div id=\"perf-details\" class=\"perf-details\">\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">FPS Stats</div>\n <div class=\"perf-detail\">Avg: <span id=\"fps-avg\">0</span></div>\n <div class=\"perf-detail\">Min: <span id=\"fps-min\">0</span></div>\n <div class=\"perf-detail\">Max: <span id=\"fps-max\">0</span></div>\n </div>\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">Memory</div>\n <div class=\"perf-detail\">Geometries: <span id=\"geometries-value\">0</span></div>\n <div class=\"perf-detail\">Textures: <span id=\"textures-value\">0</span></div>\n </div>\n <div class=\"perf-section\">\n <div class=\"perf-section-title\">Rendering</div>\n <div class=\"perf-detail\">Triangles: <span id=\"triangles-value\">0</span></div>\n <div class=\"perf-detail\">Objects: <span id=\"objects-value\">0</span></div>\n <div class=\"perf-detail\">Meshes: <span id=\"meshes-value\">0</span></div>\n </div>\n </div>\n ";
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Add CSS styles for the UI
|
|
768
|
+
*/
|
|
769
|
+
}, {
|
|
770
|
+
key: "addStyles",
|
|
771
|
+
value: function addStyles() {
|
|
772
|
+
if (document.getElementById('performance-monitor-styles')) return;
|
|
773
|
+
var style = document.createElement('style');
|
|
774
|
+
style.id = 'performance-monitor-styles';
|
|
775
|
+
// Define theme-specific colors
|
|
776
|
+
var themes = {
|
|
777
|
+
dark: {
|
|
778
|
+
background: 'rgba(0, 0, 0, 0.8)',
|
|
779
|
+
color: 'white',
|
|
780
|
+
borderColor: 'rgba(255, 255, 255, 0.1)',
|
|
781
|
+
separatorColor: 'rgba(255, 255, 255, 0.2)',
|
|
782
|
+
sectionTitleColor: '#FFC107',
|
|
783
|
+
goodColor: '#4CAF50',
|
|
784
|
+
warningColor: '#FF9800',
|
|
785
|
+
criticalColor: '#F44336'
|
|
786
|
+
},
|
|
787
|
+
light: {
|
|
788
|
+
background: 'rgba(255, 255, 255, 0.95)',
|
|
789
|
+
color: '#333333',
|
|
790
|
+
borderColor: 'rgba(0, 0, 0, 0.15)',
|
|
791
|
+
separatorColor: 'rgba(0, 0, 0, 0.1)',
|
|
792
|
+
sectionTitleColor: '#1565C0',
|
|
793
|
+
goodColor: '#2E7D32',
|
|
794
|
+
warningColor: '#E65100',
|
|
795
|
+
criticalColor: '#C62828'
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
var currentTheme = themes[this.theme] || themes.dark;
|
|
799
|
+
style.textContent = " #performance-monitor-ui {\n position: fixed;\n bottom: 10px;\n right: 10px;\n background: ".concat(currentTheme.background, ";\n color: ").concat(currentTheme.color, ";\n font-family: 'Consolas', 'Monaco', 'Courier New', monospace;\n font-size: 12px;\n padding: 10px;\n border-radius: 5px;\n z-index: 10000;\n min-width: 150px;\n backdrop-filter: blur(5px);\n border: 1px solid ").concat(currentTheme.borderColor, ";\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n }\n\n .perf-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 8px;\n border-bottom: 1px solid ").concat(currentTheme.separatorColor, ";\n padding-bottom: 5px;\n }\n\n .perf-title {\n font-weight: bold;\n font-size: 14px;\n }\n\n #perf-toggle {\n background: none;\n border: none;\n color: ").concat(currentTheme.color, ";\n cursor: pointer;\n font-size: 12px;\n padding: 0;\n width: 20px;\n height: 20px;\n }\n\n .perf-main {\n display: grid;\n grid-template-columns: 1fr;\n gap: 4px;\n }\n\n .perf-stat {\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n\n .perf-label {\n opacity: 0.8;\n }\n\n .perf-value {\n font-weight: bold;\n text-align: right;\n min-width: 50px;\n } .perf-good {\n color: ").concat(currentTheme.goodColor, ";\n }\n\n .perf-warning {\n color: ").concat(currentTheme.warningColor, ";\n }\n\n .perf-critical {\n color: ").concat(currentTheme.criticalColor, ";\n }\n\n .perf-details {\n margin-top: 10px;\n padding-top: 8px;\n border-top: 1px solid ").concat(currentTheme.separatorColor, ";\n }\n\n .perf-section {\n margin-bottom: 8px;\n }\n\n .perf-section-title {\n font-weight: bold;\n font-size: 11px;\n margin-bottom: 3px;\n color: ").concat(currentTheme.sectionTitleColor, ";\n }\n\n .perf-detail {\n font-size: 10px;\n display: flex;\n justify-content: space-between;\n margin-bottom: 2px;\n opacity: 0.9;\n }\n ");
|
|
800
|
+
document.head.appendChild(style);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Change the theme of the performance UI
|
|
805
|
+
* @param {string} theme - 'light' or 'dark'
|
|
806
|
+
*/
|
|
807
|
+
}, {
|
|
808
|
+
key: "setTheme",
|
|
809
|
+
value: function setTheme(theme) {
|
|
810
|
+
if (theme !== 'light' && theme !== 'dark') {
|
|
811
|
+
console.warn('Invalid theme. Use "light" or "dark"');
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
this.theme = theme;
|
|
815
|
+
|
|
816
|
+
// Remove existing styles and reapply with new theme
|
|
817
|
+
var existingStyle = document.getElementById('performance-monitor-styles');
|
|
818
|
+
if (existingStyle) {
|
|
819
|
+
existingStyle.remove();
|
|
820
|
+
}
|
|
821
|
+
this.addStyles();
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Static method to clean up all performance monitor UI elements globally
|
|
826
|
+
* Useful for hot-reload cleanup
|
|
827
|
+
*/
|
|
828
|
+
}], [{
|
|
829
|
+
key: "cleanupAllInstances",
|
|
830
|
+
value: function cleanupAllInstances() {
|
|
831
|
+
console.log('🧹 PerformanceUI: Global cleanup of all instances...');
|
|
832
|
+
|
|
833
|
+
// Remove all performance monitor UI elements
|
|
834
|
+
var allElements = document.querySelectorAll('#performance-monitor-ui');
|
|
835
|
+
var cleanedCount = 0;
|
|
836
|
+
allElements.forEach(function (element) {
|
|
837
|
+
try {
|
|
838
|
+
if (element.parentNode) {
|
|
839
|
+
element.parentNode.removeChild(element);
|
|
840
|
+
cleanedCount++;
|
|
841
|
+
}
|
|
842
|
+
} catch (error) {
|
|
843
|
+
console.warn('⚠️ Error during global cleanup:', error);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
// Remove global styles if no elements remain
|
|
848
|
+
var remainingElements = document.querySelectorAll('#performance-monitor-ui');
|
|
849
|
+
if (remainingElements.length === 0) {
|
|
850
|
+
var existingStyle = document.getElementById('performance-monitor-styles');
|
|
851
|
+
if (existingStyle) {
|
|
852
|
+
existingStyle.remove();
|
|
853
|
+
console.log('🧹 Performance monitor global styles removed');
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
console.log("\u2705 PerformanceUI: Global cleanup completed - removed ".concat(cleanedCount, " elements"));
|
|
857
|
+
return cleanedCount;
|
|
858
|
+
}
|
|
859
|
+
}]);
|
|
860
|
+
}();
|
|
861
|
+
|
|
862
|
+
exports.PerformanceMonitor = PerformanceMonitor;
|
|
863
|
+
exports.PerformanceUI = PerformanceUI;
|