Exemplo n.º 1
0
        public void GenerateMesh(IVoxelDataSource <VoxelData> data, Bounds cellSize, out SimpleMesh mesh)
        {
            mesh = new SimpleMesh();
            mesh.RenderMaterial = Game.BlockRegistry.AtlasMaterial;

            int xvol = (int)cellSize.size.x;
            int yvol = (int)cellSize.size.y;
            int zvol = (int)cellSize.size.y;

            int xoff = (int)cellSize.min.x;
            int yoff = (int)cellSize.min.y;
            int zoff = (int)cellSize.min.z;

            //Determine how many distinct blocks we have in this chunk
            //VoxelData[, ,] chunkData = data.SampleSpace(cellSize);

            for (int x = 0; x < xvol; x++)
            {
                for (int y = 0; y < yvol; y++)
                {
                    for (int z = 0; z < zvol; z++)
                    {
                        int xx = xoff + x;
                        int yy = yoff + y;
                        int zz = zoff + z;

                        int id = data.Sample(xx, yy, zz);
                        if (id <= 0)
                        {
                            continue;
                        }

                        Vector3 vec = new Vector3(x, y, z);
                        //Add Back Face
                        if (data.Sample(xx, yy, zz + 1) <= 0)
                        {
                            AddMesh(ref mesh, 1, vec, id);
                        }
                        //Add Front Face
                        if (data.Sample(xx, yy, zz - 1) <= 0)
                        {
                            AddMesh(ref mesh, 0, vec, id);
                        }
                        //Add Top Face
                        if (data.Sample(xx, yy + 1, zz) <= 0)
                        {
                            AddMesh(ref mesh, 4, vec, id);
                        }

                        //Add Bottom Face
                        if (data.Sample(xx, yy - 1, zz) <= 0)
                        {
                            AddMesh(ref mesh, 5, vec, id);
                        }

                        //Add Left Face
                        if (data.Sample(xx + 1, yy, zz) <= 0)
                        {
                            AddMesh(ref mesh, 3, vec, id);
                        }

                        //Add Right Face
                        if (data.Sample(xx - 1, yy, zz) <= 0)
                        {
                            AddMesh(ref mesh, 2, vec, id);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void GenerateMesh(IVoxelDataSource<VoxelData> data, Bounds cellSize, out SimpleMesh mesh)
        {
            mesh = new SimpleMesh();
            mesh.RenderMaterial = Game.BlockRegistry.AtlasMaterial;

            int xvol = (int)cellSize.size.x;
            int yvol = (int)cellSize.size.y;
            int zvol = (int)cellSize.size.y;

            int xoff = (int)cellSize.min.x;
            int yoff = (int)cellSize.min.y;
            int zoff = (int)cellSize.min.z;

            //Determine how many distinct blocks we have in this chunk
            //VoxelData[, ,] chunkData = data.SampleSpace(cellSize);

            for (int x = 0; x < xvol; x++)
            {
                for (int y = 0; y < yvol; y++)
                {
                    for (int z = 0; z < zvol; z++)
                    {
                        int xx = xoff + x;
                        int yy = yoff + y;
                        int zz = zoff + z;

                        int id = data.Sample(xx, yy, zz);
                        if (id <= 0) continue;

                        Vector3 vec = new Vector3(x, y, z);
                        //Add Back Face
                        if (data.Sample(xx, yy, zz + 1) <= 0)
                        {
                            AddMesh(ref mesh, 1, vec, id);

                        }
                        //Add Front Face
                        if (data.Sample(xx, yy, zz - 1) <= 0)
                        {
                            AddMesh(ref mesh, 0, vec, id);
                        }
                        //Add Top Face
                        if (data.Sample(xx, yy + 1, zz) <= 0)
                        {
                            AddMesh(ref mesh, 4, vec, id);
                        }

                        //Add Bottom Face
                        if (data.Sample(xx, yy - 1, zz) <= 0)
                        {
                            AddMesh(ref mesh, 5, vec, id);
                        }

                        //Add Left Face
                        if (data.Sample(xx + 1, yy, zz) <= 0)
                        {
                            AddMesh(ref mesh, 3, vec, id);
                        }

                        //Add Right Face
                        if (data.Sample(xx - 1, yy, zz) <= 0)
                        {
                            AddMesh(ref mesh, 2, vec, id);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public Block GetBlockAt(Vector3 position)
 {
     return(Game.BlockRegistry[dataSource.Sample(position.x, position.y, position.z)]);
 }