Skip to content

Initial work to display stage statistics directly in the viewport's HUD - #4720

Open
hsabri-SMS wants to merge 1 commit into
Autodesk:devfrom
hsabri-SMS:SMS/hsabri/hud_usd_stats_support
Open

Initial work to display stage statistics directly in the viewport's HUD#4720
hsabri-SMS wants to merge 1 commit into
Autodesk:devfrom
hsabri-SMS:SMS/hsabri/hud_usd_stats_support

Conversation

@hsabri-SMS

Copy link
Copy Markdown

Description

This is an initial commit to support displaying stage statistics directly in the viewport's HUD. The HUD currently displays USD stage statistics including total prims, total mesh prims, and mesh information such as vertex, triangle, face, and normal counts.

This is useful for quickly inspecting the the stage directly in the viewport without having to use additional tools or inspect the scene separately.

HUD display can be toggled on/off via following command.

mayaUsdToggleStageStatsHUD;   

The statistics work with both single and multiple stages and can also be displayed for selected prims.

Screenshots

image

@seando-adsk

Copy link
Copy Markdown
Collaborator

@hsabri-SMS We have discussed this internally and agree with the overall PR feature to add HUD support. Our designer would prefer to have just a "USD Details" menu item added to the existing "Display | Heads Up Display" rather than using a command to toggle on/off. @AramAzhari-adsk will work with you to provide a MEL script which can do this (very similar to how Maya itself adds the existing HUD items).

Sean

@scottrenaud

scottrenaud commented Sep 11, 2026

Copy link
Copy Markdown

Adding a mockup here where we can see "USD Details" in the HUD menu, to serve as an example
Screenshot 2026-09-11 at 12 50 57 PM

@AramAzhari-adsk

Copy link
Copy Markdown
Collaborator

@hsabri-SMS Sorry for the delayed response. As mentioned in the previous comments I think it would be best to hash out all the possible fields that may be useful in the HUD. Additionally, I think there is an easier approach to funnel most of this through Mel / Python scripts and only leave out the heavy computations to C++ (if any).

Here's a quick example mel script that:

  • Sets up the menus
  • Adds Prim count and vert count
// ============================================================
//  USD Prim + Vert Count HUD  -  paste into the MEL tab and run.
// ============================================================

global proc usdDefineCountFn()
{
    python(
        "def _usd_stages():\n" +
        "    stages = []\n" +
        "    try:\n" +
        "        import mayaUsd.ufe as _mufe\n" +
        "        stages = list(_mufe.getAllStages() or [])\n" +
        "    except Exception:\n" +
        "        stages = []\n" +
        "    if not stages:\n" +
        "        try:\n" +
        "            from pxr import UsdUtils\n" +
        "            stages = list(UsdUtils.StageCache.Get().GetAllStages())\n" +
        "        except Exception:\n" +
        "            stages = []\n" +
        "    return stages\n" +
        "\n" +
        "def _usd_prim_count():\n" +
        "    total = 0\n" +
        "    for s in _usd_stages():\n" +
        "        if s:\n" +
        "            total += sum(1 for _ in s.Traverse())\n" +
        "    return total\n" +
        "\n" +
        "# Tessellated vert counts for implicit gprims (what Hydra draws).\n" +
        "# Cube is exact (8). Sphere/Cylinder/Cone/Capsule are tessellation-\n" +
        "# dependent; add entries if your scenes use them.\n" +
        "_USD_IMPLICIT_VERTS = {'Cube': 8}\n" +
        "\n" +
        "def _usd_prim_verts(prim):\n" +
        "    a = prim.GetAttribute('points')\n" +
        "    if a and a.HasValue():\n" +
        "        v = a.Get()\n" +
        "        if v is not None:\n" +
        "            return len(v)\n" +
        "    return _USD_IMPLICIT_VERTS.get(prim.GetTypeName(), 0)\n" +
        "\n" +
        "def _usd_vert_count():\n" +
        "    from pxr import Usd\n" +
        "    total = 0\n" +
        "    for s in _usd_stages():\n" +
        "        if not s:\n" +
        "            continue\n" +
        "        cache = {}\n" +
        "        for proto in s.GetPrototypes():\n" +
        "            pv = 0\n" +
        "            for c in Usd.PrimRange(proto, Usd.TraverseInstanceProxies(Usd.PrimDefaultPredicate)):\n" +
        "                pv += _usd_prim_verts(c)\n" +
        "            cache[proto.GetPath()] = pv\n" +
        "        for prim in s.Traverse():\n" +
        "            if prim.IsInstance():\n" +
        "                proto = prim.GetPrototype()\n" +
        "                if proto:\n" +
        "                    total += cache.get(proto.GetPath(), 0)\n" +
        "            else:\n" +
        "                total += _usd_prim_verts(prim)\n" +
        "    return total\n"
    );
}

