public void TestRenderIsland()
        {
            var dirtMaterial = new VoxelMaterial();

            dirtMaterial.Texture = TW.Assets.LoadTexture("GrassGreenTexture0006.jpg");
            var size   = 20;
            var island = new ArrayFiniteVoxels(new Point3(size, size, size));

            island.NodeSize = 0.25f;
            for (int i = 0; i < size; i++)
            {
                for (int j = i; j < size - i; j++)
                {
                    for (int k = i; k < size - i; k++)
                    {
                        island.SetVoxel(new Point3(j, -i + size - 1, k), dirtMaterial);
                    }
                }
            }

            var c    = new VoxelMeshBuilder();
            var mesh = c.BuildMesh(island);


            var e = new Entity();

            e.Mesh = mesh;
        }
    void Awake()
    {
        meshFilter   = GetComponent <MeshFilter>();
        meshRenderer = GetComponent <MeshRenderer>();
        meshCollider = GetComponent <MeshCollider>();
        mesh         = new Mesh {
            indexFormat = IndexFormat.UInt32
        };

        VoxelMeshBuilder.InitializeShaderParameter();
    }
        public void TestGenerateIsland()
        {
            var gen    = new IslandGenerater(new Random(123));
            var island = gen.GenerateIsland(20);

            var c    = new VoxelMeshBuilder();
            var mesh = c.BuildMesh(island);


            var e = new Entity();

            e.Mesh = mesh;
        }
Example #4
0
            public void Update()
            {
                var b       = new VoxelMeshBuilder();
                var boxMesh = b.BuildMesh(new VoxelAdapter(TerrainChunk));

                _builder = new MeshBuilder();

                clearVisible();

                _ent.WorldMatrix = Matrix.Translation(TerrainChunk.WorldPosition);
                _ent.Mesh        = boxMesh;
                _ent.Solid       = true;
                _ent.Static      = true;
            }
        public void TestRenderEmptyVoxel()
        {
            var dirtMaterial = new VoxelMaterial();

            dirtMaterial.Texture = TW.Assets.LoadTexture("GrassGreenTexture0006.jpg");
            var island = new ArrayFiniteVoxels(new Point3(1, 1, 1));

            var c    = new VoxelMeshBuilder();
            var mesh = c.BuildMesh(island);


            var e = new Entity();

            e.Mesh = mesh;
        }
        public void TestRender100Islands()
        {
            var s   = new Seeder(123);
            var gen = new IslandGenerater(new Random(123));

            var c = new VoxelMeshBuilder();

            var scale = 25;

            var range = new Vector3(100, 10, 100) * (float)Math.Sqrt(scale);

            for (int i = 0; i < 20 * scale; i++)
            {
                var island = gen.GenerateIsland(s.NextInt(7, 20));
                var mesh   = c.BuildMesh(island);
                var e      = new Entity();
                e.Mesh        = mesh;
                e.WorldMatrix = Matrix.Translation(s.NextVector3(-range, range).dx());
            }
        }
