Esempio n. 1
0
        public bool ExtractToTrianglesFromIndexedPrimitives(List <Vector3Int> originalFaceIndices)
        {
            List <Vector3> trianglePos   = new List <Vector3>();
            int            triangleCount = originalFaceIndices.Count;

            for (int i = 0; i < triangleCount; ++i)
            {
                Vector3Int face = originalFaceIndices[i];
                trianglePos.Add(VertexPosArray[face.x]);
                trianglePos.Add(VertexPosArray[face.y]);
                trianglePos.Add(VertexPosArray[face.z]);
            }
            VertexPosArray = trianglePos;

            if (HadNormalData())
            {
                List <Vector3> normalLst = new List <Vector3>();
                for (int i = 0; i < triangleCount; ++i)
                {
                    Vector3Int face = originalFaceIndices[i];
                    normalLst.Add(NormalArray[face.x]);
                    normalLst.Add(NormalArray[face.y]);
                    normalLst.Add(NormalArray[face.z]);
                }
                NormalArray = normalLst;
            }
            if (HadTangentData())
            {
                List <Vector3> tangantLst  = new List <Vector3>();
                List <Vector3> binormalLst = new List <Vector3>();
                for (int i = 0; i < triangleCount; ++i)
                {
                    Vector3Int face = originalFaceIndices[i];
                    tangantLst.Add(TangentArray[face.x]);
                    tangantLst.Add(TangentArray[face.y]);
                    tangantLst.Add(TangentArray[face.z]);
                    binormalLst.Add(BinormalArray[face.x]);
                    binormalLst.Add(BinormalArray[face.y]);
                    binormalLst.Add(BinormalArray[face.z]);
                }
                TangentArray  = tangantLst;
                BinormalArray = binormalLst;
            }
            if (HadVertexColorData())
            {
                List <uint> vertextColorLst = new List <uint>();
                for (int i = 0; i < triangleCount; ++i)
                {
                    Vector3Int face = originalFaceIndices[i];
                    vertextColorLst.Add(VertexColorArray[face.x]);
                    vertextColorLst.Add(VertexColorArray[face.y]);
                    vertextColorLst.Add(VertexColorArray[face.z]);
                }
                VertexColorArray = vertextColorLst;
            }

            if (HadUVData())
            {
                UVGroups.ExtractToTrianglesFromIndexedPrimitives(originalFaceIndices);
            }
            SetMeshObjectType(NullPrimitiveType.MOT_TRIANGLES);
            FaceArray.Clear();
            return(true);
        }
Esempio n. 2
0
        public bool BuildIndexedPrimitives(List <NullMergeIndex> indexMapping)
        {
            if ((GetMeshObjectType() != NullPrimitiveType.MOT_TRIANGLES) || (GetTriangleCount() < 2))
            {
                return(false);
            }
            List <NullVertexStruct> floatData = PrepareFloatDataForVertexMerging();

            if (floatData == null)
            {
                return(false);
            }
            MergeVertices(floatData, indexMapping);

            //update mesh data
            List <Vector3> newVertices = ReCreateCompactData(VertexPosArray, indexMapping);

            VertexPosArray.Clear();
            VertexPosArray = newVertices;

            List <uint> newColors = ReCreateCompactData(VertexColorArray, indexMapping);

            if (VertexColorArray != null && VertexColorArray.Count > 0)
            {
                VertexColorArray.Clear();
                VertexColorArray = newColors;
            }

            List <Vector3> newNormals = ReCreateCompactData(NormalArray, indexMapping);

            if (NormalArray != null && NormalArray.Count > 0)
            {
                NormalArray.Clear();
                NormalArray = newNormals;
            }

            List <Vector3> newTangents = ReCreateCompactData(TangentArray, indexMapping);

            if (TangentArray != null && TangentArray.Count > 0)
            {
                TangentArray.Clear();
                TangentArray = newTangents;
            }

            List <Vector3> newBinormals = ReCreateCompactData(BinormalArray, indexMapping);

            if (BinormalArray != null && BinormalArray.Count > 0)
            {
                BinormalArray.Clear();
                BinormalArray = newBinormals;
            }
            //update uv groups
            if (UVGroups != null)
            {
                UVGroups.BuildIndexedPrimitives(indexMapping);
            }

            List <int> faceIndexes = new List <int>();

            for (int i = 0; i < GetTriangleCount(); i++)
            {
                faceIndexes.Add(i * 3 + 0);
                faceIndexes.Add(i * 3 + 1);
                faceIndexes.Add(i * 3 + 2);
            }
            for (int i = 0; i < indexMapping.Count; i++)
            {
                NullMergeIndex index = indexMapping[i];
                faceIndexes[index.index] = i;
                for (int j = 0; j < index.equalOnes.Count; j++)
                {
                    faceIndexes[index.equalOnes[j]] = i;
                }
            }
            FaceArray.Clear();
            for (int i = 0; i < GetTriangleCount(); i++)
            {
                FaceArray.Add(new Vector3Int(faceIndexes[i * 3 + 0], faceIndexes[i * 3 + 1], faceIndexes[i * 3 + 2]));
            }
            SetMeshObjectType(NullPrimitiveType.MOT_INDEXED_PRIMITIVES);
            return(true);
        }