Skip to content

Commit

Permalink
Merge pull request #119 from Doprez/simplify-debug-shapes
Browse files Browse the repository at this point in the history
Simplify Debug Shapes
  • Loading branch information
VaclavElias authored Mar 11, 2024
2 parents f9c0c08 + 57762fe commit fca4e91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/code-only/Example08_DebugShapes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ void Start(Scene rootScene)

void SetupBaseScene()
{
game.AddGraphicsCompositor()
.AddImmediateDebugRenderFeature();
game.AddGraphicsCompositor();
game.Add3DCamera().Add3DCameraController();
game.AddDirectionalLight();
game.AddSkybox();
game.Add3DGround();
game.AddDebugShapes();
}

void AddDebugComponent(Scene scene)
Expand Down
20 changes: 4 additions & 16 deletions examples/code-only/Example08_DebugShapes/Scripts/ShapeUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,18 @@ public override void Start()
{
CurrentCamera = SceneSystem.SceneInstance.RootScene.Entities.First(e => e.Get<CameraComponent>() != null).Get<CameraComponent>();

RenderStage FindRenderStage(RenderSystem renderSystem, string name)
{
for (int i = 0; i < renderSystem.RenderStages.Count; ++i)
{
var stage = renderSystem.RenderStages[i];
if (stage.Name == name)
{
return stage;
}
}

return null;
}
// Gets added in the program.cs class by the AddDebugShapes() extension.
DebugDraw = Services.GetService<ImmediateDebugRenderSystem>();

DebugDraw = new ImmediateDebugRenderSystem(Services, RenderGroup.Group1);
DebugDraw.PrimitiveColor = Color.Green;
DebugDraw.MaxPrimitives = (currentNumPrimitives * 2) + 8;
DebugDraw.MaxPrimitivesWithLifetime = (currentNumPrimitives * 2) + 8;

// keep DebugDraw visible in release builds too
DebugDraw.Visible = true;

// keep DebugText visible in release builds too
DebugText.Visible = true;
Services.AddService(DebugDraw);
Game.GameSystems.Add(DebugDraw);

InitializePrimitives(0, currentNumPrimitives);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Stride.CommunityToolkit/Engine/GameExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DebugShapes;
using Stride.BepuPhysics;
using Stride.BepuPhysics.Definitions.Colliders;
using Stride.CommunityToolkit.Rendering.Compositing;
Expand Down Expand Up @@ -707,6 +708,24 @@ public static Entity Create2DPrimitiveWithBepu(this IGame game, Primitive2DModel
return entity;
}

/// <summary>
/// <para>Adds <see cref="ImmediateDebugRenderFeature"/> and <see cref="ImmediateDebugRenderSystem"/> to the game.</para>
/// <para>Registers the system to the service registry for easy access.</para>
/// </summary>
/// <param name="game"></param>
/// <param name="debugShapeRenderFroup"></param>
public static void AddDebugShapes(this Game game, RenderGroup debugShapeRenderFroup = RenderGroup.Group1)
{
game.SceneSystem.GraphicsCompositor.AddImmediateDebugRenderFeature();

var debugDraw = new ImmediateDebugRenderSystem(game.Services, debugShapeRenderFroup);
#if DEBUG
debugDraw.Visible = true;
#endif
game.Services.AddService(debugDraw);
game.GameSystems.Add(debugDraw);
}

public static Entity Create3DPrimitiveWithBepu(this IGame game, PrimitiveModelType type, Primitive3DCreationOptionsWithBepu? options = null)
{
options ??= new();
Expand Down

0 comments on commit fca4e91

Please sign in to comment.