WorleyNoise.CellProfile GetRandomCell()
        {
            WorleyNoise worley = GetWorleyNoise();
            Random      random = Random();

            return(worley.GetCellProfile(random.NextInt2(-100, 100)));
        }
Esempio n. 2
0
    public void Generate(int2 cellIndex)
    {
        parentCell = worley.GetCellProfile(cellIndex);

        vertices  = new NativeList <float3>(Allocator.Temp);
        triangles = new NativeList <int>(Allocator.Temp);

        random = new Unity.Mathematics.Random((uint)(parentCell.data.value * 1000));

        leaves = new Leaves(vertices, triangles);
        trunk  = new Trunk(vertices, triangles, random);

        baseHeight = simplex.GetSimplex(parentCell.data.position.x, parentCell.data.position.z) * 15;

        DrawChildCells(worley.frequency * 2);
        //leaves.Draw(parentCellProfile, 0);

        trunk.DrawTrunk(parentCell);

        DrawCellSegments(parentCell);
        DrawCellLines(parentCell);

        MakeMesh();

        vertices.Dispose();
        triangles.Dispose();
    }
Esempio n. 3
0
    void DrawChildCells(float2 frequency)
    {
        WorleyNoise childWorley = worley;

        childWorley.frequency = frequency;

        float3 meanPointWorld = parentCell.data.position + vectorUtil.MeanPoint(parentCell.vertices);

        WorleyNoise.CellData startChild = childWorley.GetCellData(meanPointWorld);

        var checkNext      = new NativeQueue <WorleyNoise.CellData>(Allocator.Temp);
        var alreadyChecked = new NativeList <int2>(Allocator.Temp);

        checkNext.Enqueue(startChild);
        alreadyChecked.Add(startChild.index);

        var children = new NativeList <WorleyNoise.CellProfile>(Allocator.Temp);

        while (checkNext.Count > 0)
        {
            WorleyNoise.CellData childData = checkNext.Dequeue();

            WorleyNoise.CellData dataFromParent = worley.GetCellData(childData.position);
            bool childIsInParent = dataFromParent.index.Equals(parentCell.data.index);

            if (!childIsInParent)
            {
                continue;
            }

            WorleyNoise.CellProfile childProfile = childWorley.GetCellProfile(childData);
            float3 positionInParent = childProfile.data.position - parentCell.data.position;
            positionInParent.y += baseHeight;

            leaves.Draw(childProfile, positionInParent);

            children.Add(childProfile);

            for (int i = 0; i < childProfile.vertices.Length; i++)
            {
                WorleyNoise.CellData adjacent = childProfile.adjacentCells[i].c0;
                if (!alreadyChecked.Contains(adjacent.index))
                {
                    checkNext.Enqueue(adjacent);
                    alreadyChecked.Add(adjacent.index);
                }
            }
        }

        checkNext.Dispose();
        alreadyChecked.Dispose();
    }