void Awake()
    {
        if (cam == null)
        {
            cam = Camera.main;
        }

        gamePlane     = new Plane(Vector3.up, 0);
        frustumPlanes = new Plane[6];

        dataExtents = new Extents(16, 4, 16);
        dataVolume1 = new DataVolume(dataExtents);
        FillData1(dataVolume1);

        dataVolume2 = new DataVolume(dataExtents);
        FillData2(dataVolume2);

        var info = Chunk.CreateInfo(palette, cellSize, groundHeightMap, groundMaxHeight, ground, grass, water, rock);

        int length = colNum * rowNum;

        chunks = new Chunk[length];
        for (int row = 0; row < rowNum; ++row)
        {
            for (int col = 0; col < colNum; ++col)
            {
                int        i    = row * colNum + col;
                DataVolume data = (col + row) % 2 == 0 ? dataVolume1 : dataVolume2;
                chunks[i] = new Chunk(new float3(col * sideSize, 0, row * sideSize), transform, data, info);
            }
        }

        for (int row = 0; row < rowNum; ++row)
        {
            for (int col = 0; col < colNum; ++col)
            {
                int   i     = row * colNum + col;
                Chunk chunk = chunks[i];

                SetAdjacent(chunk, col, row, -1, -1);
                SetAdjacent(chunk, col, row, 0, -1);
                SetAdjacent(chunk, col, row, 1, -1);
                SetAdjacent(chunk, col, row, -1, 0);
                SetAdjacent(chunk, col, row, 1, 0);
                SetAdjacent(chunk, col, row, -1, 1);
                SetAdjacent(chunk, col, row, 0, 1);
                SetAdjacent(chunk, col, row, 1, 1);

                chunk.StartBuilding();
            }
        }

        StartCoroutine(CompleteMesh());
    }
예제 #2
0
    void Awake()
    {
        dataExtents = new Extents(16, 1, 16);
        dataVolume  = new DataVolume(dataExtents);
        FillData(dataVolume);

        mesh = new Mesh();

        mesher = new TileMesher2D();
        mesher.Init(dataVolume, 0, FillValue, theme, new float3(1, 1, 1));
        mesher.Start();
    }
    void Awake()
    {
        dataExtents = new Extents(16, 4, 16);
        dataVolume1 = new DataVolume(dataExtents);
        FillData1(dataVolume1);

        dataVolume2 = new DataVolume(dataExtents);
        FillData2(dataVolume2);

        var info = Chunk.CreateInfo(palette, cellSize, groundHeightMap, groundMaxHeight, ground, grass, water, rock);

        float offset = 2f;

        chunks    = new Chunk[4];
        chunks[0] = new Chunk(new float3(0, 0, 0), new float3(0 - offset, 0, 0 - offset), transform, dataVolume1, info);
        chunks[1] = new Chunk(new float3(0, 0, 16), new float3(0 - offset, 0, 16 + offset), transform, dataVolume2, info);
        chunks[2] = new Chunk(new float3(16, 0, 0), new float3(16 + offset, 0, 0 - offset), transform, dataVolume2, info);
        chunks[3] = new Chunk(new float3(16, 0, 16), new float3(16 + offset, 0, 16 + offset), transform, dataVolume1, info);

        foreach (var chunk in chunks)
        {
            foreach (var adj in chunks)
            {
                if (chunk == adj)
                {
                    continue;
                }

                byte dir = 0;
                if (adj.Position.x > chunk.Position.x)
                {
                    dir |= (byte)Dir.XPlus;
                }
                if (adj.Position.x < chunk.Position.x)
                {
                    dir |= (byte)Dir.XMinus;
                }
                if (adj.Position.z > chunk.Position.z)
                {
                    dir |= (byte)Dir.ZPlus;
                }
                if (adj.Position.z < chunk.Position.z)
                {
                    dir |= (byte)Dir.ZMinus;
                }
                chunk.SetAdjacent(adj.Data, dir);
            }
            chunk.StartBuilding();
        }

        StartCoroutine(CompleteMesh());
    }
