3D轮播展示图片

这两天做了个很有意思的小玩意儿~
完整代码下载链接
平面轮播方式展示图片显得很单调,立体效果的果然好很多~

1.球状展示:
在这里插入图片描述
2.螺旋状展示:
在这里插入图片描述

3.文字或字母形式展示:
在这里插入图片描述
做字母或文字形式展示的时候一开始没有思路,后来想到了用白底带色彩字母或文字图片,识别图像中像素rgb值区分前景和背景,之后遍历每行每列(取合适的步长),将字母或文字像素位置映射到世界空间,再用图片进行填充。
文字或字母像素位置映射到世界空间代码如下:
注意行列合适步长的选取。

   List<Vector3> GetWordPosByTexture(Texture2D texture)
    {
    
    
        List<Vector3> posList = new List<Vector3>();
        int num = 0;
        if (texture != null)
        {
    
    
            int width = texture.width;
            int height = texture.height;
            Color[] colors = texture.GetPixels();
            int index;
            for (int i = 0; i < height; i += wordHeightStep)
            {
    
    
                for (int j = 0; j < width; j += wordWidthStep)
                {
    
    
                    index = i * width + j;
                    if (nearBlack(colors[index]))
                    {
    
    
                        num++;
                        Vector3 itemPos = new Vector3();
                        itemPos.x = width-j-(width/2);
                        itemPos.y = -(height-i-(height/2));
                        itemPos.z = 0;
                        posList.Add(itemPos);
                    }
                }
            }
            Debug.Log("wordPoint:" + num);
        }
        return posList;
    }
    bool nearBlack(Color color)
    {
    
    
        if (color.r < 0.8f || color.g <0.8f || color.b < 0.8f)
            return true;
        else
            return false;
    }
``

猜你喜欢

转载自blog.csdn.net/l17768346260/article/details/105032134