示例#1
0
        /// <summary>
        /// Computes vertex normals.
        /// </summary>
        /// <param name="cornerArea">A halfedge dynamic trait with face vertex angular areas.</param>
        /// <param name="pointArea">A vertex dynamic trait with vertex angular areas.</param>
        public void ComputeFaceVertexNormals(TriMesh mesh, TriMesh.HalfedgeDynamicTrait <float> cornerArea, TriMesh.VertexDynamicTrait <float> pointArea)
        {
            TriMesh.FaceDynamicTrait <Vector3D> normal = new TriMesh.FaceDynamicTrait <Vector3D>(mesh);

            TriMesh.Vertex[] fv = new TriMesh.Vertex[3];

            // Compute normal for each face
            foreach (TriMesh.Face f in mesh.Faces)
            {
                int i = 0;
                foreach (TriMesh.Vertex v in f.Vertices)
                {
                    fv[i] = v;
                    ++i;
                }

                // Compute normal for this face
                normal[f]       = (fv[2].Traits.Position - fv[1].Traits.Position).Cross(fv[0].Traits.Position - fv[2].Traits.Position);
                normal[f]       = normal[f].Normalize();
                f.Traits.Normal = normal[f];
            }

            // Compute normal for each vertex
            foreach (TriMesh.HalfEdge h in  mesh.HalfEdges)
            {
                if (!h.OnBoundary)  // Ignore halfedges that don't have a face
                {
                    float weight = cornerArea[h] / pointArea[h.ToVertex];
                    h.ToVertex.Traits.Normal += weight * normal[h.Face];
                }
            }

            // Normalize normals
            foreach (TriMesh.Vertex v in mesh.Vertices)
            {
                if (Math.Sqrt(v.Traits.Normal.Length()) > 0.0f)    // Ignore isolated points
                {
                    v.Traits.Normal.Normalize();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Computes vertex normals.
        /// </summary>
        /// <param name="cornerArea">A halfedge dynamic trait with face vertex angular areas.</param>
        /// <param name="pointArea">A vertex dynamic trait with vertex angular areas.</param>
        public void ComputeFaceVertexNormals(TriMesh mesh, TriMesh.HalfedgeDynamicTrait<float> cornerArea, TriMesh.VertexDynamicTrait<float> pointArea)
        {
            TriMesh.FaceDynamicTrait<Vector3D> normal = new TriMesh.FaceDynamicTrait<Vector3D>(mesh);

            TriMesh.Vertex[] fv = new TriMesh.Vertex[3];

            // Compute normal for each face
            foreach (TriMesh.Face f in mesh.Faces)
            {
                int i = 0;
                foreach (TriMesh.Vertex v in f.Vertices)
                {
                    fv[i] = v;
                    ++i;
                }

                // Compute normal for this face
                normal[f] = (fv[2].Traits.Position - fv[1].Traits.Position).Cross(fv[0].Traits.Position - fv[2].Traits.Position);
                normal[f] = normal[f].Normalize();
                f.Traits.Normal = normal[f];
            }

            // Compute normal for each vertex
            foreach (TriMesh.HalfEdge h in  mesh.HalfEdges)
            {
                if (!h.OnBoundary)  // Ignore halfedges that don't have a face
                {
                    float weight = cornerArea[h] / pointArea[h.ToVertex];
                    h.ToVertex.Traits.Normal += weight * normal[h.Face];
                }
            }

            // Normalize normals
            foreach (TriMesh.Vertex v in mesh.Vertices)
            {
                if (Math.Sqrt(v.Traits.Normal.Length()) > 0.0f)    // Ignore isolated points
                {
                    v.Traits.Normal.Normalize();
                }
            }
        }