Beispiel #1
0
    /// <summary>
    /// Preform the first step of clipping, which is unpacking the mesh on the main thread
    /// </summary>
    /// <param name="mesh"></param>
    /// <param name="clippingPlaneSet"></param>
    /// <returns></returns>
    private static Task <List <MeshPoly> > ClipUnpack(Mesh mesh, ClippingPlaneSet clippingPlaneSet, Matrix4x4 worldToMeshSpace)
    {
        List <MeshPoly> output = new List <MeshPoly>();

        Vector3[] vertices  = mesh.vertices;
        Vector2[] uvs       = mesh.uv;
        int[]     triangles = mesh.triangles;
        Vector3[] normals   = mesh.normals;
        Vector4[] tangents  = mesh.tangents;
        Color[]   colors    = mesh.colors;

        return(Task.Run(() =>
        {
            return ClipEachPolygonByEachClippingPlane(
                ArrayToPolys(vertices, uvs, triangles, normals, tangents, colors),
                clippingPlaneSet, worldToMeshSpace);
        }));
    }
Beispiel #2
0
    /// <summary>
    /// Clips each polygon to each clipping plane
    /// </summary>
    /// <param name="polys"></param>
    /// <param name="clippingPlaneSet"></param>
    /// <returns></returns>
    private static List <MeshPoly> ClipEachPolygonByEachClippingPlane(
        List <MeshPoly> polys,
        ClippingPlaneSet clippingPlaneSet,
        Matrix4x4 worldToMeshSpace)
    {
        try
        {
            foreach (var plane in clippingPlaneSet)
            {
                polys = ClipEachPolyByClippingPlane(polys, plane, worldToMeshSpace);
            }

            return(polys);
        }
        catch (Exception e)
        {
            MainThreadDispatcher.Dispatch(() => { Debug.LogError(e); });
            throw e;
        }
    }
Beispiel #3
0
 /// <summary>
 /// Create a task to clip a new mesh.
 /// </summary>
 /// <param name="mesh"></param>
 /// <param name="clippingPlaneSet"></param>
 /// <param name="source"></param>
 /// <returns></returns>
 public static Task <Mesh> Clip(Mesh mesh, ClippingPlaneSet clippingPlaneSet, Matrix4x4 worldToMeshSpace, Mesh source = null)
 {
     return(ClipUnpack(mesh, clippingPlaneSet, worldToMeshSpace).ThenOnMainThread((x) => MeshPoly.ContructMesh(x, source)));
 }