示例#1
0
        public void MergeVertices(List <NullVertexStruct> vertices, List <NullMergeIndex> indexMapping)
        {
            indexMapping.Clear();
            if (vertices == null || vertices.Count < 3)
            {
                return;
            }

            for (int i = 0; i < vertices.Count; i++)
            {
                NullVertexStruct vertex = vertices[i];
                bool             merged = false;
                foreach (NullMergeIndex index in indexMapping)
                {
                    if (vertices[index.index].IsEquals(vertex))
                    {
                        merged = true;
                        index.equalOnes.Add(i);
                        break;
                    }
                }
                if (!merged)
                {
                    NullMergeIndex index = new NullMergeIndex(i);
                    indexMapping.Add(index);
                }
            }
        }
示例#2
0
        public static List <T> ReCreateCompactData <T>(List <T> sourceData, List <NullMergeIndex> indexMapping)
        {
            if (sourceData == null && sourceData.Count > 0)
            {
                return(null);
            }
            List <T> dst = new List <T>();

            for (int i = 0; i < indexMapping.Count; i++)
            {
                NullMergeIndex index = indexMapping[i];
                dst.Add(sourceData[index.index]);
            }
            return(dst);
        }
示例#3
0
        public bool BuildIndexedPrimitives(List <NullMergeIndex> indexMapping)
        {
            //build new node-array
            List <NullSkeletonBindingNode> newBindingNodeArray = new List <NullSkeletonBindingNode>();

            for (int i = 0; i < indexMapping.Count; i++)
            {
                newBindingNodeArray.Add(new NullSkeletonBindingNode(CurrentVersion));
            }
            //extract
            for (int i = 0; i < indexMapping.Count; i++)
            {
                NullMemoryStream stream = NullMemoryStream.ReadAndWrite();
                NullMergeIndex   index  = indexMapping[i];
                mBindingNodeArray[index.index].SaveToStream(stream);
                newBindingNodeArray[i].LoadFromStream(stream);
            }
            for (int i = 0; i < mBindingNodeArray.Count; i++)
            {
                mBindingNodeArray[i].Clear();
            }
            mBindingNodeArray = newBindingNodeArray;
            return(true);
        }
示例#4
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);
        }