Пример #1
0
 // mesh-г tf-р хувиргана
 public static void UpdTf(ref Mesh mesh, Tf tf)
 {
     Vector3[] vs = mesh.vertices.Cln();
     Vector3[] ns = mesh.normals.Cln();
     for (int i = 0; i < vs.Length; i++)
     {
         vs[i] = Tf.Rot(tf.r, V3.Mul(vs[i], tf.s)) + tf.t;
         ns[i] = Tf.Rot(tf.r, ns[i]).normalized;
     }
     mesh.vertices = vs;
     mesh.normals  = ns;
 }
Пример #2
0
    ///<summary>mesh-р эргэлтийн бие үүсгэнэ</summary>
    public static void RotModel(ref Mesh mesh, bool isFill, bool isDisUv, int n, List <Vector2> points, Tf tf)
    {
        List <Vector2> lis = new List <Vector2>(points);

        if (isFill)
        {
            lis.Insert(0, V2.X(points[0], 0));
            lis.Add(V2.X(points[points.Count - 1], 0));
        }
        // vertices
        Vector3[] vs   = new Vector3[n * lis.Count];
        float     dAng = 360f / n;

        for (int i = 0; i < lis.Count; i++)
        {
            for (int j = 0; j < n; j++)
            {
                vs[i * n + j] = Tf.Rot(tf.r, V3.Mul(new Vector3(lis[i].x * M.Cos(j * dAng), lis[i].y, lis[i].x * M.Sin(j * dAng)), tf.s)) + tf.t;
            }
        }
        // triangles
        int[] ts = new int[n * 6 * (lis.Count - 1)];
        for (int i = 0; i < lis.Count - 1; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < 6; k++)
                {
                    ts[n * 6 * i + j * 6 + k] = n * i + (j + UvUArr[k]) % n + UvVArr[k] * n;
                }
            }
        }
        // uv
        Vector3[] v = new Vector3[ts.Length];
        int[]     t = new int[ts.Length];
        Vector2[] uv = new Vector2[ts.Length];
        float     du = 1f / n, dv = 1f / (lis.Count - 1);

        if (isDisUv)
        {
            float        dis = 0, tmpDis, curDis = 0;
            List <float> disLis = new List <float>();
            for (int i = 1; i < lis.Count; i++)
            {
                tmpDis = Vector3.Distance(lis[i - 1], lis[i]);
                disLis.Add(tmpDis);
                dis += tmpDis;
            }
            for (int i = 0; i < ts.Length; i++)
            {
                v[i]  = vs[ts[i]];
                t[i]  = i;
                uv[i] = new Vector2(
                    (i / 6 % n + UvUArr[i % 6]) * du,
                    (curDis + UvVArr[i % 6] * disLis[i / 6 / n]) / dis
                    );
                if ((i + 1) % (6 * n) == 0)
                {
                    curDis += disLis[i / 6 / n];
                }
            }
        }
        else
        {
            for (int i = 0; i < ts.Length; i++)
            {
                v[i]  = vs[ts[i]];
                t[i]  = i;
                uv[i] = new Vector2(
                    (i / 6 % n + UvUArr[i % 6]) * du,
                    (i / 6 / n + UvVArr[i % 6]) * dv
                    );
            }
        }
        // mesh
        VsTsUvRn(ref mesh, vs, ts, uv);
    }