Ejemplo n.º 1
0
    Entity CreateSectorEntity(int2 cellIndex)
    {
        Entity sectorEntity = entityManager.CreateEntity(sectorArchetype);

        entityManager.AddComponentData <WorleyNoise.CellData>(sectorEntity, worley.GetCellData(cellIndex));
        TryAddSector(sectorEntity, cellIndex);

        return(sectorEntity);
    }
        WorleyDatas GetWorleyDatas()
        {
            WorleyNoise worley = GetWorleyGenerator();

            float3 randomPosition = Random().NextFloat3();

            WorleyNoise.CellData cellFromIndex;
            WorleyNoise.CellData cellFromPosition;

            cellFromPosition = worley.GetCellData(randomPosition);
            cellFromIndex    = worley.GetCellData(cellFromPosition.index);

            return(new WorleyDatas(cellFromIndex, cellFromPosition));
        }
Ejemplo n.º 3
0
    public WorleyNoise.CellData RandomCellData(WorleyNoise cellWorley)
    {
        int x = UnityEngine.Random.Range(-500, 500);
        int z = UnityEngine.Random.Range(-500, 500);

        return(cellWorley.GetCellData(new int2(x, z)));
    }
Ejemplo n.º 4
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();
    }
Ejemplo n.º 5
0
        float GetOrGenerateCellGrouping(int2 index)
        {
            if (cellMatrix.ItemIsSet(index))
            {
                return(cellMatrix.GetItem(index).grouping);
            }

            var cell = new CellSystem.CellMatrixItem
                       (
                worley.GetCellData(index),
                topologyUtil.CellGrouping(index),
                topologyUtil.CellHeight(index)
                       );

            cellMatrix.AddItem(cell, index);
            return(cell.grouping);
        }
Ejemplo n.º 6
0
        public void PointData_matches_CellData()
        {
            WorleyNoise.PointData randomPoint = testUtil.RandomPointData(cellWorley);
            WorleyNoise.CellData  cell        = cellWorley.GetCellData(randomPoint.currentCellIndex);

            Assert.IsTrue(
                randomPoint.currentCellPosition.Equals(cell.position),
                "Position\n" + "PointData: " + randomPoint.currentCellPosition + '\n' + "CellData: " + cell.position
                );
            Assert.IsTrue(
                randomPoint.currentCellIndex.Equals(cell.index),
                "Index\n" + "PointData: " + randomPoint.currentCellIndex + '\n' + "CellData: " + cell.index
                );
            Assert.IsTrue(
                randomPoint.currentCellValue.Equals(cell.value),
                "Value\n" + "PointData: " + randomPoint.currentCellValue + '\n' + "CellData: " + cell.value
                );
        }
Ejemplo n.º 7
0
    void DebugWorley(int range)
    {
        for (int x = -range; x < range; x++)
        {
            for (int z = -range; z < range; z++)
            {
                /*float xf = 0.1f * ( (float)math.abs(x) / range );
                 * float zf = 0.1f * ( (float)math.abs(z) / range ); */

                float dist2Edge;
                WorleyNoise.CellData cell = worley.GetCellData(x, z, out dist2Edge);

                float colorFloat = cell.value;
                Color color      = new Color(colorFloat /* + dist2Edge */, colorFloat, colorFloat, 1);

                CreateCube(new float3(x, 0, z), color);
            }
        }
    }