예제 #4
0
    void Awake()
    {
        dataExtents = new Extents(16, 8, 16);
        dataVolume  = new DataVolume(dataExtents);
        FillData(dataVolume);

        mesh = new Mesh();

        mesher = new TileMesher3D();
        mesher.Init(dataVolume, FillValue, theme, cellSize);
        mesher.Start();

        StartCoroutine(CompleteMesh());
    }
    void Awake()
    {
        drawerComponent = GetComponent <MeshBuilderDrawerComponent>();

        dataExtents = new Extents(16, 4, 16);
        dataVolume  = new DataVolume(dataExtents);
        FillData(dataVolume);

        var groundMesher = new TileMesher3D();

        groundMesher.Init(dataVolume, 0, palette, cellSize,
                          new TileMesher3D.Settings()
        {
            filledBoundaries = Tile.Direction.None,
            skipDirections   = Tile.Direction.YAxis,
        });
        Add(groundMesher, ground);
        if (useGroundNormalAlignment)
        {
            //       builders[builders.Count - 1].AddAligner(cellSize);
        }

        var topGroundMesher = new GridMesher();

        topGroundMesher.Init(dataVolume, GroundIndex, cellSize, 3, GridMesher.UVMode.Normalized);
        topGroundMesher.InitHeightMapScaleFromHeightAvgOffset(groundHeightMap, groundMaxHeight);
        Add(topGroundMesher, grass);

        var waterMesher = new GridMesher();

        waterMesher.Init(dataVolume, WaterIndex, cellSize, 1, GridMesher.UVMode.NoScaling, new float3(0, -0.2f, 0));
        Add(waterMesher, water);

        var rockMesher = new TileMesher3D();

        rockMesher.Init(dataVolume, 1, palette, cellSize);
        Add(rockMesher, rock);

        foreach (var drawer in drawerComponent.Drawers)
        {
            drawer.StartBuilder();
        }

        StartCoroutine(CompleteMesh());
    }
    void Awake()
    {
        builders = new List <BuiltMesh>();

        dataExtents = new Extents(16, 4, 16);
        dataVolume  = new DataVolume(dataExtents);
        FillData(dataVolume);

        var groundMesher = new TileMesher3D();

        groundMesher.Init(dataVolume, 0, palette, cellSize,
                          new TileMesher3D.Settings()
        {
            filledBoundaries = Tile.Direction.None,
            skipDirections   = Tile.Direction.YAxis,
        });
        Add(groundMesher, groundMeshFilter);
        if (useGroundNormalAlignment)
        {
            builders[builders.Count - 1].AddAligner(cellSize);
        }

        var topGroundMesher = new GridMesher();

        topGroundMesher.Init(dataVolume, GroundIndex, cellSize, 3, GridMesher.UVMode.Normalized);
        topGroundMesher.InitHeightMapScaleFromHeightAvgOffset(groundHeightMap, groundMaxHeight);
        Add(topGroundMesher, groundTopMeshFilter);

        var waterMesher = new GridMesher();

        waterMesher.Init(dataVolume, WaterIndex, cellSize, 1, GridMesher.UVMode.NoScaling, new float3(0, -0.2f, 0));
        Add(waterMesher, waterMeshFilter);

        foreach (var built in builders)
        {
            built.Start();
        }

        targetGrid = new LatticeGridComponent.VertexGrid(startGrid.Grid);

        groundModifier = new LatticeGridModifier();
        grassModifier  = new LatticeGridModifier();
    }
