Пример #1
0
        public T SeperatePolygonGroup <T>(STGenericMesh mesh, int index)
            where T : STGenericMesh, new()
        {
            T newMesh = new T();

            newMesh.Name = index == 0 ? mesh.Name : $"{mesh.Name}_{index}";

            Dictionary <STVertex, int> verticesNew = new Dictionary <STVertex, int>();

            STPolygonGroup group = new STPolygonGroup();

            group.Material      = this.Material;
            group.MaterialIndex = this.MaterialIndex;
            newMesh.PolygonGroups.Add(group);

            for (int i = 0; i < Faces.Count; i++)
            {
                if (!verticesNew.ContainsKey(mesh.Vertices[(int)Faces[i]]))
                {
                    verticesNew.Add(mesh.Vertices[(int)Faces[i]], verticesNew.Count);
                }

                group.Faces.Add(Faces[i]);
            }

            newMesh.Vertices = verticesNew.Keys.ToList();
            return(newMesh);
        }
Пример #2
0
        /// <summary>
        /// Optmizes the indices by regenerating them from the given polygon group.
        /// </summary>
        /// <param name="group"></param>
        public void Optmize(STPolygonGroup group)
        {
            Dictionary <STVertex, int> verticesNew = new Dictionary <STVertex, int>();

            group.Faces.Clear();

            foreach (var v in Vertices)
            {
                if (!verticesNew.ContainsKey(v))
                {
                    verticesNew.Add(v, verticesNew.Count);
                }

                if (verticesNew.ContainsKey(v))
                {
                    group.Faces.Add((uint)verticesNew[v]);
                }
            }

            Vertices.Clear();
            Vertices.AddRange(verticesNew.Keys);
        }