Skip to content

Commit

Permalink
Merge pull request #105 from VaclavElias/main
Browse files Browse the repository at this point in the history
fix: Docs improvements and link references fixes
  • Loading branch information
VaclavElias authored Feb 10, 2024
2 parents a13e00f + 2be5a9f commit 7717303
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 126 deletions.
8 changes: 6 additions & 2 deletions docs/manual/code-only/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ Some extensions return `Entity` so it can be further modified.

- [`Run()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Run(Stride.Engine.Game,Stride.Games.GameContext,System.Action{Stride.Engine.Scene},System.Action{Stride.Engine.Scene,Stride.Games.GameTime})) - Initialising the game, use `start` and `update` params
- [`SetupBase()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.SetupBase(Stride.Engine.Game)) - Adds graphics compositor, camera and directional light
- [`SetupBase2DScene()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.SetupBase2DScene(Stride.Engine.Game)) - Same as `SetupBase()` plus skybox, ground, mouse look camera
- [`SetupBase3DScene()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.SetupBase3DScene(Stride.Engine.Game)) - Same as `SetupBase()` plus skybox, ground, mouse look camera
- [`AddGraphicsCompositor()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddGraphicsCompositor(Stride.Engine.Game)) - Adds a default `GraphicsCompositor`
- [`AddCamera()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddCamera(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector3},System.Nullable{Stride.Core.Mathematics.Vector3})) - Adds camera
- [`Add2DCamera()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Add2DCamera(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector3},System.Nullable{Stride.Core.Mathematics.Vector3})) - Adds 2D camera
- [`Add3DCamera()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Add3DCamera(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector3},System.Nullable{Stride.Core.Mathematics.Vector3},Stride.Engine.Processors.CameraProjectionMode)) - Adds 3D camera
- [`AddDirectionalLight()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddDirectionalLight(Stride.Engine.Game,System.String)) - Adds directional light
- [`AddSkybox()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddSkybox(Stride.Engine.Game,System.String)) - Adds skybox
- [`AddGround()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddGround(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector2},System.Boolean)) - Adds ground
- [`Add2DGround()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Add2DGround(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector2})) - Adds 2D ground
- [`Add3DGround()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Add3DGround(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector2},System.Boolean)) - Adds 3D ground
- [`AddInfinite3DGround()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddInfinite3DGround(Stride.Engine.Game,System.String,System.Nullable{Stride.Core.Mathematics.Vector2},System.Boolean)) - Adds infinite 3D ground

## GraphicsCompositorExtensions.cs

Expand Down
4 changes: 3 additions & 1 deletion docs/manual/entity-extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

Here is an overview of the available extension methods:

- [`Add2DCameraController()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.Add2DCameraController(Stride.Engine.Entity)) - Adds an interactive 2D camera script to the specified entity, enabling camera movement and rotation
- [`Add3DCameraController()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.Add3DCameraController(Stride.Engine.Entity)) - Adds an interactive 3D camera script to the specified entity, enabling camera movement and rotation
- [`AddGizmo()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.AddGizmo(Stride.Engine.Entity,Stride.Graphics.GraphicsDevice,System.Nullable{Stride.Core.Mathematics.Color},System.Nullable{Stride.Core.Mathematics.Color},System.Nullable{Stride.Core.Mathematics.Color},System.Boolean,System.Boolean)) - Adds a TranslationGizmo to the specified entity with optional custom colors
- [`AddInteractiveCameraScript()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.AddInteractiveCameraScript(Stride.Engine.Entity)) - Adds an interactive camera script to the specified entity, enabling camera movement and rotation
- [`GetComponent<T>()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.GetComponent``1(Stride.Engine.Entity)) - Retrieves the first component of the specified type from the entity
- [`GetComponents<T>()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.GetComponents``1(Stride.Engine.Entity)) - Retrieves all components of the specified type from the entity
- [`Remove()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.Remove(Stride.Engine.Entity)) - Removes the entity from its current scene by setting its `Scene` property to null
- [`TryGetComponent<T>()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.TryGetComponent``1(Stride.Engine.Entity,``0@)) - Tries to retrieve a component of type T from the given entity
- [`WorldPosition()`](xref:Stride.CommunityToolkit.Engine.EntityExtensions.WorldPosition(Stride.Engine.Entity,System.Boolean)) - An easier way to get world position

