Пример #1
0
        public static void Restore(DMesh3 mesh, BinaryReader reader)
        {
            int version = reader.ReadInt32();

            if (version != DMesh3Version)
            {
                throw new Exception("gSerialization.Restore: Incorrect DMesh3Version!");
            }

            MeshComponents components = (MeshComponents)reader.ReadInt32();

            Restore(mesh.VerticesBuffer, reader);
            Restore(mesh.TrianglesBuffer, reader);
            Restore(mesh.EdgesBuffer, reader);
            Restore(mesh.EdgesRefCounts.RawRefCounts, reader);

            if ((components & MeshComponents.VertexNormals) != 0)
            {
                mesh.EnableVertexNormals(Vector3f.AxisY);
                Restore(mesh.NormalsBuffer, reader);
            }
            else
            {
                mesh.DiscardVertexNormals();
            }

            if ((components & MeshComponents.VertexColors) != 0)
            {
                mesh.EnableVertexColors(Vector3f.One);
                Restore(mesh.ColorsBuffer, reader);
            }
            else
            {
                mesh.DiscardVertexColors();
            }

            if ((components & MeshComponents.VertexUVs) != 0)
            {
                mesh.EnableVertexUVs(Vector2f.Zero);
                Restore(mesh.UVBuffer, reader);
            }
            else
            {
                mesh.DiscardVertexUVs();
            }

            if ((components & MeshComponents.FaceGroups) != 0)
            {
                mesh.EnableTriangleGroups(0);
                Restore(mesh.GroupsBuffer, reader);
            }
            else
            {
                mesh.DiscardTriangleGroups();
            }

            mesh.RebuildFromEdgeRefcounts();
        }
Пример #2
0
        public virtual void MakeMesh(DMesh3 m)
        {
            int  nV           = vertices.Count;
            bool bWantNormals = WantNormals && normals != null && normals.Count == vertices.Count;

            if (bWantNormals)
            {
                m.EnableVertexNormals(Vector3f.AxisY);
            }

            bool bWantUVs = WantUVs && uv != null && uv.Count == vertices.Count;

            if (bWantUVs)
            {
                m.EnableVertexUVs(Vector2f.Zero);
            }

            for (int i = 0; i < nV; ++i)
            {
                var ni = new NewVertexInfo()
                {
                    v = vertices[i]
                };
                if (bWantNormals)
                {
                    ni.bHaveN = true;
                    ni.n      = normals[i];
                }
                if (bWantUVs)
                {
                    ni.bHaveUV = true;
                    ni.uv      = uv[i];
                }
                int vID = m.AppendVertex(ni);
                Util.gDevAssert(vID == i);
            }
            int nT = triangles.Count;

            if (WantGroups && groups != null && groups.Length == nT)
            {
                m.EnableTriangleGroups();
                for (int i = 0; i < nT; ++i)
                {
                    m.AppendTriangle(triangles[i], groups[i]);
                }
            }
            else
            {
                for (int i = 0; i < nT; ++i)
                {
                    m.AppendTriangle(triangles[i]);
                }
            }
        }
Пример #3
0
        public void CopyTo(DMesh3 SetMesh)
        {
            if (SetMesh.MaxVertexID < Mesh.MaxVertexID)
            {
                throw new Exception("MeshNormals.Set: SetMesh does not have enough vertices!");
            }
            if (!SetMesh.HasVertexNormals)
            {
                SetMesh.EnableVertexNormals(Vector3f.AxisY);
            }
            int NV = Mesh.MaxVertexID;

            for (int vi = 0; vi < NV; ++vi)
            {
                if (Mesh.IsVertex(vi) && SetMesh.IsVertex(vi))
                {
                    SetMesh.SetVertexNormal(vi, (Vector3f)Normals[vi]);
                }
            }
        }