private void GenerateMesh()
    {
        //Generate the points.
        var   verts           = new PolyShape.Point[NPoints];
        float radianIncrement = Mathf.PI * -2.0f / NPoints;
        float minDist         = Radius - Variance,
              maxDist         = Radius + Variance;

        for (int i = 0; i < verts.Length; ++i)
        {
            float   radians = i * radianIncrement;
            Vector2 pos     = new Vector2(Mathf.Cos(radians),
                                          Mathf.Sin(radians));
            pos *= Mathf.Lerp(minDist, maxDist, UnityEngine.Random.value);

            verts[i] = new PolyShape.Point(pos, 1.0f);
        }
        shape = new PolyShape(verts);

        Vector3[] verts3 = null;
        int[]     tris   = null;
        shape.Triangulate(ref verts3, ref tris);

        var mf = GetComponent <MeshFilter>();

        if (mf.mesh == null)
        {
            mf.mesh = new Mesh();
        }
        mf.mesh.vertices  = verts3;
        mf.mesh.triangles = tris;
        mf.mesh.UploadMeshData(false);
    }
    private void GenerateShape()
    {
        //Generate the points.
        PolyShape.Point[] verts           = new PolyShape.Point[NPoints];
        float             radianIncrement = Mathf.PI * -2.0f / NPoints;
        float             minDist         = Radius - Variance,
                          maxDist = Radius + Variance;

        for (int i = 0; i < verts.Length; ++i)
        {
            float   radians = i * radianIncrement;
            Vector2 pos     = new Vector2(Mathf.Cos(radians),
                                          Mathf.Sin(radians));
            pos *= Mathf.Lerp(minDist, maxDist, UnityEngine.Random.value);

            verts[i] = new PolyShape.Point(pos, 1.0f);
        }
        shape = new PolyShape(verts);
    }
Exemple #3
0
    /// <summary>
    /// Generates a new InstanceShape value based off the BaseShape.
    /// </summary>
    /// <param name="render">
    /// If true, this instance shape will immediately be rendered to "RenderedShape".
    /// </param>
    /// <param name="renderInto">
    /// If "render" is true, this is the texture that will be rendered into.
    /// Pass null to render into "RenderedShape".
    /// </param>
    public void GenerateInstanceBlotch(bool render = true, RenderTexture renderInto = null)
    {
        Update();

        UnityEngine.Assertions.Assert.IsNotNull(BaseShape, "Didn't generate a base shape first!");

        //Make a copy of the base shape.
        var points = new PolyShape.Point[BaseShape.NPoints];

        for (int i = 0; i < points.Length; ++i)
        {
            points[i] = new PolyShape.Point(BaseShape.GetPoint(i), baseShape.GetVariance(i));
        }
        InstanceShape = new PolyShape(points);

        Subdivide(InstanceShape,
                  InitialBlotchIterations,
                  InitialBlotchIterations + ExtraBlotchIterations - 1);

        if (render)
        {
            Render(InstanceShape, renderInto == null ? RenderedShape : renderInto);
        }
    }