Exemple #1
0
        public HeightMapRenderer(HeightMapMesh heightMap, AnimationUtilities.SkinnedEffect effect)
        {
            mMesh = heightMap;
            mEffect = effect;

            mUIConfigurer = null;
        }
Exemple #2
0
        public static bool AddNewLevelBlock(Level level, Vector3 coordinate, Texture2D heightMap, Texture2D alphaMap, string[] detailTextureNames, Vector2[] uvOffsets, Vector2[] uvScales)
        {
            if (level.Contains(coordinate))
            {
                return false;
            }

            Color[] heightColors = new Color[HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_VERTICES];
            if (heightMap.Width != HeightMapMesh.NUM_SIDE_VERTICES || heightMap.Height != HeightMapMesh.NUM_SIDE_VERTICES)
            {
                RenderTarget2D resizedHeightMap = new RenderTarget2D(GraphicsManager.Device, HeightMapMesh.NUM_SIDE_VERTICES, HeightMapMesh.NUM_SIDE_VERTICES);
                GraphicsManager.Device.SetRenderTarget(resizedHeightMap);

                GraphicsManager.SpriteBatch.Begin();
                GraphicsManager.SpriteBatch.Draw(heightMap, new Rectangle(0, 0, HeightMapMesh.NUM_SIDE_VERTICES, HeightMapMesh.NUM_SIDE_VERTICES), Color.White);
                GraphicsManager.SpriteBatch.End();

                GraphicsManager.Device.SetRenderTarget(null);
                resizedHeightMap.GetData(heightColors);
            }
            else
            {
                heightMap.GetData(heightColors);
            }

            float[,] heights = new float[HeightMapMesh.NUM_SIDE_VERTICES, HeightMapMesh.NUM_SIDE_VERTICES];
            for (int i = 0; i < heightColors.Length; i++)
            {
                heights[i % HeightMapMesh.NUM_SIDE_VERTICES, i / HeightMapMesh.NUM_SIDE_VERTICES] = ConvertColorToFloat(heightColors[i]);
            }

            if (alphaMap.Height != HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD ||
                alphaMap.Width != HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD)
            {
                RenderTarget2D resizedAlphaMap = new RenderTarget2D(GraphicsManager.Device,
                    HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD,
                    HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD);

                GraphicsManager.Device.SetRenderTarget(resizedAlphaMap);

                GraphicsManager.SpriteBatch.Begin();
                GraphicsManager.SpriteBatch.Draw(alphaMap,
                    new Rectangle(0,
                        0,
                        HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD,
                        HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD),
                    Color.White);
                GraphicsManager.SpriteBatch.End();

                GraphicsManager.Device.SetRenderTarget(null);

                alphaMap = resizedAlphaMap;
            }

            HeightMapMesh heightMapMesh = new HeightMapMesh(heights, alphaMap, detailTextureNames, uvOffsets, uvScales);

            AssetLibrary.AddHeightMap(level.Name + coordinate.ToString(), heightMapMesh);
            level.AddNewBlock(coordinate);
            return true;
        }
Exemple #3
0
 public static void AddHeightMap(string heightMapName, HeightMapMesh heightMap)
 {
     if (mAssetLibrary[HeightMapKey].ContainsKey(heightMapName))
     {
         return;
     }
     mAssetLibrary[HeightMapKey].Add(heightMapName, new HeightMapRenderer(heightMap, mVertexBufferShader));
 }
Exemple #4
0
 public static void AddGrid(string gridName, HeightMapMesh grid)
 {
     if (mAssetLibrary[GridKey].ContainsKey(gridName))
     {
         return;
     }
     mAssetLibrary[GridKey].Add(gridName, new GridRenderer(grid, mVertexBufferShader));
 }
Exemple #5
0
 public GridRenderer(HeightMapMesh heightMap, AnimationUtilities.SkinnedEffect effect)
     : base(heightMap, effect)
 {
     mNormalDepthConfigurer = null;
     mPickingConfigurer = null;
     mShadowMapConfigurer = null;
     mUIConfigurer = null;
     mWithoutShadowsConfigurer = null;
     mWithShadowsConfigurer = null;
 }
Exemple #6
0
        public DummyWorld(Controls controls)
        {
            mName = null;
            mLevel = null;

            Texture2D gridAlphaMap = new Texture2D(GraphicsManager.Device, HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD, HeightMapMesh.NUM_SIDE_VERTICES * HeightMapMesh.NUM_SIDE_TEXELS_PER_QUAD);
            HeightMapMesh gridMesh = new HeightMapMesh(new float[HeightMapMesh.NUM_SIDE_VERTICES, HeightMapMesh.NUM_SIDE_VERTICES], gridAlphaMap, new string[0], null, null);
            AssetLibrary.AddGrid("BLOCK_GRID", gridMesh);

            mGridRenderable = new GridRenderable("BLOCK_GRID");
        }
Exemple #7
0
 public void EraseTexture(Vector3 centerPosition, float radius, float alpha, HeightMapMesh.TextureLayer layer, string texture, Vector2 UVOffset, Vector2 UVScale, bool isFeathered, bool isBlock)
 {
     HeightMapMesh mesh = AssetLibrary.LookupHeightMap(mName).Mesh;
     mesh.EraseTerrain(centerPosition, radius, alpha, layer, texture, UVOffset, UVScale, isFeathered, isBlock);
 }
Exemple #8
0
        public void ModifyTextureMap(
            Vector3 position, 
            string texture, 
            Vector2 UVOffset, 
            Vector2 UVScale, 
            float radius, 
            float alpha,
            EditorForm.Brushes brush,
            EditorForm.Tools tool, 
            HeightMapMesh.TextureLayer layer)
        {
            bool isFeathered = brush == EditorForm.Brushes.CIRCLE_FEATHERED || brush == EditorForm.Brushes.BLOCK_FEATHERED;
            bool isBlock = brush == EditorForm.Brushes.BLOCK || brush == EditorForm.Brushes.BLOCK_FEATHERED;

            ModifiableLevel.BlockModifier textureModifier = null;
            switch (tool)
            {
                case EditorForm.Tools.PAINT:
                    textureModifier = PaintTexture;
                    break;
                case EditorForm.Tools.ERASE:
                    textureModifier = EraseTexture;
                    break;
                case EditorForm.Tools.BLEND:
                    textureModifier = BlendTexture;
                    break;
            }

            mLevel.IterateOverBlocksInContainerInRadius(
                mSelectedBlocks.Count == 0 ? null : mSelectedBlocks,
                position,
                radius,
                textureModifier,
                new object[] { (bool?)isFeathered, (bool?)isBlock, (float?)alpha, (HeightMapMesh.TextureLayer?)layer, texture, (Vector2?)UVOffset, (Vector2?)UVScale});
        }