Customizable Utility Layer for Physics Viewer

Hi. I have a setup where I use a separate camera for Babylon GUI along with a normal ArcCamera. When I enable the physics viewer from the inspector, it doesn’t display because the viewer creates a new utility layer and assigns the GUI camera by default, which isn’t suitable for rendering 3D objects. You can see the relevant code here:

I could create my own physics viewer, but since the utility layer is set to private, there’s no official way to set a custom renderCamera or utility layer without resorting to hacks like:

// @ts-ignore
this.physicsViewer._utilityLayer.setRenderCamera(this.arcCamera);
// alternative hack, same result
// this.physicsViewer._utilityLayer = UtilityLayerRenderer.DefaultUtilityLayer;

I would like to propose the following solutions:

  1. Provide a public method in the physics viewer to set a custom utility layer or renderCamera.
  2. Modify the physics viewer to use UtilityLayerRenderer.DefaultUtilityLayer or UtilityLayerRenderer.DefaultKeepDepthUtilityLayer so that the renderCamera can be set externally.

Thank you for considering this request.

1 Like

Change should not be too complicated to do. Let me see if I can do something :slight_smile:

1 Like
1 Like

Perfect! I just tested the fix and the issue is completely resolved now, thank you!

1 Like