These extensions are designed to streamline common tasks associated with entities in Stride, enhancing the overall efficiency and flexibility of game development workflows.
6 changes: 4 additions & 2 deletions docs/manual/game-extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

Here's a brief overview of the functionalities provided by these extension methods:

- [`AddAllDirectionLighting()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddAllDirectionLighting(Stride.Engine.Game,System.Single,System.Boolean)) - Adds directional lighting from multiple angles to the current scene
- [`AddProfiler()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.AddProfiler(Stride.Engine.Game,System.String)) - Adds a profiler to the game, which can be toggled on/off with Left Shift + Left Ctrl + P
- [`CreateMaterial()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.CreateMaterial(Stride.Engine.Game,System.Nullable{Stride.Core.Mathematics.Color},System.Single,System.Single)) - Creates a basic material with optional color, specular reflection, and microsurface smoothness values
- [`CreatePrimitive()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.CreatePrimitive(Stride.Engine.Game,Stride.CommunityToolkit.ProceduralModels.PrimitiveModelType,System.String,Stride.Rendering.Material,System.Boolean,System.Nullable{Stride.Core.Mathematics.Vector3},Stride.Rendering.RenderGroup)) - Creates a primitive 3D model entity of the specified type with optional customizations
- [`CreateMaterial()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.CreateMaterial(Stride.Games.IGame,System.Nullable{Stride.Core.Mathematics.Color},System.Single,System.Single)) - Creates a basic material with optional color, specular reflection, and micro-surface smoothness values
- [`Create2DPrimitive()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.Create2DPrimitive(Stride.Games.IGame)) - Creates a primitive 3D model entity of the specified type with optional customizations
- [`CreatePrimitive()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.CreatePrimitive(Stride.Games.IGame,Stride.CommunityToolkit.ProceduralModels.PrimitiveModelType,Stride.CommunityToolkit.Engine.PrimitiveCreationOptions)) - Creates a primitive 3D model entity of the specified type with optional customizations
- [`DeltaTime()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.DeltaTime(Stride.Games.IGame)) - Gets the time elapsed since the last game update in seconds as a single-precision floating-point number
- [`DeltaTimeAccurate()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.DeltaTimeAccurate(Stride.Games.IGame)) - Gets the time elapsed since the last game update in seconds as a double-precision floating-point
- [`FPS()`](xref:Stride.CommunityToolkit.Engine.GameExtensions.FPS(Stride.Engine.Game)) - Retrieves the current frames per second (FPS) rate of the running game
Expand Down
8 changes: 4 additions & 4 deletions src/Stride.CommunityToolkit/Engine/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public static void Remove(this Entity entity)
}

/// <summary>
/// Searching for an entity in all scene entities.
/// Searches for an entity by name within the top-level entities of the current scene.
/// </summary>
/// <param name="entity"></param>
/// <param name="name"></param>
/// <returns></returns>
/// <param name="entity">The reference entity used to access the scene.</param>
/// <param name="name">The name of the entity to find.</param>
/// <returns>The first entity matching the specified name, or null if no match is found. This search does not include child entities.</returns>
public static Entity? FindEntity(this Entity entity, string name)
{
return entity.Scene.Entities.FirstOrDefault(w => w.Name == name);
Expand Down
86 changes: 10 additions & 76 deletions src/Stride.CommunityToolkit/Engine/GameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
using Stride.CommunityToolkit.Skyboxes;
using Stride.Engine;
using Stride.Engine.Processors;
using Stride.Extensions;
using Stride.Games;
using Stride.Graphics;
using Stride.Graphics.GeometricPrimitives;
using Stride.Physics;
using Stride.Rendering;
using Stride.Rendering.Colors;
Expand All @@ -17,7 +15,6 @@
using Stride.Rendering.Materials.ComputeColors;
using Stride.Rendering.ProceduralModels;
using Stride.Rendering.Skyboxes;
using System.Reflection;

namespace Stride.CommunityToolkit.Engine;

Expand Down Expand Up @@ -267,6 +264,16 @@ public static Entity AddDirectionalLight(this Game game, string? entityName = nu
return entity;
}

/// <summary>
/// Adds directional lighting from multiple angles to the current scene, enhancing scene illumination.
/// </summary>
/// <param name="game">The game instance to which the lighting will be added.</param>
/// <param name="intensity">The intensity of the light sources.</param>
/// <param name="showLightGizmo">Specifies whether to display a gizmo for the light in the editor. Default is true.</param>
/// <remarks>
/// This method creates six directional lights positioned around a central point, each aiming from a unique angle to simulate uniform lighting from all directions.
/// The lights are added at predefined positions and rotations to cover the scene evenly.
/// </remarks>
public static void AddAllDirectionLighting(this Game game, float intensity, bool showLightGizmo = true)
{
var position = new Vector3(7f, 2f, 0);
Expand Down Expand Up @@ -612,77 +619,4 @@ private static PrimitiveProceduralModelBase GetProceduralModel(PrimitiveModelTyp
/// <param name="game">The game instance from which to obtain the FPS rate.</param>
/// <returns>The current FPS rate of the game.</returns>
public static float FPS(this Game game) => game.UpdateTime.FramePerSecond;
}

/// <summary>
/// Temporary workaround for BoxColliderShape not working with 2D
/// </summary>
public class BoxColliderShapeX4 : ColliderShape
{
public readonly Vector3 BoxSize;

/// <summary>
/// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
/// </summary>
/// <param name="is2D">If this cube is a 2D quad</param>
/// <param name="size">The size of the cube</param>
public BoxColliderShapeX4(bool is2D, Vector3 size)
{
Type = ColliderShapeTypes.Box;
BoxSize = size;

// Use reflection to set internal properties
SetInternalProperties(is2D, size);

cachedScaling = Is2D ? new Vector3(1, 1, 0.001f) : Vector3.One;

//if (is2D) size.Z = 0.001f;

//if (Is2D)
//{
// InternalShape = new BulletSharp.Convex2DShape(new BulletSharp.Box2DShape(size / 2)) { LocalScaling = cachedScaling };
//}
//else
//{
// InternalShape = new BulletSharp.BoxShape(size / 2) { LocalScaling = cachedScaling };
//}

//DebugPrimitiveMatrix = Matrix.Scaling(size * DebugScaling);
}

private void SetInternalProperties(bool is2D, Vector3 size)
{
// Set the Is2D property using reflection
//var is2DProperty = typeof(ColliderShape).GetProperty("Is2D", BindingFlags.NonPublic | BindingFlags.Instance);
var is2DProperty = typeof(ColliderShape).GetProperty("Is2D");

if (is2DProperty != null)
{
is2DProperty.SetValue(this, is2D);
}

// Set the InternalShape property using reflection
var internalShapeField = typeof(ColliderShape).GetField("InternalShape", BindingFlags.NonPublic | BindingFlags.Instance);
if (internalShapeField != null)
{
BulletSharp.CollisionShape internalShape;

if (is2D)
{
size.Z = 0.001f; // Adjust the Z size for 2D
internalShape = new BulletSharp.Convex2DShape(new BulletSharp.Box2DShape(size / 2) { LocalScaling = Vector3.One }) { LocalScaling = cachedScaling };
}
else
{
internalShape = new BulletSharp.BoxShape(size / 2) { LocalScaling = cachedScaling };
}

internalShapeField.SetValue(this, internalShape);
}
}

public override MeshDraw CreateDebugPrimitive(GraphicsDevice device)
{
return GeometricPrimitive.Cube.New(device).ToMeshDraw();
}
}
Loading

0 comments on commit 7717303

Please sign in to comment.