Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 36 additions & 2 deletions src/extras/mini-stats/mini-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, MiniStatsGraphOptions[]>}
* @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:
Expand All @@ -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: [
Expand Down Expand Up @@ -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;
}

/**
Expand Down