diff --git a/examples/src/examples/gaussian-splatting/flipbook.example.mjs b/examples/src/examples/gaussian-splatting/flipbook.example.mjs index a89920c7cc6..2cdb4e3fd9f 100644 --- a/examples/src/examples/gaussian-splatting/flipbook.example.mjs +++ b/examples/src/examples/gaussian-splatting/flipbook.example.mjs @@ -76,9 +76,7 @@ assetListLoader.load(() => { roomEntity.setLocalScale(30, 30, 30); app.root.addChild(roomEntity); - // Mini-Stats with default options - const msOptions = pc.MiniStats.getDefaultOptions(); - const miniStats = new pc.MiniStats(app, msOptions); // eslint-disable-line no-unused-vars + const miniStats = new pc.MiniStats(app, pc.MiniStats.getDefaultOptions(['gsplats'])); // eslint-disable-line no-unused-vars // Create an Entity with a camera component const camera = new pc.Entity(); diff --git a/examples/src/examples/gaussian-splatting/lod-streaming.example.mjs b/examples/src/examples/gaussian-splatting/lod-streaming.example.mjs index a95985d21ef..83c9ad81333 100644 --- a/examples/src/examples/gaussian-splatting/lod-streaming.example.mjs +++ b/examples/src/examples/gaussian-splatting/lod-streaming.example.mjs @@ -119,25 +119,7 @@ assetListLoader.load(() => { app.scene.skyboxMip = 1; app.scene.exposure = 1.5; - // Mini-Stats: insert gsplat stats after the default 'Frame' entry - const msOptions = pc.MiniStats.getDefaultOptions(); - const frameIndex = msOptions.stats.findIndex(s => s.name === 'Frame'); - msOptions.stats.splice(frameIndex + 1, 0, { - name: 'GSplats', - stats: ['frame.gsplats'], - decimalPlaces: 3, - multiplier: 1 / 1000000, - unitsName: 'M', - watermark: 10 - }, { - name: 'GsplatsCopy', - stats: ['frame.gsplatBufferCopy'], - decimalPlaces: 1, - multiplier: 1, - unitsName: '%', - watermark: 100 - }); - const miniStats = new pc.MiniStats(app, msOptions); // eslint-disable-line no-unused-vars + const miniStats = new pc.MiniStats(app, pc.MiniStats.getDefaultOptions(['gsplats', 'gsplatsCopy'])); // eslint-disable-line no-unused-vars // enable rotation-based LOD updates and behind-camera penalty app.scene.gsplat.lodUpdateAngle = 90; diff --git a/src/extras/mini-stats/mini-stats.js b/src/extras/mini-stats/mini-stats.js index 41fb77f3daa..5c6e1b67086 100644 --- a/src/extras/mini-stats/mini-stats.js +++ b/src/extras/mini-stats/mini-stats.js @@ -211,6 +211,23 @@ class MiniStats { this.div.remove(); } + /** + * Predefined stat groups that can be included via {@link MiniStats.getDefaultOptions}. Each + * key maps to an array of {@link MiniStatsGraphOptions} entries that are inserted after the + * 'Frame' stat in the default options. + * + * @type {Object} + * @ignore + */ + static statPresets = { + gsplats: [ + { name: 'GSplats', stats: ['frame.gsplats'], decimalPlaces: 3, multiplier: 1 / 1000000, unitsName: 'M', watermark: 10 } + ], + gsplatsCopy: [ + { name: 'GsplatsCopy', stats: ['frame.gsplatBufferCopy'], decimalPlaces: 1, multiplier: 1, unitsName: '%', watermark: 100 } + ] + }; + /** * Returns the default options for MiniStats. The default options configure the overlay to * show the following graphs: @@ -221,12 +238,19 @@ class MiniStats { * - Draw call count * - Total VRAM usage * + * @param {string[]} [extraStats] - Optional array of preset names from + * {@link MiniStats.statPresets} to include. The preset stats are inserted after the 'Frame' + * entry. Can be: 'gsplats', 'gsplatsCopy'. * @returns {object} The default options for MiniStats. * @example + * // default options without extra stats * const options = pc.MiniStats.getDefaultOptions(); + * @example + * // include gsplat stats + * const options = pc.MiniStats.getDefaultOptions(['gsplats', 'gsplatsCopy']); */ - static getDefaultOptions() { - return { + static getDefaultOptions(extraStats = []) { + const options = { // sizes of area to render individual graphs in and spacing between individual graphs sizes: [ @@ -299,6 +323,16 @@ class MiniStats { // minimum size index to show VRAM subcategory graphs vramTimingMinSize: 1 }; + + if (extraStats.length > 0) { + const frameIndex = options.stats.findIndex(s => s.name === 'Frame'); + const insertIndex = frameIndex !== -1 ? frameIndex + 1 : options.stats.length; + // reverse so user-specified order matches visual top-to-bottom order + const extra = extraStats.flatMap(name => MiniStats.statPresets[name] ?? []).reverse(); + options.stats.splice(insertIndex, 0, ...extra); + } + + return options; } /**