Example #1
0
        /// TODO: make the smooth generic with the subdivision type
        /// <summary>
        /// Smooth the vertex with loop subdivision
        /// </summary>
        /// <param name="m">Polymesh</param>
        /// <param name="vh">Vertex Handle to smooth</param>
        /// <param name="p">new position for the vertex</param>
        /// <returns>false indicates that the vertex is not in the Polymesh which can be removed</returns>
        public static bool Smooth(PolyMesh m, int vh, out Vector3 p)
        {
            p = Vector3.zero;
            if (m.IsBoundaryVertex(vh))
            {
                int heh = m.GetHalfedgeVertexH(vh), prev_heh;
                if (heh.isValidHandle())
                {
                    //Debug.Assert(m.IsBoundaryEdge(m.GetEdgeH(heh)));

                    prev_heh = m.GetPrevHalfedgeH(heh);

                    int to_vh   = m.GetEndVertexH(heh),
                        from_vh = m.GetStartVertexH(prev_heh);

                    p  = m.GetPoint(vh);
                    p *= 6.0f;
                    p += m.GetPoint(to_vh);
                    p += m.GetPoint(from_vh);
                    p *= 0.125f;
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                var vit     = m.GetVertexVertexIter(vh);
                int valence = 0;
                foreach (var vvh in vit)
                {
                    valence++;
                    p += m.GetPoint(vvh);
                }

                var w = SmoothUtils.loopWeights[valence];
                p *= w.second;
                p += m.GetPoint(vh) * w.first;
            }
            return(true);
        }