Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Physics] Adding margins to convex hull colliders (Issue1577) #2257

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ from shape in Parameters.ColliderShapes
ConvexHullColliderShapeDesc convexHullDescClone = new ConvexHullColliderShapeDesc
{
Scaling = convexHullDesc.Scaling,
Margin = convexHullDesc.Margin,
LocalOffset = convexHullDesc.LocalOffset,
LocalRotation = convexHullDesc.LocalRotation,
Decomposition = convexHullDesc.Decomposition,
Expand Down
6 changes: 6 additions & 0 deletions sources/engine/Stride.Physics/ColliderShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ public virtual void UpdateDebugPrimitive(CommandList commandList, IDebugPrimitiv
{
}

public float Margin
{
get { return InternalShape.Margin; }
set { InternalShape.Margin = value; }
}

public Matrix DebugPrimitiveMatrix;

internal bool NeedsCustomCollisionCallback;
Expand Down
10 changes: 10 additions & 0 deletions sources/engine/Stride.Physics/Data/ConvexHullColliderShapeDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public class ConvexHullColliderShapeDesc : IAssetColliderShapeDesc
[DataMember(45)]
public Vector3 Scaling = Vector3.One;

/// <userdoc>
/// The Margin of the generated convex hull.
/// Default = 0.04f
/// </userdoc>
[DataMember(48)]
public float Margin { get; set; } = 0.04f;

/// <userdoc>
/// If this is not checked, the contained parameters are ignored and only a simple convex hull of the model will be generated.
/// </userdoc>
Expand Down Expand Up @@ -84,6 +91,7 @@ public ColliderShape CreateShape(IServiceRegistry services)
shape = new ConvexHullColliderShape(ConvexHulls[0][0], ConvexHullsIndices[0][0], Scaling)
{
NeedsCustomCollisionCallback = true,
Margin = Margin,
};

//shape.UpdateLocalTransformations();
Expand All @@ -107,6 +115,7 @@ public ColliderShape CreateShape(IServiceRegistry services)
if (indices.Count == 0) continue;

var subHull = new ConvexHullColliderShape(verts, indices, Scaling);
subHull.Margin = Margin;
//subHull.UpdateLocalTransformations();
subCompound.AddChildShape(subHull);
}
Expand Down Expand Up @@ -134,6 +143,7 @@ public ColliderShape CreateShape(IServiceRegistry services)
if (indices[0].Count == 0) continue;

var subHull = new ConvexHullColliderShape(verts[0], indices[0], Scaling);
subHull.Margin = Margin;
//subHull.UpdateLocalTransformations();
compound.AddChildShape(subHull);
}
Expand Down