Ejemplo n.º 1
0
    IEnumerator UpdateMesh()
    {
        if (Updating)
        {
            yield break;
        }

        if (!generator.CanUpdate)
        {
            yield break;
        }

        generator.UpdatingChunks++;

        int3 chunkSizeInt3 = VoxelUtil.ToInt3(chunkSize);

        List <Voxel[]> neighborVoxels = generator.GetNeighborVoxels(chunkPosition, 1);

        lightData?.Dispose();
        lightData = new VoxelLightBuilder.NativeLightData(chunkSizeInt3);
        yield return(lightData.ScheduleLightingJob(neighborVoxels, VoxelUtil.ToInt3(chunkPosition), chunkSizeInt3, 1, argent));

        meshData?.Dispose();
        meshData = new VoxelMeshBuilder.NativeMeshData(VoxelUtil.ToInt3(chunkSize));
        yield return(meshData.ScheduleMeshingJob(voxels, lightData, VoxelUtil.ToInt3(chunkSize), generator.SimplifyingMethod, argent));

        meshData.GetMeshInformation(out int verticeSize, out int indicesSize);

        if (verticeSize > 0 && indicesSize > 0)
        {
            mesh.Clear();
            mesh.SetVertices(meshData.nativeVertices, 0, verticeSize);
            mesh.SetNormals(meshData.nativeNormals, 0, verticeSize);
            mesh.SetColors(meshData.nativeColors, 0, verticeSize);
            mesh.SetUVs(0, meshData.nativeUVs, 0, verticeSize);
            mesh.SetIndices(meshData.nativeIndices, 0, indicesSize, MeshTopology.Triangles, 0);

            mesh.RecalculateNormals();
            mesh.RecalculateBounds();

            if (argent)
            {
                SetSharedMesh(mesh);
            }
            else
            {
                VoxelColliderBuilder.Instance.Enqueue(this, mesh);
            }
        }

        lightData.Dispose();
        meshData.Dispose();
        dirty            = false;
        argent           = false;
        gameObject.layer = LayerMask.NameToLayer("Voxel");
        meshUpdator      = null;
        generator.UpdatingChunks--;
    }
    public void UpdateMesh()
    {
        if (dirty == false)
        {
            return;
        }

        meshData?.Dispose();
        meshData = new VoxelMeshBuilder.NativeMeshData(generator.ChunkSize);
        meshData.ScheduleMeshingJob(voxels, generator.ChunkSize, generator.SimplifyingMethod);

        isUpdating = true;
        dirty      = false;
    }