diff --git a/src/Stride.CommunityToolkit/Engine/GameExtensions.cs b/src/Stride.CommunityToolkit/Engine/GameExtensions.cs index f2ef03ac..00fbaf70 100644 --- a/src/Stride.CommunityToolkit/Engine/GameExtensions.cs +++ b/src/Stride.CommunityToolkit/Engine/GameExtensions.cs @@ -620,7 +620,7 @@ public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type, if (!options.IncludeCollider || options.PhysicsComponent is null) return entity; - var colliderShape = Get3DColliderShape(type, options.Size, options.Is2D); + var colliderShape = Get3DColliderShape(type, options.Size); if (colliderShape is null) return entity; @@ -829,21 +829,22 @@ public static void SetMaxFPS(this IGame game, int targetFPS) Primitive2DModelType.Rectangle => size is null ? new BoxColliderShapeDesc() { Is2D = true } : new() { Size = new(size.Value.X, size.Value.Y, 0), Is2D = true }, Primitive2DModelType.Square => size is null ? new BoxColliderShapeDesc() { Is2D = true } : new() { Size = new(size.Value.X, size.Value.Y, 0), Is2D = true }, Primitive2DModelType.Circle => size is null ? new SphereColliderShapeDesc() : new() { Radius = size.Value.X, Is2D = true }, + Primitive2DModelType.Capsule => size is null ? new CapsuleColliderShapeDesc() : new() { Radius = size.Value.X, Is2D = true }, _ => throw new InvalidOperationException(), }; - private static IInlineColliderShapeDesc? Get3DColliderShape(PrimitiveModelType type, Vector3? size = null, bool is2D = false) + private static IInlineColliderShapeDesc? Get3DColliderShape(PrimitiveModelType type, Vector3? size = null) => type switch { PrimitiveModelType.Plane => size is null ? new BoxColliderShapeDesc() : new() { Size = new Vector3(size.Value.X, 0, size.Value.Y) }, PrimitiveModelType.InfinitePlane => new StaticPlaneColliderShapeDesc(), - PrimitiveModelType.Sphere => size is null ? new SphereColliderShapeDesc() : new() { Radius = size.Value.X, Is2D = is2D }, - PrimitiveModelType.Cube => size is null ? new BoxColliderShapeDesc() : new() { Size = size ?? Vector3.One, Is2D = is2D }, + PrimitiveModelType.Sphere => size is null ? new SphereColliderShapeDesc() : new() { Radius = size.Value.X }, + PrimitiveModelType.Cube => size is null ? new BoxColliderShapeDesc() : new() { Size = size ?? Vector3.One }, PrimitiveModelType.Cylinder => size is null ? new CylinderColliderShapeDesc() : new() { Radius = size.Value.X, Height = size.Value.Y }, PrimitiveModelType.Torus => null, PrimitiveModelType.Teapot => null, PrimitiveModelType.Cone => size is null ? new ConeColliderShapeDesc() : new() { Radius = size.Value.X, Height = size.Value.Y }, - PrimitiveModelType.Capsule => size is null ? new CapsuleColliderShapeDesc() { Radius = 0.35f } : new() { Radius = size.Value.X, Length = size.Value.Y, Is2D = is2D }, + PrimitiveModelType.Capsule => size is null ? new CapsuleColliderShapeDesc() { Radius = 0.35f } : new() { Radius = size.Value.X, Length = size.Value.Y }, _ => throw new InvalidOperationException(), }; } \ No newline at end of file diff --git a/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptions.cs b/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptions.cs index 5b5be5d2..4234738f 100644 --- a/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptions.cs +++ b/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptions.cs @@ -1,40 +1,19 @@ -using Stride.Engine; +using Stride.Engine; using Stride.Physics; -using Stride.Rendering; namespace Stride.CommunityToolkit.Engine; -public class Primitive2DCreationOptions +public class Primitive2DCreationOptions : PrimitiveCreationOptions { - /// - /// Gets or sets the name of the entity. - /// - public string? EntityName { get; set; } - - /// - /// Gets or sets the material to be applied to the primitive model. - /// - public Material? Material { get; set; } - - /// - /// Determines whether to include a collider component in the entity. Defaults to true. - /// - public bool IncludeCollider { get; set; } = true; - /// /// Gets or sets the size of the primitive model. If null, default dimensions are used. /// public Vector2? Size { get; set; } - /// - /// Gets or sets the render group for the entity. Defaults to RenderGroup.Group0. - /// - public RenderGroup RenderGroup { get; set; } = RenderGroup.Group0; + public float Depth { get; set; } = 0.04f; /// /// Gets or sets the physics component to be added to the entity. Defaults to a new instance of RigidbodyComponent. /// public PhysicsComponent? PhysicsComponent { get; set; } = new RigidbodyComponent(); - - public float Depth { get; set; } = 0.04f; } \ No newline at end of file diff --git a/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptionsWithBepu.cs b/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptionsWithBepu.cs new file mode 100644 index 00000000..751b3888 --- /dev/null +++ b/src/Stride.CommunityToolkit/Engine/Primitive2DCreationOptionsWithBepu.cs @@ -0,0 +1,20 @@ +using Stride.BepuPhysics; +using Stride.BepuPhysics.Definitions.Colliders; +using Stride.CommunityToolkit.Bepu; + +namespace Stride.CommunityToolkit.Engine; + +public class Primitive2DCreationOptionsWithBepu : PrimitiveCreationOptions +{ + /// + /// Gets or sets the size of the primitive model. If null, default dimensions are used. + /// + public Vector2? Size { get; set; } + + public float Depth { get; set; } = 1; + + /// + /// Gets or sets the physics component to be added to the entity. + /// + public ContainerComponent Component { get; set; } = new Body2DComponent() { Collider = new CompoundCollider() }; +} \ No newline at end of file diff --git a/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptions.cs b/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptions.cs index 08739698..351c197f 100644 --- a/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptions.cs +++ b/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptions.cs @@ -1,121 +1,20 @@ -using Stride.BepuPhysics; -using Stride.BepuPhysics.Definitions.Colliders; using Stride.Engine; using Stride.Physics; -using Stride.Rendering; namespace Stride.CommunityToolkit.Engine; /// /// Provides options for creating a primitive entity in a 3D scene. /// -public class Primitive3DCreationOptions +public class Primitive3DCreationOptions : PrimitiveCreationOptions { - /// - /// Gets or sets the name of the entity. - /// - public string? EntityName { get; set; } - - /// - /// Gets or sets the material to be applied to the primitive model. - /// - public Material? Material { get; set; } - - /// - /// Determines whether to include a collider component in the entity. Defaults to true. - /// - public bool IncludeCollider { get; set; } = true; - /// /// Gets or sets the size of the primitive model. If null, default dimensions are used. /// public Vector3? Size { get; set; } - /// - /// Gets or sets the render group for the entity. Defaults to RenderGroup.Group0. - /// - public RenderGroup RenderGroup { get; set; } = RenderGroup.Group0; - - /// - /// Indicates whether the primitive is 2D. Defaults to false. - /// - public bool Is2D { get; set; } - /// /// Gets or sets the physics component to be added to the entity. Defaults to a new instance of RigidbodyComponent. /// public PhysicsComponent? PhysicsComponent { get; set; } = new RigidbodyComponent(); -} - -/// -/// Provides options for creating a primitive entity in a 3D scene. -/// -public class Primitive3DCreationOptionsWithBepu -{ - /// - /// Gets or sets the name of the entity. - /// - public string? EntityName { get; set; } - - /// - /// Gets or sets the material to be applied to the primitive model. - /// - public Material? Material { get; set; } - - /// - /// Determines whether to include a collider component in the entity. Defaults to true. - /// - public bool IncludeCollider { get; set; } = true; - - /// - /// Gets or sets the size of the primitive model. If null, default dimensions are used. - /// - public Vector3? Size { get; set; } - - /// - /// Gets or sets the render group for the entity. Defaults to RenderGroup.Group0. - /// - public RenderGroup RenderGroup { get; set; } = RenderGroup.Group0; - - /// - /// Gets or sets the physics component to be added to the entity. - /// - public ContainerComponent Component { get; set; } = new BodyComponent() { Collider = new CompoundCollider() }; - - public float Depth { get; set; } = 0.04f; -} - -public class Primitive2DCreationOptionsWithBepu -{ - /// - /// Gets or sets the name of the entity. - /// - public string? EntityName { get; set; } - - /// - /// Gets or sets the material to be applied to the primitive model. - /// - public Material? Material { get; set; } - - /// - /// Determines whether to include a collider component in the entity. Defaults to true. - /// - public bool IncludeCollider { get; set; } = true; - - /// - /// Gets or sets the size of the primitive model. If null, default dimensions are used. - /// - public Vector2? Size { get; set; } - - /// - /// Gets or sets the render group for the entity. Defaults to RenderGroup.Group0. - /// - public RenderGroup RenderGroup { get; set; } = RenderGroup.Group0; - - /// - /// Gets or sets the physics component to be added to the entity. - /// - public ContainerComponent Component { get; set; } = new Body2DComponent() { Collider = new CompoundCollider() }; - - public float Depth { get; set; } = 1; } \ No newline at end of file diff --git a/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptionsWithBepu.cs b/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptionsWithBepu.cs new file mode 100644 index 00000000..60447f6f --- /dev/null +++ b/src/Stride.CommunityToolkit/Engine/Primitive3DCreationOptionsWithBepu.cs @@ -0,0 +1,20 @@ +using Stride.BepuPhysics; +using Stride.BepuPhysics.Definitions.Colliders; + +namespace Stride.CommunityToolkit.Engine; + +/// +/// Provides options for creating a primitive entity in a 3D scene. +/// +public class Primitive3DCreationOptionsWithBepu : PrimitiveCreationOptions +{ + /// + /// Gets or sets the size of the primitive model. If null, default dimensions are used. + /// + public Vector3? Size { get; set; } + + /// + /// Gets or sets the physics component to be added to the entity. + /// + public ContainerComponent Component { get; set; } = new BodyComponent() { Collider = new CompoundCollider() }; +} diff --git a/src/Stride.CommunityToolkit/Engine/PrimitiveCreationOptions.cs b/src/Stride.CommunityToolkit/Engine/PrimitiveCreationOptions.cs new file mode 100644 index 00000000..37a0a983 --- /dev/null +++ b/src/Stride.CommunityToolkit/Engine/PrimitiveCreationOptions.cs @@ -0,0 +1,26 @@ +using Stride.Rendering; + +namespace Stride.CommunityToolkit.Engine; + +public abstract class PrimitiveCreationOptions +{ + /// + /// Gets or sets the name of the entity. + /// + public string? EntityName { get; set; } + + /// + /// Gets or sets the material to be applied to the primitive model. + /// + public Material? Material { get; set; } + + /// + /// Determines whether to include a collider component in the entity. Defaults to true. + /// + public bool IncludeCollider { get; set; } = true; + + /// + /// Gets or sets the render group for the entity. Defaults to RenderGroup.Group0. + /// + public RenderGroup RenderGroup { get; set; } = RenderGroup.Group0; +} \ No newline at end of file