DmitriySalnikov / godot_debug_draw_3d

Draw 3D debug graphics and 2D overlays with this add-on.

Home Page:https://dd3d.dmitriysalnikov.ru/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Doesn't render 3D debugdraws in subviewports without a main viewport camera

N-e-m opened this issue · comments

commented

Godot version

4.2.2.stable

DebugDraw3D version

4.1.3+

On which operating systems the error occurs

Windows

Using which renderers the error occurs

No response

Issue description

It seems like your frustum culling relies on an active camera in the main viewport of a scene. I'd like to be able to assign a different camera for instances when I'm using subviewports. Or even better, automatically detect the relevant camera based on the node calling the draw functions parent viewport.

Steps to reproduce

N/A

Minimal reproduction project

N/A

DebugDraw3D version

4.1.3+

This is not the DD3D version, this is the minimum version of Godot that it supports.

It seems like your frustum culling relies on an active camera in the main viewport of a scene. I'd like to be able to assign a different camera for instances when I'm using subviewports.

In fact, frustum culling depends on the current viewport in scoped_config.

Try to change the current/scoped viewport of DD3D https://dd3d.dmitriysalnikov.ru/docs/1.4.2/classDebugDraw3DScopeConfig.html#aa5cc8163e120284dc83f2b8e46534277
DebugDraw3DScopeConfig has a usage example in the description.

Or even better, automatically detect the relevant camera based on the node calling the draw functions parent viewport.

Is it possible to get a calling node in godot?

@N-e-m Did the message above help you?

I've tried doing this and it worked for me.
For reference I have this setup

image

And then I have this code

def _physics_process(delta):
	var _s = DebugDraw3D.new_scoped_config().set_viewport(Globals.v.main_viewport.viewport)
	for point in points:	
		DebugDraw3D.draw_sphere(point, 2.5)

Before doing this, it was not drawing.
Also, as per the documentation, you need to use the var _s =, otherwise it won't work.

For reference I have this setup

Also, if your Viewport is global, then you can replace new_scoped_config().set_viewport in _process with:

func _ready():
    DebugDraw3D.scoped_config().set_viewport(Globals.v.main_viewport.viewport)

in the script where the Viewport is created. scoped_config() allows you to set default values (which are set at the beginning of each frame).

It's probably worth adding explicit examples of working with scoped_config() to the Readme and documentation... (although examples_dd3d already has these examples)