Ejemplo n.º 1
0
    void StartChunkProcessing(Chunk c)
    {
        remeshJobs.Clear();
        foreach (var chunk in chunks.Values)
        {
            if (chunk.DeferRemesh)
            {
                chunk.DisposeMeshing();

                remeshJobs.Add(TerrainMesher.StartJob(chunk, genJob));

                chunk.DeferRemesh = false;
            }
        }

        if (chunkInProcess == null && c != null)
        {
            chunkInProcess = c;

            c.DisposeMeshing();

            genJob  = TerrainGenerator.StartJob(c);
            meshJob = TerrainMesher.StartJob(c, genJob);
        }
    }
Ejemplo n.º 2
0
    public Job StartJob(Chunk c, TerrainGenerator.Job terrGen)
    {
        var j = new Job {
            chunk = c
        };

        c.SurfaceEdgePositions = new NativeList <int>(Chunk.VOXELS * Chunk.VOXELS, Allocator.Persistent);
        c.SurfaceEdges         = new NativeList <Edge>(Chunk.VOXELS * Chunk.VOXELS, Allocator.Persistent);
        c.SurfaceCells         = new NativeList <int>(Chunk.VOXELS * Chunk.VOXELS, Allocator.Persistent);
        c.Cells    = new NativeArray <Cell>(CELLS_TOTAL, Allocator.Persistent, NativeArrayOptions.ClearMemory);
        j.MeshData = new MeshData();

        var findSurface = new FindSurfaceEdgesJob {
            Voxels = c.Voxels,
        };
        var calcEdges = new CalcEdgesJob {
            Voxels = c.Voxels,
            SurfaceEdgePositions = c.SurfaceEdgePositions,

            SurfaceEdges = c.SurfaceEdges,
            SurfaceCells = c.SurfaceCells,
            Cells        = c.Cells,
        };
        var calcVertices = new CalcVerticesJob {
            DCIterStrength  = DCIterStrength,
            DCMaxIterations = DCMaxIterations,
            SurfaceEdges    = c.SurfaceEdges,
            SurfaceCells    = c.SurfaceCells,
            Voxels          = c.Voxels,

            Cells = c.Cells,
        };
        var genMesh = new GenerateMeshJob {
            SurfaceEdgePositions = c.SurfaceEdgePositions,
            SurfaceEdges         = c.SurfaceEdges,
            Cells = c.Cells,

            vertices = j.MeshData.vertices,
            normals  = j.MeshData.normals,
            //uv		  = j.MeshData.uv		,
            colors    = j.MeshData.colors,
            triangles = j.MeshData.triangles,
            materials = j.MeshData.materials,
        };

        var findSurfaceH = findSurface.ScheduleAppend(c.SurfaceEdgePositions, EDGES_TOTAL, 64, terrGen?.Handle ?? default);
        var calcEdgesH   = calcEdges.Schedule(findSurfaceH);
        var calcVertsH   = calcVertices.Schedule(c.SurfaceCells, 64, calcEdgesH);

        j.FinalJob = genMesh.Schedule(calcVertsH);
        return(j);
    }
Ejemplo n.º 3
0
    void OnDestroy()
    {
        genJob?.Complete();
        meshJob?.Complete();

        chunkInProcess = null;
        genJob         = null;
        meshJob        = null;

        foreach (var c in chunks.Values)
        {
            c.Dispose();
            Destroy(c);
        }
        chunks.Clear();
    }
Ejemplo n.º 4
0
    void FinishChunkProcessing()
    {
        foreach (var j in remeshJobs)
        {
            j.Complete();
        }

        if (chunkInProcess != null && (genJob?.IsCompleted ?? true) && (meshJob?.IsCompleted ?? true))
        {
            genJob?.Complete();
            meshJob?.Complete();
            chunkInProcess.Done = true;

            chunkInProcess = null;
            genJob         = null;
            meshJob        = null;
        }
    }