예제 #7
0
    void Awake()
    {
        drawerComponent = GetComponent <MeshBuilderDrawerComponent>();

        dataExtents = new Extents(16, 4, 16);
        dataVolume  = new DataVolume(dataExtents);
        FillData(dataVolume);

        var walkwayMesher = new TileMesher2D();

        walkwayMesher.Init(dataVolume, 0, WalkwayFill, walkwayTheme, cellSize, new TileMesher2D.Settings {
            centerRandomRotation = true
        });
        Add(walkwayMesher, walkway);

        var walkwayBgMesher = new GridMesher();

        walkwayBgMesher.Init(dataVolume, WalkwayFill, cellSize, 3, GridMesher.UVMode.Normalized, new float3(0, -1f, 0));
        walkwayBgMesher.InitHeightMapScaleFromHeightAvgOffset(groundHeightMap, groundMaxHeight);
        Add(walkwayBgMesher, walkwayBg);

        var waterMesher = new GridMesher();

        waterMesher.Init(dataVolume, WaterFill, cellSize, 1, GridMesher.UVMode.NoScaling, new float3(0, -1.2f, 0));
        Add(waterMesher, water);

        var wallMesher = new TileMesher2D();

        wallMesher.Init(dataVolume, 0, WallFill, wallTheme, cellSize, new TileMesher2D.Settings()
        {
            emptyBoundaries = Tile.Direction.None
        });
        Add(wallMesher, wall);

        foreach (var drawer in drawerComponent.Drawers)
        {
            drawer.StartBuilder();
        }
    }
예제 #8
0
 public bool DoesSizeMatch(Extents e)
 {
     return(DoesSizeMatch(e.X, e.Y, e.Z));
 }
예제 #9
0
 public TileDataArray(Extents e)
 {
     extents = e;
     data    = new TileData[e.X * e.Y * e.Z];
 }
예제 #10
0
 public TileDataArray(int x, int y, int z)
 {
     extents = new Extents(x, y, z);
     data    = new TileData[x * y * z];
 }
