Skip to content

Commit

Permalink
Added examples with scoped_config. Fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jul 25, 2024
1 parent 3c5ba6a commit a18034c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
31 changes: 31 additions & 0 deletions addons/debug_draw_3d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ func _process(delta: float) -> void:

![screenshot_1](/images/screenshot_1.png)

An example of using scoped configs:

```gdscript
@tool
extends Node3D
func _ready():
# Set the base scoped_config.
# Each frame will be reset to these scoped values.
DebugDraw3D.scoped_config().set_thickness(0.1).set_center_brightness(0.6)
func _process(delta):
# Draw using the base scoped config.
DebugDraw3D.draw_box(Vector3.ZERO, Quaternion.IDENTITY, Vector3.ONE * 2, Color.CORNFLOWER_BLUE)
if true:
# Create a scoped config that will exist until exiting this if.
var _s = DebugDraw3D.new_scoped_config().set_thickness(0).set_center_brightness(0.1)
# Draw with a thickness of 0
DebugDraw3D.draw_box(Vector3.ZERO, Quaternion.IDENTITY, Vector3.ONE, Color.RED)
# If necessary, the values inside this scope can be changed
# even before each call to draw_*.
_s.set_thickness(0.05)
DebugDraw3D.draw_box(Vector3(1,0,1), Quaternion.IDENTITY, Vector3.ONE * 1, Color.BLUE_VIOLET)
```

![screenshot_5](/images/screenshot_5.png)

> [!TIP]
>
> If you want to use a non-standard Viewport for rendering a 3d scene, then do not forget to specify it in the scoped config!
## API

This project has a separate [documentation](https://dd3d.dmitriysalnikov.ru/docs/) page.
Expand Down
37 changes: 37 additions & 0 deletions docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ func _process(delta: float) -> void:
DebugDraw2D.set_text("delta", delta)
```

An example of using scoped configs:

```python
@tool
extends Node3D

func _ready():
# Set the base scoped_config.
# Each frame will be reset to these scoped values.
DebugDraw3D.scoped_config().set_thickness(0.1).set_center_brightness(0.6)

func _process(delta):
# Draw using the base scoped config.
DebugDraw3D.draw_box(Vector3.ZERO, Quaternion.IDENTITY, Vector3.ONE * 2, Color.CORNFLOWER_BLUE)
if true:
# Create a scoped config that will exist until exiting this if.
var _s = DebugDraw3D.new_scoped_config().set_thickness(0).set_center_brightness(0.1)
# Draw with a thickness of 0
DebugDraw3D.draw_box(Vector3.ZERO, Quaternion.IDENTITY, Vector3.ONE, Color.RED)
# If necessary, the values inside this scope can be changed
# even before each call to draw_*.
_s.set_thickness(0.05)
DebugDraw3D.draw_box(Vector3(1,0,1), Quaternion.IDENTITY, Vector3.ONE * 1, Color.BLUE_VIOLET)
```

@note
If you want to use a non-standard Viewport for rendering a 3d scene, then do not forget to specify it in the scoped config!

## CSharp

When you start the engine for the first time, bindings for `C#` will be generated automatically. If this does not happen, you can manually generate them through the `Project - Tools - Debug Draw` menu.
Expand All @@ -42,6 +70,15 @@ public override void _Process(float delta)
}
```

Scoped config's work similarly to the GDScript version, but require a manual `Dispose` or using `using`:

```csharp
using (var _w1 = DebugDraw3D.NewScopedConfig().SetViewport(someViewportHere).SetThickness(0.01f).SetNoDepthTest(true))
{
// ...
}
```

@warning
C# bindings work using ClassDB, which greatly decreases its performance and it can run slower than GDScript. There is currently no way to fix this.

Expand Down
Binary file added images/screenshot_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a18034c

Please sign in to comment.