Example #1
0
        /// <summary>
        /// get uv from pyramid texture map
        /// </summary>
        /// <param name="side">side of the pyramid</param>
        /// <param name="baryCoords">point in barycentric coordinates in respect to side of the pyramid</param>
        /// <returns>uv coordinate of a point</returns>
        static Vector2 GetPyramidUVMap(PyramidSide side, Vector3 baryCoords)
        {
            var a = new Vector2(2.0f / (2 + Mathf.Sqrt(3)), 0.5f);

            switch (side)
            {
            case PyramidSide.side0:
                return(new Vector2(baryCoords.x * a.x + baryCoords.y * a.x + baryCoords.z * 1,
                                   baryCoords.x * a.y + baryCoords.y * 0.0f + baryCoords.z * (a.y / 2)));

            case PyramidSide.side1:
                return(new Vector2(baryCoords.x * a.x + baryCoords.y * 1 + baryCoords.z * 1,
                                   baryCoords.x * a.y + baryCoords.y * a.y / 2.0f + baryCoords.z * (a.y * 3.0f / 2.0f)));

            case PyramidSide.side2:
                return(new Vector2(baryCoords.x * a.x + baryCoords.y * 1 + baryCoords.z * a.x,
                                   baryCoords.x * a.y + baryCoords.y * (a.y * 3.0f / 2.0f) + baryCoords.z * 1));

            case PyramidSide.side3:
                return(new Vector2(baryCoords.x * a.x + baryCoords.y * a.x + baryCoords.z * (a.x - a.y * Mathf.Sqrt(3.0f) / 2.0f),
                                   baryCoords.x * a.y + baryCoords.y * 1 + baryCoords.z * (a.y * 3.0f / 2.0f)));

            case PyramidSide.bottom:
                return(new Vector2(baryCoords.x * a.x, baryCoords.y * a.y));
            }

            return(Vector2.zero);
        }
Example #2
0
        /// <summary>
        /// get uv from pyramid texture map
        /// </summary>
        /// <param name="side">side of the pyramid</param>
        /// <param name="baryCoords">point in barycentric coordinates in respect to side of the pyramid</param>
        /// <returns>uv coordinate of a point</returns>
        static Vector2 GetPyramidUVMap(PyramidSide side, Vector3 baryCoords)
        {
            var a = new Vector2(2.0f/(2 + Mathf.Sqrt(3)), 0.5f);

            switch (side)
            {
                case PyramidSide.side0:
                    return new Vector2(baryCoords.x*a.x + baryCoords.y*a.x + baryCoords.z*1,
                                       baryCoords.x*a.y + baryCoords.y*0.0f + baryCoords.z*(a.y/2));
                case PyramidSide.side1:
                    return new Vector2(baryCoords.x * a.x + baryCoords.y * 1 + baryCoords.z * 1,
                                       baryCoords.x * a.y + baryCoords.y * a.y / 2.0f + baryCoords.z * (a.y * 3.0f / 2.0f));
                case PyramidSide.side2:
                    return new Vector2(baryCoords.x * a.x + baryCoords.y * 1 + baryCoords.z * a.x,
                                       baryCoords.x * a.y + baryCoords.y * (a.y * 3.0f/2.0f) + baryCoords.z * 1);
                case PyramidSide.side3:
                    return new Vector2(baryCoords.x*a.x + baryCoords.y*a.x + baryCoords.z*(a.x- a.y * Mathf.Sqrt(3.0f)/2.0f),
                                       baryCoords.x*a.y + baryCoords.y*1 + baryCoords.z*(a.y*3.0f/2.0f));
                case PyramidSide.bottom:
                    return new Vector2(baryCoords.x*a.x, baryCoords.y*a.y);
            }

            return Vector2.zero;
        }