Example #7
0
        public void BuildMesh()
        {
            if (Mesh != null)
            {
                frontMeshBuilder.Clear();
            }

            // We use a temporary empty var here in the case of this being ran on a seperate thread.
            // If this chunk was previously renderable, and is being updated, we don't want it to "flicker"
            // on the main thread while it is being updated. The main thread should just render the old mesh
            // until this is completed.
            bool isEmpty = true;

            for (int x = 0; x < HSIZE; x++)
            {
                for (int y = 0; y < VSIZE; y++)
                {
                    for (int z = 0; z < HSIZE; z++)
                    {
                        // Grab data about the current block
                        ChunkBlock data  = blockData[z, y, x];
                        Block      block = Blocks[z, y, x];

                        // If it's not air, lets draw!
                        if (block != Block.AIR)
                        {
                            // Calculate the color of the block
                            Color4 voxelColor = block.GetColor4();

                            // Determine which builder we'll be using
                            VoxelMeshBuilder useBuilder = frontMeshBuilder;

                            // Calculate the position of the block for local and global space.
                            IndexPosition blockPos = new IndexPosition(x, y, z);
                            Vector3       off      = (blockPos * Block.CUBE_SIZE);

                            // Get information about this block's neighbors.
                            bool blockAbove, blockBelow, blockLeft,
                                 blockForward, blockBackward, blockRight;
                            if (Mesh != null && !dirtyMask[z, y, x])
                            {
                                // If this block was already calculated and isn't dirty,
                                // we can simply pull the neighbor data from the chunkblock data.
                                blockAbove    = data.Up;
                                blockBelow    = data.Down;
                                blockLeft     = data.Left;
                                blockForward  = data.Front;
                                blockBackward = data.Back;
                                blockRight    = data.Right;
                            }
                            else
                            {
                                // Search for each block in all 6 directions
                                blockAbove    = GetBlockSafe(x, y + 1, z).IsOpaqueTo(block);
                                blockBelow    = GetBlockSafe(x, y - 1, z).IsOpaqueTo(block);
                                blockLeft     = GetBlockSafe(x - 1, y, z).IsOpaqueTo(block);
                                blockForward  = GetBlockSafe(x, y, z + 1).IsOpaqueTo(block);
                                blockBackward = GetBlockSafe(x, y, z - 1).IsOpaqueTo(block);
                                blockRight    = GetBlockSafe(x + 1, y, z).IsOpaqueTo(block);

                                // Update the chunkblock data
                                data.SetNeighbors(blockAbove, blockBelow, blockLeft, blockRight, blockForward, blockBackward);
                            }

                            // Only set this chunk to being non-empty if we are actually rendering something
                            if (data.NeighborCount != 6)
                            {
                                isEmpty = false;
                            }

                            // Add each cube face
                            if (!blockLeft)
                            {
                                useBuilder.AddLeft(block, blockPos, off, voxelColor);
                            }
                            if (!blockRight)
                            {
                                useBuilder.AddRight(block, blockPos, off, voxelColor);
                            }
                            if (!blockBackward)
                            {
                                useBuilder.AddBack(block, blockPos, off, voxelColor);
                            }
                            if (!blockForward)
                            {
                                useBuilder.AddFront(block, blockPos, off, voxelColor);
                            }
                            if (!blockAbove)
                            {
                                useBuilder.AddTop(block, blockPos, off, voxelColor);
                            }
                            if (!blockBelow)
                            {
                                useBuilder.AddBottom(block, blockPos, off, voxelColor);
                            }
                        }
                        else
                        {
                            // Default air-blocks to zero so that they are
                            // correctly updated when a block is place there later.
                            data.NeighborCount = 0;
                        }

                        // Update the block data
                        dirtyMask[z, y, x] = false;
                        blockData[z, y, x] = data;
                    }
                }
            }

            IsEmpty = isEmpty;

            // Swap Buffers
            VoxelMeshBuilder temp = frontMeshBuilder;

            frontMeshBuilder = backMeshBuilder;
            backMeshBuilder  = temp;
        }
Example #8
0
 protected override void CreateMeshBuilders(float cubeSize)
 {
     frontMeshBuilder = new VoxelMeshBuilder(this, Block.CUBE_SIZE, 0.5f);
     backMeshBuilder  = new VoxelMeshBuilder(this, Block.CUBE_SIZE, 0.5f);
 }
Example #9
0
        public IMesh GetMesh(IVoxel gameVoxel)
        {
            return(provider.GetMesh(gameVoxel));

            return(VoxelMeshBuilder.createColoredMesh(Color.FromArgb(r.NextByte(0, 255), r.NextByte(0, 255), r.NextByte(0, 255))));
        }
 public IslandMeshFactory(VoxelMeshBuilder c)
 {
     this.c = c;
 }