/// <summary> /// Initialise the editor. /// </summary> /// <param name="terrainEditorProgram">The terrain editor effect to clone. In the default content, this is stored as "Terracotta/TerrainEditorEffect".</param> /// <param name="terrain">The terrain to edit.</param> public TerrainEditor(PlanarTerrainBlock block) { this.terrainBlock = block; var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.TerrainEditor.glsl"); Program = new Program( builder.VertexShader("Common", "Vertex"), builder.FragmentShader("Common", "Fragment")); Program.Uniforms["TerrainSize"].Set(Terrain.BlockSize); Program.Uniforms["InverseTerrainSize"].Set(1.0 / Terrain.BlockSize); Rng = new Random(); byte[] permutations = new byte[PerlinSize]; for (int i = 0; i < permutations.Length; i++) { permutations[i] = (byte)i; } for (int i = 0; i < permutations.Length; i++) { Extensions.Swap(ref permutations[i], ref permutations[Rng.Next(permutations.Length)]); } CreatePerlinPermutationTexture(permutations); CreatePerlinGradientTexture(permutations); CreateTemporaryTexture(); //LoadRandomPerlinTransform(); PerlinTransform = Matrix4d.Identity; }
/// <summary> /// Initialise the editor. /// </summary> /// <param name="terrainEditorProgram">The terrain editor effect to clone. In the default content, this is stored as "Terracotta/TerrainEditorEffect".</param> /// <param name="terrain">The terrain to edit.</param> public TerrainEditor(PlanarTerrainBlock block) { this.terrainBlock = block; var builder = ShaderBuilder.CreateFromAssemblyResource("Glare.Graphics.Shaders.TerrainEditor.glsl"); Program = new Program( builder.VertexShader("Common", "Vertex"), builder.FragmentShader("Common", "Fragment")); Program.Uniforms["TerrainSize"].Set(Terrain.BlockSize); Program.Uniforms["InverseTerrainSize"].Set(1.0 / Terrain.BlockSize); Rng = new Random(); byte[] permutations = new byte[PerlinSize]; for (int i = 0; i < permutations.Length; i++) permutations[i] = (byte)i; for (int i = 0; i < permutations.Length; i++) Extensions.Swap(ref permutations[i], ref permutations[Rng.Next(permutations.Length)]); CreatePerlinPermutationTexture(permutations); CreatePerlinGradientTexture(permutations); CreateTemporaryTexture(); //LoadRandomPerlinTransform(); PerlinTransform = Matrix4d.Identity; }
/// <summary>Get the <see cref="PlanarTerrainBlock"/> at the given block indices, creating it if necessary.</summary> /// <param name="blockIndex">The block index.</param> /// <returns>The <see cref="PlanarTerrainBlock"/>.</returns> public PlanarTerrainBlock GenerateBlock(Vector2i blockIndex) { PlanarTerrainBlock block; if (!BlockDictionary.TryGetValue(blockIndex, out block)) { block = BlockDictionary[blockIndex] = new PlanarTerrainBlock(this, blockIndex); foreach (TerrainComponent component in ComponentsMutable) { component.OnBlockAdded(block); } } return(block); }
/// <summary> /// Generate the tree node. /// </summary> /// <param name="terrainBlock">The terrain this is a node within.</param> /// <param name="corner">The integer coordinates of the top-left corner of the tree node.</param> /// <param name="size">The size in cells of this tree node.</param> /// <param name="lod">The level of detail of this node. This decreases for each step down into the terrain until it reaches zero.</param> public TerrainTreeNode(PlanarTerrainBlock terrainBlock, Vector2i corner, int size, int lod) { if (size < TerrainBlockSize) { throw new Exception("Invalid terrain size - must be a power of 2 greater than " + TerrainBlockSize + "."); } this.terrainBlock = terrainBlock; pLod = lod; pTexelCorner = new Vector2d(corner.X, corner.Y) / Terrain.BlockSize; pTexelSize = size / (double)Terrain.BlockSize; pBox.Min = new Vector3d(corner.X, 0, corner.Y); pBox.Max = new Vector3d(corner.X + size, 0, corner.Y + size); pVertexCorner = new Vector2i(corner.X / TerrainBlockSize, corner.Y / TerrainBlockSize); if (size > TerrainBlockSize) { var hsize = size / 2; pChildTopLeft = new TerrainTreeNode(terrainBlock, corner, hsize, lod - 1); pChildTopRight = new TerrainTreeNode(terrainBlock, new Vector2i(corner.X + hsize, corner.Y), hsize, lod - 1); pChildBottomLeft = new TerrainTreeNode(terrainBlock, new Vector2i(corner.X, corner.Y + hsize), hsize, lod - 1); pChildBottomRight = new TerrainTreeNode(terrainBlock, new Vector2i(corner.X + hsize, corner.Y + hsize), hsize, lod - 1); } }
/// <summary> /// The terrain's heightmap has been modified and its changes have been accepted into the core. /// This is then called on each attached module to give it an opportunity to affect it. /// </summary> /// <param name="area"></param> public virtual void OnHeightModified(PlanarTerrainBlock block, ref Box2i area) { }
public virtual void OnDrawing(PlanarTerrainBlock block, ref Matrix4d world) { }
/// <summary>This is called when the <see cref="PlanarTerrain"/> has added a new <see cref="PlanarTerrainBlock"/>.</summary> /// <param name="block"></param> public virtual void OnBlockAdded(PlanarTerrainBlock block) { }
/// <summary> /// The terrain's heightmap has been modified and its changes have been accepted into the core. /// This is then called on each attached module to give it an opportunity to affect it. /// </summary> /// <param name="area"></param> public virtual void OnHeightModified(PlanarTerrainBlock block, ref Box2i area) { }
public virtual void OnDrawing(PlanarTerrainBlock block, ref Matrix4d world) { }
/// <summary>This is called when the <see cref="PlanarTerrain"/> has added a new <see cref="PlanarTerrainBlock"/>.</summary> /// <param name="block"></param> public virtual void OnBlockAdded(PlanarTerrainBlock block) { }