global proc int usdHudCount()
{
    usdDefineCountFn();
    int $n = python("_usd_prim_count()");
    return $n;
}

global proc int usdVertCount()
{
    usdDefineCountFn();
    int $n = python("_usd_vert_count()");
    return $n;
}

global proc setUsdHudVisibility(int $vis)
{
    if (`headsUpDisplay -ex HUDUsdDemo`)   headsUpDisplay -e -vis $vis HUDUsdDemo;
    if (`headsUpDisplay -ex HUDUsdVerts`)  headsUpDisplay -e -vis $vis HUDUsdVerts;
    if (`menuItem -ex usdDemoHudItem`)     menuItem -e -cb $vis usdDemoHudItem;
    optionVar -iv "usdDemoHudVisibility" $vis;
}

global proc usdDemoHudCreate()
{
    if (!`optionVar -ex "usdDemoHudVisibility"`) optionVar -iv "usdDemoHudVisibility" 1;
    usdDefineCountFn();

    if (!`headsUpDisplay -ex HUDUsdDemo`)
    {
        int $block = `headsUpDisplay -nfb 0`;
        headsUpDisplay -section 0 -block $block -blockSize "small"
                       -label "USD Prims:" -labelFontSize "small" -dataFontSize "small"
                       -labelWidth 70 -dataWidth 60 -dataAlignment "right"
                       -command "usdHudCount"
                       -event "SelectionChanged" -nodeChanges "attributeChange"
                       -vis `optionVar -q usdDemoHudVisibility`
                       HUDUsdDemo;
    }

    if (!`headsUpDisplay -ex HUDUsdVerts`)
    {
        int $block = `headsUpDisplay -nfb 0`;
        headsUpDisplay -section 0 -block $block -blockSize "small"
                       -label "USD Verts:" -labelFontSize "small" -dataFontSize "small"
                       -labelWidth 70 -dataWidth 60 -dataAlignment "right"
                       -command "usdVertCount"
                       -event "SelectionChanged" -nodeChanges "attributeChange"
                       -vis `optionVar -q usdDemoHudVisibility`
                       HUDUsdVerts;
    }

    if (!`runTimeCommand -ex ToggleUsdDemoHud`)
        runTimeCommand -default false -annotation "Toggle the USD prim/vert count HUD"
            -command ("setUsdHudVisibility(!`optionVar -q usdDemoHudVisibility`);")
            ToggleUsdDemoHud;

    global string $gHeadsUpDisplayMenu;
    if (`menuItem -ex $gHeadsUpDisplayMenu`)
    {
        setParent -m $gHeadsUpDisplayMenu;
        if (!`menuItem -ex usdDemoHudItem`)
            menuItem -checkBox `optionVar -q usdDemoHudVisibility`
                -label "USD Details" -annotation "Show/hide the USD prim & vert HUD"
                -command "ToggleUsdDemoHud" -insertAfter "frameRateItem"
                usdDemoHudItem;
    }
}

global proc usdDemoHudDelete()
{
    if (`menuItem -ex usdDemoHudItem`)         deleteUI -menuItem usdDemoHudItem;
    if (`headsUpDisplay -ex HUDUsdDemo`)        headsUpDisplay -rem HUDUsdDemo;
    if (`headsUpDisplay -ex HUDUsdVerts`)       headsUpDisplay -rem HUDUsdVerts;
    if (`runTimeCommand -ex ToggleUsdDemoHud`)  runTimeCommand -e -delete ToggleUsdDemoHud;
}

usdDemoHudDelete();
usdDemoHudCreate();
headsUpDisplay -r HUDUsdDemo;
headsUpDisplay -r HUDUsdVerts;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants