Esempio n. 1
0
        public void Render(Voxmap voxmap)
        {
            //    Look at each voxel
            var voxelSize   = voxmap.VoxelSize;
            var voxmapStart = voxmap.scale * -0.5f;

            //    For each voxel, render all sides of it
            for (var x = 0; x < voxmap.Width; x++)
            {
                var xmin = voxmapStart.x + (voxelSize.x * x);
                var xmax = xmin + voxelSize.x;
                for (var y = 0; y < voxmap.Height; y++)
                {
                    var ymin = voxmapStart.y + (voxelSize.y * y);
                    var ymax = ymin + voxelSize.y;
                    for (var z = 0; z < voxmap.Depth; z++)
                    {
                        // look at each surrounding voxel side to see if it needs to be rendered.

                        if (voxmap[x, y, z].m == 0)
                        {
                            continue;
                        }
                        var zmin = voxmapStart.z + (voxelSize.z * z);
                        var zmax = zmin + voxelSize.z;
                    }
                }
            }
        }
Esempio n. 2
0
        public void Render(Voxmap voxmap)
        {
            var voxelSize   = voxmap.VoxelSize;
            var voxmapStart = voxmap.scale * -0.5f;

            //var quadStart = 1f * -0.5f;
            //    For each voxel, render all sides of it
            for (var x = 0; x < voxmap.Width; x++)
            {
                var xmin = voxmapStart.x + (voxelSize.x * x);
                var xmax = xmin + voxelSize.x;
                for (var y = 0; y < voxmap.Height; y++)
                {
                    var ymin = voxmapStart.y + (voxelSize.y * y);
                    var ymax = ymin + voxelSize.y;
                    for (var z = 0; z < voxmap.Depth; z++)
                    {
                        if (voxmap[x, y, z].m == 0)
                        {
                            continue;
                        }
                        var zmin = voxmapStart.z + (voxelSize.z * z);
                        var zmax = zmin + voxelSize.z;
                        AddQuad(chunk, CreateFaceX(xmin, xmax, ymin, ymax, zmin));
                        AddQuad(chunk, CreateFaceX(xmax, xmin, ymin, ymax, zmax));
                        AddQuad(chunk, CreateFaceZ(zmin, zmax, ymin, ymax, xmax));
                        AddQuad(chunk, CreateFaceZ(zmax, zmin, ymin, ymax, xmin));
                        AddQuad(chunk, CreateFaceY(xmin, xmax, zmin, zmax, ymax));
                        AddQuad(chunk, CreateFaceY(xmax, xmin, zmin, zmax, ymin));
                    }
                }
            }
        }
Esempio n. 3
0
        public void Render(Voxmap voxmap)
        {
            StreamWriter writer = new StreamWriter(filePath, false);
            var          json   = JsonUtility.ToJson(voxmap);

            writer.Write(json);
            writer.Close();
        }
Esempio n. 4
0
        public void Start()
        {
            var filePath = Application.dataPath + "/voxmap.json";
            var voxelmap = new Voxmap(size, size, size);
            var loader   = new FileLoader(filePath);

            // var loader = new PerlinNoise();
            loader.Load(voxelmap);
            var chunk    = new Chunk();
            var renderer = new FullRenderer(chunk);

            renderer.Render(voxelmap);
            Mesh mesh = GetComponent <MeshFilter>().mesh;

            mesh.Clear();
            mesh.vertices  = chunk.vertices.ToArray();
            mesh.triangles = chunk.triangles.ToArray();
            //mesh.RecalculateNormals();
            if (optimize)
            {
                MeshUtility.Optimize(mesh);
            }
        }