How to display 3D object in 2D UI (with SubViewport node)

You might want one day to render 3D objects for some reason in the UI.

Just like this:

The setup looks like this:

image(Canvas Layer wtih default values; the root for the 2D UI)

The idea is to make a CanvasLayer, then subnode the SubViewportContainer

Then subnode SubViewport under SubViewportContainer

Then you make a Node3D and place a MeshInstance3D, StaticBody3D or anything else you want.

Then you add Camera3D under SubViewport/Node3D.

Then you setup the SubViewport Node as follows:

Core notes

Camera3D Node: all default parameters

SubViewportContainer Node: all default parameters

SubViewport Node:

  1. Enable Own World 3D: Enable Own World 3D to isolate the Camera3D so it does exist in its own world.
  2. Transparent BG: Enable to make background skybox not existing and background transparent for the UI underneath.

“Own World 3D” option: Needs a copy of environment subnoded.

For own world to not show just dimmed black stuff, you will need to subnode a copy of WorldEnvironment and DirectionalLight3D like this:

That’s it. Now you can have your 3D mesh/object displayed on 2D UI.

1 Like