Class PolygonProceduralModel
- Namespace
- Stride.CommunityToolkit.Rendering.ProceduralModels
- Assembly
- Stride.CommunityToolkit.dll
Generates a planar polygon mesh (convex fan triangulation) from an arbitrary set of 2D vertices.
public class PolygonProceduralModel : PrimitiveProceduralModelBase, IProceduralModel
- Inheritance
-
PolygonProceduralModel
- Implements
- Inherited Members
Remarks
Do not spawn these overlapping each other while they carry a physics collider. A polygon
gets a convex-hull collider, and Bepu's hull-versus-hull contact generation returns
depth = NaN for two overlapping extruded polygons. The NaN reaches the body poses on
the same timestep, and Tree.Add then never returns - the application hangs with one core
pegged and no exception to catch.
There is no safe Sides value to dodge it. A Monte Carlo sweep over random overlapping poses fails for every side count from 3 upwards, at 15-40% of placements once the bodies have rotated about Z; freshly spawned axis-aligned bodies fail at roughly 40% for 5, 7 and 8 sides. Triangles and custom-vertex polygons are exposed for the same reason. The identical placements with an analytic box collider never fail, so this is the hull path alone.
The only mitigation available today is to space spawns so hull-collider bodies do not start interpenetrating. A fix belongs upstream in Bepu; until it lands, treat overlap as unsupported.
Properties
Radius
Gets or sets the circumradius of the regular polygon used when Vertices is empty.
public float Radius { get; set; }
Property Value
Sides
Gets or sets the number of sides of the regular polygon used when Vertices is empty.
public int Sides { get; set; }
Property Value
Remarks
The value must be greater than or equal to 3. No value is safer than any other where physics is concerned - see the remarks on PolygonProceduralModel before spawning these overlapping.
Vertices
Gets or sets the vertex positions in the XY plane defining a custom polygon outline.
public Vector2[] Vertices { get; set; }
Property Value
- Vector2[]
Remarks
When empty, a regular polygon is generated from Radius and Sides. Custom vertices must contain at least 3 unique points and should be ordered around a convex outline.
Methods
CreateMesh(Vector2[], float, float, bool)
Builds a new mesh for the given points (no caching). Assumes convex ordering; uses fan triangulation.
public static GeometricMeshData<VertexPositionNormalTexture> CreateMesh(Vector2[] points, float uScale = 1, float vScale = 1, bool toLeftHanded = false)
Parameters
pointsVector2[]The polygon vertices in the XY plane.
uScalefloatThe U coordinate scale factor.
vScalefloatThe V coordinate scale factor.
toLeftHandedboolWhether to convert the mesh to left-handed coordinates.
Returns
- GeometricMeshData<VertexPositionNormalTexture>
A geometric mesh data instance representing the polygon.
Exceptions
- ArgumentNullException
Thrown when
pointsis null.- ArgumentException
Thrown when
pointscontains fewer than 3 points, duplicate points, or does not span both axes.
CreatePrimitiveMeshData()
protected override GeometricMeshData<VertexPositionNormalTexture> CreatePrimitiveMeshData()
Returns
CreateRectangle(Vector2)
Convenience factory for an axis-aligned rectangle centered at the origin.
public static PolygonProceduralModel CreateRectangle(Vector2 size)
Parameters
sizeVector2The rectangle width and height.
Returns
- PolygonProceduralModel
A polygon model configured with four rectangle vertices.
CreateTriangle(Vector2)
Convenience factory for an isosceles triangle centered at the origin.
public static PolygonProceduralModel CreateTriangle(Vector2 size)
Parameters
sizeVector2The triangle width and height.
Returns
- PolygonProceduralModel
A polygon model configured with three triangle vertices.
GenerateRegularPolygonVertices(float, int)
Generates vertices for a regular polygon centered at the origin.
public static Vector2[] GenerateRegularPolygonVertices(float radius, int sides)
Parameters
radiusfloatThe polygon circumradius. Must be greater than 0.
sidesintThe number of polygon sides. Must be greater than or equal to 3.
Returns
- Vector2[]
The generated polygon vertices in the XY plane.
Exceptions
- ArgumentOutOfRangeException
Thrown when
radiusis not positive orsidesis less than 3.
New(Vector2[], float, float, bool)
Creates (or retrieves from cache) a mesh for the supplied polygon vertex list.
public static GeometricMeshData<VertexPositionNormalTexture> New(Vector2[] vertices, float uScale = 1, float vScale = 1, bool toLeftHanded = false)
Parameters
verticesVector2[]The polygon vertices in the XY plane.
uScalefloatThe U coordinate scale factor.
vScalefloatThe V coordinate scale factor.
toLeftHandedboolWhether to convert the mesh to left-handed coordinates.
Returns
- GeometricMeshData<VertexPositionNormalTexture>
A geometric mesh data instance representing the polygon.
Exceptions
- ArgumentNullException
Thrown when
verticesis null.- ArgumentException
Thrown when
verticescontains fewer than 3 points or duplicate points.