Example #1
0
        public void AddTrianglesTest()
        {
            var T2  = new Triangulation();
            var tr  = new Triangle(v1, v2, v3);
            var tr2 = new Triangle(v1, v3, v4);

            T2.AddTriangles(new List <Triangle>()
            {
                tr, tr2
            });
            Assert.AreEqual(2, T2.Triangles.Count);
        }
Example #2
0
    Mesh GetTriangulationMesh()
    {
        targetTriangulation.Calculate();
        cutterTriangulation.Calculate();

        Mesh mesh = new Mesh
        {
            subMeshCount = 2
        };

        int cutterTriangleCount = targetTriangulation.triangles.Count;
        int targetTriangleCount = cutterTriangulation.triangles.Count;

        int[] verticesA = new int[cutterTriangleCount * 3];
        int[] verticesB = new int[targetTriangleCount * 3];

        targetTriangulation.AddTriangles(cutterTriangulation.vertices.ToArray(), cutterTriangulation.triangles.ToArray());
        targetTriangulation.UpdateLocalPosition(target.transform);

        Vector3[] vertices = new Vector3[targetTriangulation.vertices.Count];
        Vector3[] normals  = new Vector3[targetTriangulation.vertices.Count];
        Vector2[] uv       = new Vector2[targetTriangulation.vertices.Count];

        for (int i = 0; i < targetTriangulation.vertices.Count; i++)
        {
            vertices[i] = targetTriangulation.vertices[i].localPos;
            normals[i]  = targetTriangulation.vertices[i].normal.normalized;
            uv[i]       = targetTriangulation.vertices[i].uv;
        }

        for (int i = 0; i < cutterTriangleCount; i++)
        {
            verticesA[i * 3]     = targetTriangulation.triangles[i].verticesIndexes[0];
            verticesA[i * 3 + 1] = targetTriangulation.triangles[i].verticesIndexes[1];
            verticesA[i * 3 + 2] = targetTriangulation.triangles[i].verticesIndexes[2];
        }

        for (int i = 0; i < targetTriangleCount; i++)
        {
            verticesB[i * 3]     = targetTriangulation.triangles[cutterTriangleCount + i].verticesIndexes[0];
            verticesB[i * 3 + 1] = targetTriangulation.triangles[cutterTriangleCount + i].verticesIndexes[1];
            verticesB[i * 3 + 2] = targetTriangulation.triangles[cutterTriangleCount + i].verticesIndexes[2];
        }

        RecalculateTriangles(vertices, normals, verticesA);
        if (legacyKeepCutterGeometry)
        {
            RecalculateTriangles(vertices, normals, verticesB);
        }

        mesh.vertices = vertices;
        mesh.normals  = normals;
        mesh.uv       = uv;
        mesh.SetTriangles(verticesA, 0);
        if (legacyKeepCutterGeometry)
        {
            mesh.SetTriangles(verticesB, 1);
        }

        return(mesh);
    }