SpatialEntity.TryGetPolygon
bool TryGetPolygon(Pose& origin, Vec2[]& polygon)
The boundary polygon outlining the entity’s surface, on the XY plane of the origin pose. This allocates a new array each call, so for every frame use, prefer the overload that reuses one.
| Pose& origin | Pose the polygon’s points are relative to. |
| Vec2[]& polygon | A copy of the boundary points, in meters on the origin’s XY plane. |
| RETURNS: bool | False if this entity has no polygon component. |
bool TryGetPolygon(Pose& origin, Vec2[]& polygon, Int32& count)
The boundary polygon outlining the entity’s surface,
copied into an array you keep, so calling this every frame doesn’t
allocate. The array only grows when it’s too small, so use
count rather than its length.
| Pose& origin | Pose the polygon’s points are relative to. |
| Vec2[]& polygon | An array to copy the boundary points into, in meters on the origin’s XY plane. Null is fine, it’s created as needed. |
| Int32& count | How many points in the array belong to this polygon. |
| RETURNS: bool | False if this entity has no polygon component. |
Examples
Outlining a plane’s real shape
Bounds are a rectangle, while the polygon follows the actual edge, like an L-shaped counter. This runs every frame, so it reuses one array instead of allocating a new one each time.
static Vec2[] outline;
static void DrawOutline(SpatialEntity plane)
{
if (!plane.TryGetPolygon(out Pose origin, ref outline, out int count)) return;
Matrix toWorld = origin.ToMatrix();
for (int i = 0; i < count; i++)
{
Vec3 start = toWorld.Transform(outline[i].XY0);
Vec3 end = toWorld.Transform(outline[(i + 1) % count].XY0);
Lines.Add(start, end, Color32.White, 0.005f);
}
}
Found an issue with these docs, or have some additional questions? Create an Issue on Github!