예제 #11
0
            public JobHandle StartGeneration(MeshData meshData, float uScale, float vScale, int cellResolution, Extents dataExtent, NativeArray <GridCell> gridCells, NativeArray <int> borderIndices, JobHandle lastHandle)
            {
                if (HeightMap != null && (scaleMode != ScaleMode.Manual || offsetMode != OffsetMode.Manual))
                {
                    int imgWidth  = HeightMap.width;
                    int imgHeight = HeightMap.height;

                    tempHeightMapColors = new NativeArray <Color32>(HeightMap.GetPixels32(), Allocator.TempJob);

                    tempHeightMapMin = new NativeArray <byte>(imgHeight, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                    tempHeightMapAvg = new NativeArray <byte>(imgHeight, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
                    tempHeightMapMax = new NativeArray <byte>(imgHeight, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);


                    var heightMapJob = new CalcHeightMapInfoJob
                    {
                        heightmapWidth = imgWidth,
                        colors         = tempHeightMapColors,
                        minValues      = tempHeightMapMin,
                        avgValues      = tempHeightMapAvg,
                        maxValues      = tempHeightMapMax
                    };

                    lastHandle = heightMapJob.Schedule(imgHeight, 128, lastHandle);

                    var fillHeightMapInfo = new FillHeightMapInfoJob
                    {
                        scaleMode   = scaleMode,
                        offsetMode  = offsetMode,
                        maxHeight   = maxHeight,
                        valueScale  = valueScale,
                        valueOffset = valueOffset,
                        minValues   = tempHeightMapMin,
                        avgValues   = tempHeightMapAvg,
                        maxValues   = tempHeightMapMax,
                        outValues   = values
                    };

                    lastHandle = fillHeightMapInfo.Schedule(lastHandle);

                    if (applyEdgeLerp)
                    {
                        tempHeightLerpValues = new NativeArray <float>(meshData.UVs.Length, Allocator.TempJob, NativeArrayOptions.ClearMemory);

                        var generateHeightLerpJob = new GenerateEdgeHeightLerpJob
                        {
                            cellResolution   = cellResolution,
                            volumeExtent     = dataExtent,
                            cells            = gridCells,
                            borderIndices    = borderIndices,
                            heightLerpValues = tempHeightLerpValues
                        };
                        var heightLerpHandle = generateHeightLerpJob.Schedule(gridCells.Length, 32, lastHandle);

                        lastHandle = JobHandle.CombineDependencies(lastHandle, heightLerpHandle);

                        var applyHeightmapJob = new ApplyHeightMapWithEdgeLerpJob
                        {
                            heightmapWidth       = HeightMap.width,
                            heightmapHeight      = HeightMap.height,
                            uScale               = uScale,
                            vScale               = vScale,
                            colors               = tempHeightMapColors,
                            heightValues         = values,
                            uvs                  = meshData.UVs,
                            heightEdgeLerpValues = tempHeightLerpValues,
                            vertices             = meshData.Vertices
                        };
                        lastHandle = applyHeightmapJob.Schedule(meshData.VerticesLength, 128, lastHandle);
                    }
                    else
                    {
                        var applyHeightmapJob = new ApplyHeightMapJob
                        {
                            heightmapWidth  = HeightMap.width,
                            heightmapHeight = HeightMap.height,
                            uScale          = uScale,
                            vScale          = vScale,
                            colors          = tempHeightMapColors,
                            heightValues    = values,
                            uvs             = meshData.UVs,
                            vertices        = meshData.Vertices
                        };
                        lastHandle = applyHeightmapJob.Schedule(meshData.VerticesLength, 128, lastHandle);
                    }
                }

                return(lastHandle);
            }
예제 #12
0
            static private byte FindAdjacentDirections(int x, int y, int z, NativeArray <TileData> data, int filledValue, Extents extent)
            {
                int  i   = extent.ToIndexAt(x, y, z);
                byte res = 0;

                if (x > 0 && HasTop(i - 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXMinus;
                }
                if (x < extent.X - 1 && HasTop(i + 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXPlus;
                }

                if (z > 0 && HasTop(i - extent.X, y, data, filledValue, extent))
                {
                    res |= AdjacentZMinus;
                }
                if (z < extent.Z - 1 && HasTop(i + extent.X, y, data, filledValue, extent))
                {
                    res |= AdjacentZPlus;
                }

                if (x > 0 && z > 0 && HasTop(i - extent.X - 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXMinusZMinus;
                }
                if (x > 0 && z < extent.Z - 1 && HasTop(i + extent.X - 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXMinusZPlus;
                }
                if (x < extent.X - 1 && z > 0 && HasTop(i - extent.X + 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXPlusZMinus;
                }
                if (x < extent.X - 1 && z < extent.Z - 1 && HasTop(i + extent.X + 1, y, data, filledValue, extent))
                {
                    res |= AdjacentXPlusZPlus;
                }

                return(res);
            }
예제 #13
0
 static private bool HasTop(int index, int y, NativeArray <TileData> data, int filledValue, Extents extent)
 {
     return(data[index].themeIndex == filledValue && (y == extent.Y - 1 || data[index + extent.XZ].themeIndex != filledValue));
 }
예제 #14
0
 static public int IndexFromCoord(int x, int y, int z, Extents ext)
 {
     return(y * ext.XZ + z * ext.X + x);
 }
예제 #15
0
 static public int IndexFromCoord(int3 c, Extents ext)
 {
     return(c.y * ext.XZ + c.z * ext.X + c.x);
 }
예제 #16
0
            static private bool HasTop(int x, int y, int z, NativeArray <TileData> data, int filledValue, Extents extent)
            {
                int i = extent.ToIndexAt(x, y, z);

                return(data[i].themeIndex == filledValue && (y == extent.Y - 1 || data[i + extent.XZ].themeIndex != filledValue));
            }
예제 #17
0
 public int ToIndex(int x, int y, int z)
 {
     return(Extents.IndexFromCoord(x, y, z, xLength * zLength, xLength));
 }