示例#1
0
        public Mesh getFace(out int[] verticesInCenter)
        {
            var colliderCube = gameObject.GetComponent <MeshCollider>();

            List <Int32> trianglesDetected = getTrianglesInFront();

            List <Int32> indicesVerticesDetected_f1;

            int[]     trianglesFront_f1;
            Vector3[] verticesWithDetectedFrontFace_f1,
            verticesWithDetectedBackFace_f1;
            Vector2[] uv_f1;
            Vector2[] verticesFrontGlobalCordinates;


            getTrianglesAndVertices(
                trianglesDetected,
                colliderCube.sharedMesh,
                out indicesVerticesDetected_f1,
                out trianglesFront_f1,
                out verticesWithDetectedFrontFace_f1,
                out verticesWithDetectedBackFace_f1,
                out uv_f1,
                out verticesFrontGlobalCordinates
                );

            int[] trianglesFrontFace_f2 = new int[trianglesDetected.Count * 3];
            int[] trianglesBackFace_f2  = new int[trianglesDetected.Count * 3];

            Vector3[] verticesFrontFace_f2 = new Vector3[indicesVerticesDetected_f1.Count];
            Vector3[] verticesBackFace_f2  = new Vector3[indicesVerticesDetected_f1.Count];
            Vector2[] uv_f2 = new Vector2[indicesVerticesDetected_f1.Count];

            int indexVertice_f2 = 0;

            foreach (Int32 indexVertice_f1 in indicesVerticesDetected_f1)
            {
                verticesFrontFace_f2[indexVertice_f2] = verticesWithDetectedFrontFace_f1[indexVertice_f1];
                verticesBackFace_f2[indexVertice_f2]  = verticesWithDetectedBackFace_f1[indexVertice_f1];

                uv_f2[indexVertice_f2] = uv_f1[indexVertice_f1];
                for (int t = 0; t < trianglesFront_f1.Length; t++)
                {
                    if (trianglesFront_f1[t] == indexVertice_f1)
                    {
                        trianglesFrontFace_f2[t] = indexVertice_f2;
                        trianglesBackFace_f2[t]  = indexVertice_f2 + verticesBackFace_f2.Length;
                    }
                }
                indexVertice_f2++;
            }

            int offset = verticesFrontFace_f2.Length;

            List <Vector3> listVerticesFrontFace_f2 = new List <Vector3>();
            List <Vector2> listUvFrontFace_f2       = new List <Vector2>();

            for (int vf = 0; vf < verticesFrontFace_f2.Length; vf++)
            {
                Vector3 currentVertex = verticesFrontFace_f2[vf];
                // Checar si se repite
                if (!listVerticesFrontFace_f2.Exists(notReptitiveVertex => notReptitiveVertex == currentVertex))
                {
                    // SI no se repite agregarlo
                    listVerticesFrontFace_f2.Add(currentVertex);
                    listUvFrontFace_f2.Add(uv_f2[vf]);
                    int indexCurrentVertex = listVerticesFrontFace_f2.Count - 1;
                    for (int t = 0; t < trianglesFrontFace_f2.Length; t++)
                    {
                        if (verticesFrontFace_f2[trianglesFrontFace_f2[t]] == currentVertex)
                        {
                            trianglesFrontFace_f2[t] = indexCurrentVertex;
                        }
                    }
                }
            }

            Mesh meshFront_f1 = new Mesh();

            meshFront_f1.vertices  = listVerticesFrontFace_f2.ToArray();
            meshFront_f1.triangles = trianglesFrontFace_f2;
            meshFront_f1.uv        = listUvFrontFace_f2.ToArray();

            verticesInCenter = VertexClassifier.getVerticesInCenter(meshFront_f1, verticesFrontGlobalCordinates, gameObject.transform);

            return(meshFront_f1);
        }
示例#2
0
        public Mesh getFaceDeprecated(out int[] verticesInCenter)
        {
            var colliderCube = gameObject.GetComponent <MeshCollider>();

            List <Int32> trianglesDetected = getTrianglesInFront();

            List <Int32> indicesVerticesDetected_f1;

            int[]     trianglesFront_f1;
            Vector3[] verticesWithDetectedFrontFace_f1,
            verticesWithDetectedBackFace_f1;
            Vector2[] uv_f1;
            Vector2[] verticesFrontGlobalCordinates;


            getTrianglesAndVertices(
                trianglesDetected,
                colliderCube.sharedMesh,
                out indicesVerticesDetected_f1,
                out trianglesFront_f1,
                out verticesWithDetectedFrontFace_f1,
                out verticesWithDetectedBackFace_f1,
                out uv_f1,
                out verticesFrontGlobalCordinates
                );

            int[] trianglesFrontFace_f2 = new int[trianglesDetected.Count * 3];
            int[] trianglesBackFace_f2  = new int[trianglesDetected.Count * 3];

            Vector3[] verticesFrontFace_f2 = new Vector3[indicesVerticesDetected_f1.Count];
            Vector3[] verticesBackFace_f2  = new Vector3[indicesVerticesDetected_f1.Count];
            Vector2[] uv_f2 = new Vector2[indicesVerticesDetected_f1.Count];

            int indexVertice_f2 = 0;

            foreach (Int32 indexVertice_f1 in indicesVerticesDetected_f1)
            {
                verticesFrontFace_f2[indexVertice_f2] = verticesWithDetectedFrontFace_f1[indexVertice_f1];
                verticesBackFace_f2[indexVertice_f2]  = verticesWithDetectedBackFace_f1[indexVertice_f1];

                uv_f2[indexVertice_f2] = uv_f1[indexVertice_f1];
                for (int t = 0; t < trianglesFront_f1.Length; t++)
                {
                    if (trianglesFront_f1[t] == indexVertice_f1)
                    {
                        trianglesFrontFace_f2[t] = indexVertice_f2;
                        trianglesBackFace_f2[t]  = indexVertice_f2 + verticesBackFace_f2.Length;
                    }
                }
                indexVertice_f2++;
            }

            Vector3[] verticesForHole = new Vector3[verticesFrontFace_f2.Length + verticesBackFace_f2.Length];
            Array.Copy(verticesFrontFace_f2, verticesForHole, verticesFrontFace_f2.Length);
            Array.Copy(verticesBackFace_f2, 0, verticesForHole, verticesFrontFace_f2.Length, verticesBackFace_f2.Length);

            Vector2[] uvsForHole = new Vector2[uv_f2.Length + uv_f2.Length];
            Array.Copy(uv_f2, uvsForHole, uv_f2.Length);
            Array.Copy(uv_f2, 0, uvsForHole, uv_f2.Length, uv_f2.Length);


            int offset = verticesFrontFace_f2.Length;

            Mesh meshFront_f1 = new Mesh();

            meshFront_f1.vertices  = verticesFrontFace_f2;
            meshFront_f1.triangles = trianglesFrontFace_f2;
            meshFront_f1.uv        = uv_f2;

            verticesInCenter = VertexClassifier.getVerticesInCenter(meshFront_f1, verticesFrontGlobalCordinates, gameObject.transform);

            return(meshFront_f1);
        }