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); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var job = new GenerateMeshJob { Vertices = GetBufferFromEntity <Vertex>(false), Normals = GetBufferFromEntity <Normal>(false), Tris = GetBufferFromEntity <Triangle>(false), Uvs = GetBufferFromEntity <Uv>(false), blocks = GetBufferFromEntity <BlockIDBuffer>(true), CommandBuffer = system.CreateCommandBuffer().ToConcurrent(), EntityType = GetArchetypeChunkEntityType(), meshesThisFrame = 0, ChunkEntities = Main.chunkEntities, chunk = GetComponentDataFromEntity <Chunk>(true) }; inputDeps = job.Schedule <GenerateMeshJob>(query, inputDeps); system.AddJobHandleForProducer(inputDeps); return(inputDeps); }