Skip to content

Viewer NRG Support#18495

Open
MiiBond wants to merge 6 commits into
BabylonJS:masterfrom
MiiBond:mbond/viewer-nrg-support
Open

Viewer NRG Support#18495
MiiBond wants to merge 6 commits into
BabylonJS:masterfrom
MiiBond:mbond/viewer-nrg-support

Conversation

@MiiBond
Copy link
Copy Markdown
Contributor

@MiiBond MiiBond commented May 22, 2026

This is a Draft PR. I'm looking for feedback before continuing.

I want to be able to load a custom NRG in the viewer. To do this, I've made some changes to viewer.ts:

  • Two new protected methods, _setActiveFrameGraph and _bindObjectList, give derived classes the hooks they need to activate a custom FrameGraph and keep its mesh lists in sync with the scene as models load and unload. An SSAO guard ensures the standard SSAO pipeline isn't created when a frame graph is active, since the two rendering paths are incompatible.
  • The viewer's internal onAfterRenderObservable was previously wired to scene.onAfterRenderCameraObservable, which is part of the per-camera render loop. That loop is bypassed when a frame graph is active. Switching to scene.onAfterRenderObservable (which fires at the end of every scene.render() regardless of rendering path) ensures that viewerrender events — and therefore hotspot annotation position updates — continue to fire correctly in all rendering modes.
  • hotspots are now fully cleared when a new model loads, preventing stale annotations from a previous model from persisting
  • _shouldRender now stays true for the duration of any in-flight model load, preventing the snapshot helper from capturing a background-only frame before the new model has been added to the scene.

I also made some changes to TransmissionHelper.ts to support unbinding things when needed. In my test viewer, I was loading a frame graph after already potentially loading a scene with transmission and needed these fixes.

// 5. The environment shadows are not yet in a ready state.
// 6. The SSAO pipeline is not yet in a ready state.
// 7. At least one model should render (playing animations).
// 8. A model (or other asset) load is in flight.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition 8 prevents a subtle snapshot timing bug: when the camera stops moving while a model is still loading, scene.isReady() returns true (the model is not yet in the scene, so there are no pending effects to check). The "render ready frame" logic would then fire onRenderingSuspended() before addAllToScene() has been called, and the resulting snapshot would capture only the background. Keeping _shouldRender true for the duration of any in-flight load ensures that effects are compiled (via rendered frames) before the snapshot helper is allowed to record a new snapshot.

@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented May 22, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

Snapshot stored with reference name:
refs/pull/18495/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18495/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18495/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18495/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18495/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18495/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18495/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18495/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

🟢 Memory Leak Test Results

13 passed, 0 leaked out of 13 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (13)
Scenario Package
Core Feature Stack @babylonjs/core
Core Rendering Materials Shadows Stack @babylonjs/core
Core Textures Render Targets PostProcess Stack @babylonjs/core
GUI Fullscreen UI Controls @babylonjs/gui
GUI Mesh ADT Controls @babylonjs/gui
Loaders Boombox Import @babylonjs/loaders
Loaders OBJ Direct Load @babylonjs/loaders
Loaders STL Direct Load @babylonjs/loaders
Materials Library Stack @babylonjs/materials
Serializers glTF Export @babylonjs/serializers
Serializers GLB Export @babylonjs/serializers
PostProcesses Digital Rain Stack @babylonjs/post-processes
Procedural Textures Stack @babylonjs/procedural-textures

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented May 22, 2026

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.

3 participants