Beispiel #1
0
        public void Optimise()
        {
            List <C2Vertex> points = new List <C2Vertex>();
            List <Vector3>  verts  = new List <Vector3>();
            List <Vector2>  uvs    = new List <Vector2>();

            for (int i = 0; i < Verts.Count; i++)
            {
                C2Vertex p = new C2Vertex(Verts[i], UVs[i]);

                //Console.WriteLine("Vert " + i);
                int newID = points.IndexOf(p);
                //int newID = verts.IndexOf(Verts[i]);

                if (newID == -1)
                {
                    //Console.WriteLine("Adding " + p.ToString());
                    points.Add(p);
                    verts.Add(Verts[i]);
                    uvs.Add(UVs[i]);
                    newID = verts.Count - 1;
                }

                for (int j = 0; j < Faces.Count; j++)
                {
                    Faces[j].ReplaceVertID(i, newID);
                }
            }

            //Console.WriteLine("Reduced Vert count from " + Verts.Count + " to " + verts.Count);
            //Console.WriteLine("Reduced UV count from " + UVs.Count + " to " + uvs.Count);

            Verts.Clear();
            for (int i = 0; i < verts.Count; i++)
            {
                Verts.Add(verts[i]);
            }
            UVs.Clear();
            for (int i = 0; i < uvs.Count; i++)
            {
                UVs.Add(uvs[i]);
            }
        }
        private void StartTubeSegment()
        {
            currentSegmentLength = 0;
            Verts.Clear();
            Tris.Clear();
            UVs.Clear();

            CurrentSegment = new GameObject();
            CurrentSegment.AddComponent <MeshFilter>();
            CurrentSegment.AddComponent <MeshRenderer>();

            Mesh = CurrentSegment.GetComponent <MeshFilter>().mesh;
            Mesh.MarkDynamic();
            CurrentSegment.GetComponent <Renderer>().material = Material;
            Mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

            UpdateVertsAndUVs();
            Mesh.RecalculateNormals();
            LoopCount = 1;
        }