Exemplo n.º 1
0
        //public void CopyTo(SimpleMesh mTo)
        //{
        //    mTo.Vertices = Util.BufferCopy(this.Vertices, mTo.Vertices);
        //    mTo.Normals = Util.BufferCopy(this.Normals, mTo.Normals);
        //    mTo.Colors = Util.BufferCopy(this.Colors, mTo.Colors);
        //    mTo.Triangles = Util.BufferCopy(this.Triangles, mTo.Triangles);
        //    mTo.FaceGroups = Util.BufferCopy(this.FaceGroups, mTo.FaceGroups);
        //}

        //public object Clone()
        //{
        //    SimpleMesh mTo = new SimpleMesh();
        //    this.CopyTo(mTo);
        //    return mTo;
        //}

        public SimpleMesh(IMesh copy)
        {
            Initialize(copy.HasVertexNormals, copy.HasVertexColors, copy.HasVertexUVs, copy.HasTriangleGroups);
            int[] mapV = new int[copy.MaxVertexID];
            foreach (int vid in copy.VertexIndices())
            {
                NewVertexInfo vi      = copy.GetVertexAll(vid);
                int           new_vid = AppendVertex(vi);
                mapV[vid] = new_vid;
            }
            foreach (int tid in copy.TriangleIndices())
            {
                Index3i t = copy.GetTriangle(tid);
                t[0] = mapV[t[0]];
                t[1] = mapV[t[1]];
                t[2] = mapV[t[2]];
                if (copy.HasTriangleGroups)
                {
                    AppendTriangle(t[0], t[1], t[2], copy.GetTriangleGroup(tid));
                }
                else
                {
                    AppendTriangle(t[0], t[1], t[2]);
                }
            }
        }
Exemplo n.º 2
0
        public int AppendVertex(NewVertexInfo info)
        {
            int i = Vertices.Length / 3;

            if (info.bHaveN && HasVertexNormals)
            {
                Normals.Add(info.n[0]); Normals.Add(info.n[1]); Normals.Add(info.n[2]);
            }
            else if (HasVertexNormals)
            {
                Normals.Add(0); Normals.Add(1); Normals.Add(0);
            }
            if (info.bHaveC && HasVertexColors)
            {
                Colors.Add(info.c[0]); Colors.Add(info.c[1]); Colors.Add(info.c[2]);
            }
            else if (HasVertexColors)
            {
                Colors.Add(1); Colors.Add(1); Colors.Add(1);
            }
            if (info.bHaveUV && HasVertexUVs)
            {
                UVs.Add(info.uv[0]); UVs.Add(info.uv[1]);
            }
            else if (HasVertexUVs)
            {
                UVs.Add(0); UVs.Add(0);
            }

            Vertices.Add(info.v[0]); Vertices.Add(info.v[1]); Vertices.Add(info.v[2]);
            return(i);
        }
Exemplo n.º 3
0
        public NewVertexInfo GetVertexAll(int i)
        {
            NewVertexInfo vi = new NewVertexInfo();

            vi.v = GetVertex(i);
            if (HasVertexNormals)
            {
                vi.bHaveN = true;
                vi.n      = GetVertexNormal(i);
            }
            else
            {
                vi.bHaveN = false;
            }
            if (HasVertexColors)
            {
                vi.bHaveC = true;
                vi.c      = GetVertexColor(i);
            }
            else
            {
                vi.bHaveC = false;
            }
            if (HasVertexUVs)
            {
                vi.bHaveUV = true;
                vi.uv      = GetVertexUV(i);
            }
            else
            {
                vi.bHaveUV = false;
            }
            return(vi);
        }
Exemplo n.º 4
0
        public bool AppendMesh(IMesh appendMesh, out int[] mapV, int appendGID = -1)
        {
            mapV = new int[appendMesh.MaxVertexID];
            foreach (int vid in appendMesh.VertexIndices())
            {
                NewVertexInfo vinfo  = appendMesh.GetVertexAll(vid);
                int           newvid = Mesh.AppendVertex(vinfo);
                mapV[vid] = newvid;
            }

            foreach (int tid in appendMesh.TriangleIndices())
            {
                Index3i t = appendMesh.GetTriangle(tid);
                t.a = mapV[t.a];
                t.b = mapV[t.b];
                t.c = mapV[t.c];
                int gid = appendMesh.GetTriangleGroup(tid);
                if (appendGID >= 0)
                {
                    gid = appendGID;
                }
                Mesh.AppendTriangle(t, gid);
            }

            return(true);
        }
Exemplo n.º 5
0
 public int AppendVertex(NewVertexInfo info)
 {
     return(Meshes[nActiveMesh].AppendVertex(info));
 }