Example #1
0
    public void MeshVisualizer(Texture2D tex, CustomMesh customMesh)
    {
        MeshFilter   meshFilter   = mesh.GetComponent <MeshFilter>();
        MeshRenderer meshRenderer = mesh.GetComponent <MeshRenderer>();

        meshFilter.sharedMesh = customMesh.CreateMesh();
        meshRenderer.sharedMaterial.mainTexture = tex;
    }
Example #2
0
 public static Mesh CreateMesh(Vector3[] vertices)
 {
     int[] triangles = new int[vertices.Length];
     for (int i = 0; i < triangles.Length; i++)
     {
         triangles[i] = i;
     }
     return(CustomMesh.CreateMesh(vertices, triangles));
 }
Example #3
0
    public static Mesh Hexagon(float[] heights)
    {
        Vector3 center    = new Vector3(0, 0, 0);
        int     sideCount = 6;
        float   length    = 1f;

        Vector2[] points = new Vector2[sideCount];
        float     deg    = 360f / (float)sideCount;

        for (int i = 0; i < points.Length; i++)
        {
            float radians = (float)i * deg * Mathf.Deg2Rad;
            float x       = length * Mathf.Sin(radians);
            float y       = length * Mathf.Cos(radians);
            points[i] = new Vector2(x, y);
        }

        Mesh hex = CustomMesh.CreateMesh(
            new Vector3[] {
            center,
            new Vector3(points[0].x, heights[0], points[0].y),
            new Vector3(points[1].x, heights[1], points[1].y),

            center,
            new Vector3(points[1].x, heights[1], points[1].y),
            new Vector3(points[2].x, heights[2], points[2].y),

            center,
            new Vector3(points[2].x, heights[2], points[2].y),
            new Vector3(points[3].x, heights[3], points[3].y),

            center,
            new Vector3(points[3].x, heights[3], points[3].y),
            new Vector3(points[4].x, heights[4], points[4].y),

            center,
            new Vector3(points[4].x, heights[4], points[4].y),
            new Vector3(points[5].x, heights[5], points[5].y),

            center,
            new Vector3(points[5].x, heights[5], points[5].y),
            new Vector3(points[0].x, heights[0], points[0].y)
        },
            new int[] {
            0, 1, 2,
            3, 4, 5,
            6, 7, 8,
            9, 10, 11,
            12, 13, 14,
            15, 16, 17
        }
            );

        return(hex);
    }
Example #4
0
    public static Mesh Oil()
    {
        float half = 0.5f;

        return(CustomMesh.CreateMesh(
                   new Vector3[] {
            new Vector3(0, 0, half),
            new Vector3(-1, 0, -1),
            new Vector3(1, 0, -1)
        },
                   new int[3] {
            2, 1, 0
        }
                   ));
    }
Example #5
0
    public static Mesh Step(float width)
    {
        float halfWidth = width * 0.5f;
        float length    = 1f;

        return(CustomMesh.CreateMesh(
                   new Vector3[] {
            new Vector3(0, 0, 0),
            new Vector3(halfWidth, 0, length),
            new Vector3(-halfWidth, 0, length)
        },
                   new int[3] {
            2, 1, 0
        }
                   ));
    }
Example #6
0
    void Start()
    {
        Ring[] rings = CreateRingsOnHelix();

        Vector3[] vs    = new Vector3[rings.Length * (ringSideCount * 2) * 3];
        int       count = 0;

        for (int i = 0; i < rings.Length - 1; i++)
        {
            Vector3[] points  = rings[i].GetRingPoints();
            Vector3[] points2 = rings[i + 1].GetRingPoints();

            for (int j = 0; j < ringSideCount - 1; j++)
            {
                vs[count]     = points2[j];
                vs[count + 1] = points[j + 1];
                vs[count + 2] = points[j];

                vs[count + 3] = points2[j];
                vs[count + 4] = points2[j + 1];
                vs[count + 5] = points[j + 1];

                count += 6;
            }

            vs[count]     = points2[ringSideCount - 1];
            vs[count + 1] = points[0];
            vs[count + 2] = points[ringSideCount - 1];

            vs[count + 3] = points2[ringSideCount - 1];
            vs[count + 4] = points2[0];
            vs[count + 5] = points[0];

            count += 6;
        }

        Mesh helixTerrain = CustomMesh.CreateMesh(vs);

        CustomMeshObject c = Instantiate(cmo, Vector3.zero, Quaternion.identity) as CustomMeshObject;

        c.Init(helixTerrain, Color.green, true);

        CustomMeshObject c2 = Instantiate(cmo, Vector3.zero, Quaternion.identity) as CustomMeshObject;

        c2.Init(helixTerrain, Color.white, true);
        c2.transform.SetLocalEulerAnglesY(180f);
    }