Пример #1
0
        /// <summary>
        /// Write a single point to buffer.
        /// </summary>
        /// <param name="srcPoint">Source point.</param>
        /// <param name="dstPlane">Destination plane buffer.</param>
        /// <implementation>
        /// Vector coordinates are divided by 256.0f, and texture coordinates by 16.0f.
        /// </implementation>
        private int WritePoint(ref FaceUVTool.DFPurePoint srcPoint, ref DFPlaneBuffer dstPlane)
        {
            // Copy point data
            int pointPos = dstPlane.PointCount;
            dstPlane.PointBuffer[pointPos].X = srcPoint.x / pointDivisor;
            dstPlane.PointBuffer[pointPos].Y = srcPoint.y / pointDivisor;
            dstPlane.PointBuffer[pointPos].Z = srcPoint.z / pointDivisor;
            dstPlane.PointBuffer[pointPos].NX = srcPoint.nx / pointDivisor;
            dstPlane.PointBuffer[pointPos].NY = srcPoint.ny / pointDivisor;
            dstPlane.PointBuffer[pointPos].NZ = srcPoint.nz / pointDivisor;
            dstPlane.PointBuffer[pointPos].U = srcPoint.u / textureDivisor;
            dstPlane.PointBuffer[pointPos].V = srcPoint.v / textureDivisor;
            dstPlane.PointCount++;

            return pointPos;
        }
Пример #2
0
        /// <summary>
        /// Find corner points from a pure face - this reduces the number of points in the final strip.
        /// </summary>
        /// <param name="pointsIn">Source points to find corners of.</param>
        /// <returns>Number of corners found in this point array.</returns>
        private int GetCornerPoints(ref FaceUVTool.DFPurePoint[] pointsIn)
        {
            int cornerCount = 0;
            Vector3 v0, v1, v2, l0, l1;
            int pointCount = pointsIn.Length;
            for (int point = 0; point < pointCount; point++)
            {
                // Determine angle between this point and next two points
                int cornerIndex;
                if (point < pointCount - 2)
                {
                    v0 = new Vector3(pointsIn[point].x, pointsIn[point].y, pointsIn[point].z);
                    v1 = new Vector3(pointsIn[point + 1].x, pointsIn[point + 1].y, pointsIn[point + 1].z);
                    v2 = new Vector3(pointsIn[point + 2].x, pointsIn[point + 2].y, pointsIn[point + 2].z);
                    cornerIndex = point + 1;
                }
                else if (point < pointCount - 1)
                {
                    v0 = new Vector3(pointsIn[point].x, pointsIn[point].y, pointsIn[point].z);
                    v1 = new Vector3(pointsIn[point + 1].x, pointsIn[point + 1].y, pointsIn[point + 1].z);
                    v2 = new Vector3(pointsIn[0].x, pointsIn[0].y, pointsIn[0].z);
                    cornerIndex = point + 1;
                }
                else
                {
                    v0 = new Vector3(pointsIn[point].x, pointsIn[point].y, pointsIn[point].z);
                    v1 = new Vector3(pointsIn[0].x, pointsIn[0].y, pointsIn[0].z);
                    v2 = new Vector3(pointsIn[1].x, pointsIn[1].y, pointsIn[1].z);
                    cornerIndex = 0;
                }

                // Construct direction vectors
                l0 = v1 - v0;
                l1 = v2 - v0;

                // Check angle between direction vectors
                double angle = l0.Angle(l1);
                if (angle > 0.001f)
                {
                    // Write corner point to buffer
                    cornerPointBuffer[cornerCount++] = cornerIndex;
                }
            }

            return cornerCount;
        }