示例#1
0
        /// Compute corner normals based on polygon normal and point location attributes
        /// Results are stored in internally stored attribute map named "corner_normals".
        public void SmoothNormalize(
            string cornerAttribute,
            string polygonAttribute,
            float maxSmoothingAngleRadians
            )
        {
            var cornerAttributes  = CornerAttributes.FindOrCreate <Vector3>(cornerAttribute /*"corner_normals"*/);
            var polygonAttributes = PolygonAttributes.Find <Vector3>(polygonAttribute /*"polygon_normals"*/);
            var polygonNormals    = PolygonAttributes.Find <Vector3>("polygon_normals");

            float cosMaxSmoothingAngle = (float)System.Math.Cos((double)maxSmoothingAngleRadians);

            cornerAttributes.Clear();
            foreach (Polygon polygon in Polygons)
            {
                if (maxSmoothingAngleRadians == 0)
                {
                    polygon.CopyToCorners(
                        cornerAttributes,
                        polygonAttributes
                        );
                }
                else
                {
                    polygon.SmoothNormalize(
                        cornerAttributes,
                        polygonAttributes,
                        polygonNormals,
                        cosMaxSmoothingAngle
                        );
                }
            }
        }
示例#2
0
        public Vector3 ComputePointNormal(Point point)
        {
            var polygonNormals = PolygonAttributes.Find <Vector3>("polygon_normals");

            Vector3 normalSum = new Vector3(0.0f, 0.0f, 0.0f);

            foreach (Corner corner in point.Corners)
            {
                normalSum += polygonNormals[corner.Polygon];
            }
            Vector3 averageNormal = normalSum / (float)point.Corners.Count;

            return(averageNormal);
        }
示例#3
0
        public void ComputePointNormals(string mapName)
        {
            var pointNormals   = PointAttributes.FindOrCreate <Vector3>(mapName);
            var polygonNormals = PolygonAttributes.Find <Vector3>("polygon_normals");

            pointNormals.Clear();
            foreach (Point point in Points)
            {
                Vector3 normalSum = new Vector3(0.0f, 0.0f, 0.0f);
                foreach (Corner corner in point.Corners)
                {
                    normalSum += polygonNormals[corner.Polygon];
                }
                Vector3 averageNormal = normalSum / (float)point.Corners.Count;
                pointNormals[point] = averageNormal;
            }
        }