Exemplo n.º 1
0
        private TerrainPatch CreatePatch(
            TerrainMaterial terrainMaterial,
            HeightMap heightMap,
            BlendTileData blendTileData,
            Rectangle patchBounds,
            GraphicsDevice graphicsDevice,
            TerrainPatchIndexBufferCache indexBufferCache)
        {
            var indexBuffer = indexBufferCache.GetIndexBuffer(
                patchBounds.Width,
                patchBounds.Height,
                out var indices);

            var vertexBuffer = AddDisposable(CreateVertexBuffer(
                                                 graphicsDevice,
                                                 heightMap,
                                                 patchBounds,
                                                 indices,
                                                 out var boundingBox,
                                                 out var triangles));

            return(new TerrainPatch(
                       terrainMaterial,
                       patchBounds,
                       vertexBuffer,
                       indexBuffer,
                       (uint)indices.Length,
                       triangles,
                       boundingBox));
        }
Exemplo n.º 2
0
        private TerrainPatchComponent CreatePatch(
            TerrainEffect terrainEffect,
            EffectPipelineStateHandle pipelineStateHandle,
            HeightMap heightMap,
            BlendTileData blendTileData,
            Int32Rect patchBounds,
            GraphicsDevice graphicsDevice,
            ResourceUploadBatch uploadBatch,
            TerrainPatchIndexBufferCache indexBufferCache)
        {
            var indexBuffer = indexBufferCache.GetIndexBuffer(
                patchBounds.Width,
                patchBounds.Height,
                uploadBatch,
                out var indices);

            var vertexBuffer = AddDisposable(CreateVertexBuffer(
                                                 graphicsDevice,
                                                 uploadBatch,
                                                 heightMap,
                                                 patchBounds,
                                                 indices,
                                                 out var boundingBox,
                                                 out var triangles));

            return(new TerrainPatchComponent(
                       terrainEffect,
                       pipelineStateHandle,
                       patchBounds,
                       vertexBuffer,
                       indexBuffer,
                       triangles,
                       boundingBox));
        }
Exemplo n.º 3
0
        private void CreatePatches(
            GraphicsDevice graphicsDevice,
            ResourceUploadBatch uploadBatch,
            Entity terrainEntity,
            HeightMap heightMap,
            BlendTileData blendTileData,
            TerrainEffect terrainEffect,
            EffectPipelineStateHandle pipelineStateHandle,
            TerrainPatchIndexBufferCache indexBufferCache)
        {
            const int numTilesPerPatch = TerrainComponent.PatchSize - 1;

            var numPatchesX = heightMap.Width / numTilesPerPatch;

            if (heightMap.Width % numTilesPerPatch != 0)
            {
                numPatchesX += 1;
            }

            var numPatchesY = heightMap.Height / numTilesPerPatch;

            if (heightMap.Height % numTilesPerPatch != 0)
            {
                numPatchesY += 1;
            }

            for (var y = 0; y < numPatchesY; y++)
            {
                for (var x = 0; x < numPatchesX; x++)
                {
                    var patchX = x * numTilesPerPatch;
                    var patchY = y * numTilesPerPatch;

                    var patchBounds = new Int32Rect
                    {
                        X      = patchX,
                        Y      = patchY,
                        Width  = Math.Min(TerrainComponent.PatchSize, heightMap.Width - patchX),
                        Height = Math.Min(TerrainComponent.PatchSize, heightMap.Height - patchY)
                    };

                    terrainEntity.Components.Add(CreatePatch(
                                                     terrainEffect,
                                                     pipelineStateHandle,
                                                     heightMap,
                                                     blendTileData,
                                                     patchBounds,
                                                     graphicsDevice,
                                                     uploadBatch,
                                                     indexBufferCache));
                }
            }
        }
Exemplo n.º 4
0
        private List <TerrainPatch> CreatePatches(
            GraphicsDevice graphicsDevice,
            HeightMap heightMap,
            BlendTileData blendTileData,
            TerrainMaterial terrainMaterial,
            TerrainPatchIndexBufferCache indexBufferCache)
        {
            const int numTilesPerPatch = Terrain.Terrain.PatchSize - 1;

            var heightMapWidthMinusOne = heightMap.Width - 1;
            var numPatchesX            = heightMapWidthMinusOne / numTilesPerPatch;

            if (heightMapWidthMinusOne % numTilesPerPatch != 0)
            {
                numPatchesX += 1;
            }

            var heightMapHeightMinusOne = heightMap.Height - 1;
            var numPatchesY             = heightMapHeightMinusOne / numTilesPerPatch;

            if (heightMapHeightMinusOne % numTilesPerPatch != 0)
            {
                numPatchesY += 1;
            }

            var patches = new List <TerrainPatch>();

            for (var y = 0; y < numPatchesY; y++)
            {
                for (var x = 0; x < numPatchesX; x++)
                {
                    var patchX = x * numTilesPerPatch;
                    var patchY = y * numTilesPerPatch;

                    var patchBounds = new Rectangle(
                        patchX,
                        patchY,
                        Math.Min(Terrain.Terrain.PatchSize, heightMap.Width - patchX),
                        Math.Min(Terrain.Terrain.PatchSize, heightMap.Height - patchY));

                    patches.Add(CreatePatch(
                                    terrainMaterial,
                                    heightMap,
                                    blendTileData,
                                    patchBounds,
                                    graphicsDevice,
                                    indexBufferCache));
                }
            }

            return(patches);
        }