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.
No Sides value avoids it, and triangles and custom-vertex polygons are affected too; box colliders are not. Space spawns so hull-collider bodies do not start interpenetrating.
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.