コード例 #1
0
    private void AddVoxelIJL(IJL ijl)
    {
        if (!_sampleset.Add(ijl))
        {
            return;
        }
        IJL chunk = Vx.ChunkIJL(ijl, chunk_radius);

        if (!_chunkmap.ContainsKey(chunk))
        {
            _chunkmap.Add(chunk, new List <IJL>());
            _chunklist.Add(chunk);
        }
        _chunkmap[chunk].Add(ijl - Vx.ChunkVoxelIJL(chunk, chunk_radius));
    }
コード例 #2
0
    private void UpdateChunkMesh(IJL chunk)
    {
        if (!_chunkobjmap.ContainsKey(chunk) || !_chunkmap.ContainsKey(chunk))
        {
            return;
        }
        _data.Clear();
        _data.flat_shaded = flat_shaded;
        _data.map         = voxelstyle;
        int        cnt        = Vx.AdjBlockIJL.Length;
        IJL        chunkvoxel = Vx.ChunkVoxelIJL(chunk, chunk_radius);
        List <IJL> voxels     = _chunkmap[chunk];

        for (int k = 0; k < voxels.Count; k++)
        {
            _data.UpdateVoxelData(voxels[k], new Voxel(1), true);
            IJL voxelijl = chunkvoxel + voxels[k];
            for (int cell_index = 0; cell_index < cnt; cell_index++)
            {
                IJL adjvoxel = voxelijl + Vx.AdjBlockIJL[cell_index];
                if (Vx.ChunkIJL(adjvoxel, chunk_radius) == chunk)
                {
                    continue;
                }
                if (!_sampleset.Contains(adjvoxel))
                {
                    continue;
                }
                _data.UpdateVoxelData(voxels[k] + Vx.AdjBlockIJL[cell_index], new Voxel(1), false);
            }
        }
        _data.UpdateDirtyComponents();
        _data.GenerateMesh();

        MeshFilter filter = _chunkobjmap[chunk].GetComponent <MeshFilter>();

        if (filter.mesh == null)
        {
            filter.mesh = new Mesh();
        }
        filter.mesh.SetVertices(_data.vertices);
        filter.mesh.SetNormals(_data.normals);
        filter.mesh.SetTriangles(_data.triangles, 0);
        filter.mesh.RecalculateBounds();
        filter.mesh.RecalculateTangents();
        filter.mesh.UploadMeshData(false);
    }