コード例 #1
0
        public void AddImage(float w, float h, string texturename, float stx, float sty, float dx, float dy)
        {
            NamedTextureElement tbi = new NamedTextureElement {
                width = w, height = h, texturename = texturename
            };

            tbi.UVstartx = stx;
            tbi.UVstarty = sty;
            tbi.UVwidth  = dx;
            tbi.UVheight = dy;
            AppendSpecialChar(tbi);
            //tm.gameObject.renderer.sharedMaterials[int.Parse(texturename)].mainTexture));
        }
コード例 #2
0
 public void AddImage(float w, float h,string texturename, float stx,float sty,float dx, float dy)
 {
     NamedTextureElement tbi=new NamedTextureElement {width=w,height=h,texturename=texturename};
     tbi.UVstartx=stx;
     tbi.UVstarty=sty;
     tbi.UVwidth=dx;
     tbi.UVheight=dy;
     AppendSpecialChar(tbi);
     //tm.gameObject.renderer.sharedMaterials[int.Parse(texturename)].mainTexture));
 }
コード例 #3
0
        /// <summary>
        /// Compute the UV map for a specific mesh
        /// </summary>
        /// <param name='mesh'>
        /// Mesh.
        /// </param>
        /// <param name='uvType'>
        /// Uv type.
        /// </param>
        /// <param name='normalized'>
        /// Normalized.
        /// </param>
        /// <param name='uvscale'>
        /// Uvscale.
        /// </param>
        /// <param name='charmetadata'>
        /// Charmetadata.
        /// </param>
        public static void ComputeUVs2(Mesh mesh, TTFText.UVTypeEnum uvType, bool normalized, Vector3 uvscale, object charmetadata)
        {
            mesh.RecalculateBounds();
            Bounds b = mesh.bounds;
            //Vector3 e = b.extents;
            Vector3 e     = b.size;
            Vector3 c     = b.center;
            Vector3 invse = new Vector3(
                (e.x != 0) ? (1f / e.x) : 1f,
                (e.y != 0) ? (1f / e.y) : 1f,
                (e.z != 0) ? (1f / e.z) : 1f
                );

            //Debug.Log(invse);
            Vector3[] vertices = mesh.vertices;

            Vector2[] uvs = new Vector2[vertices.Length];

            Vector3 a;

            if (vertices.Length == 0)
            {
                return;
            }



            if ((charmetadata != null))
            {
                if (((charmetadata as NamedTextureElement) != null))
                {
                    NamedTextureElement tbi = (charmetadata as NamedTextureElement);
                    for (int i = 0; i < vertices.Length; ++i)
                    {
                        //Debug.Log(vertices [i]-b.min);
                        a        = Vector3.Scale(vertices [i] - b.min, invse);
                        uvs[i].x = tbi.UVstartx + (a.x * tbi.UVwidth);
                        uvs[i].y = tbi.UVstarty + (a.y * tbi.UVheight);
                    }
                }
                if (((charmetadata as TextureElement) != null))
                {
                    TextureElement tbi = (charmetadata as TextureElement);
                    for (int i = 0; i < vertices.Length; ++i)
                    {
                        a = Vector3.Scale(vertices [i] - b.min, invse);
                        //Debug.Log(a);
                        uvs [i].x = tbi.UVstartx + a.x * tbi.UVwidth;
                        uvs [i].y = tbi.UVstarty + a.y * tbi.UVheight;
                    }
                }
            }
            else
            {
                for (int i = 0; i < vertices.Length; ++i)
                {
                    if (uvType == TTFText.UVTypeEnum.Box)
                    {
                        a = vertices [i];
                        if (normalized)
                        {
                            a = Vector3.Scale(vertices [i], invse);
                        }
                    }
                    else         // Spherical
                    {
                        a  = Quaternion.FromToRotation(Vector3.forward, vertices [i] - c).eulerAngles;
                        a /= 360;        //(Mathf.PI*2);
                    }

                    uvs [i].x = (uvscale.x * a.x + uvscale.z * a.z);
                    uvs [i].y = (uvscale.y * a.y + uvscale.z * a.z);
                }
            }

            mesh.uv = uvs;
        }