⚠ Preview docs — built from the develop branch and may be unstable. Go to the stable docs.

SpatialEntity.TryGetMesh2D

bool TryGetMesh2D(Mesh mesh, Pose& origin)

The entity’s 2D surface mesh, on the XY plane of the origin pose. Works just like TryGetMesh, so pass null to fetch only the origin, and refill when Changed flags the Mesh2D component.

   
Mesh mesh A valid Mesh to fill with the entity’s geometry, or null to only retrieve the origin pose.
Pose& origin Pose the mesh’s vertices are relative to.
RETURNS: bool False if this entity has no mesh2d component.

Examples

Keeping a mesh for each plane

Filling a Mesh isn’t free, so this only refills when the plane’s shape changes, and drops the mesh when the plane goes away.

Dictionary<SpatialEntity, Mesh> planeMeshes = new Dictionary<SpatialEntity, Mesh>();

public void StepPlaneMeshes()
{
	foreach (SpatialEntity plane in SpatialEntity.With(SpatialComponent.Mesh2D))
	{
		bool isNew = !planeMeshes.TryGetValue(plane, out Mesh mesh);
		if (isNew)
		{
			mesh = new Mesh();
			planeMeshes.Add(plane, mesh);
		}

		// A null mesh only fetches the origin, which moves every frame
		bool refill = isNew || plane.HasChanged(SpatialComponent.Mesh2D);
		plane.TryGetMesh2D(refill ? mesh : null, out Pose origin);
		mesh.Draw(Material.Default, origin.ToMatrix());
	}

	// Removed entities are still readable this frame, so clean up here
	foreach (SpatialEntity plane in SpatialEntity.Removed)
		planeMeshes.Remove(plane);
}




Found an issue with these docs, or have some additional questions? Create an Issue on Github!