/// <summary> /// Apply the Circle Brush /// </summary> /// <param name="modType">The modification type to apply</param> /// <param name="heightData">Terrain height data</param> /// <param name="terrainData">Terrain Data used</param> private void CircleBrush(TerrainModificationType modType, float[,] heightData, TerrainData terrainData) { int offsetX = m_BrushWidth / 2; int offsetY = m_BrushHeight / 2; for (int i = 0; i < m_BrushHeight; i++) { for (int j = 0; j < m_BrushWidth; j++) { float currentRadiusSqr = new Vector2(offsetX - j, offsetY - i).sqrMagnitude; if (currentRadiusSqr < offsetX * offsetY) { switch (modType) { case TerrainModificationType.Raise: heightData[i, j] = NewRaiseHeight(heightData[i, j], terrainData); break; case TerrainModificationType.Lower: heightData[i, j] = NewLowerHeight(heightData[i, j], terrainData); break; case TerrainModificationType.Flatten: heightData[i, j] = NewFlattenHeight(heightData[offsetX, offsetY], terrainData); break; case TerrainModificationType.Smooth: SmoothTerrainOperation(1, heightData, j, i); break; } } } } }
/// <summary> /// Apply the Rectangle Brush /// </summary> /// <param name="modType">The modification type to apply</param> /// <param name="heightData">Terrain height data</param> /// <param name="terrainData">Terrain Data used</param> private void RectangleBrush(TerrainModificationType modType, float[,] heightData, TerrainData terrainData) { int offsetX = m_BrushWidth / 2; int offsetY = m_BrushHeight / 2; for (int i = 0; i < m_BrushHeight; i++) { for (int j = 0; j < m_BrushWidth; j++) { switch (modType) { case TerrainModificationType.Raise: heightData[i, j] = NewRaiseHeight(heightData[i, j], terrainData); break; case TerrainModificationType.Lower: heightData[i, j] = NewLowerHeight(heightData[i, j], terrainData); break; case TerrainModificationType.Flatten: heightData[i, j] = NewFlattenHeight(heightData[offsetX, offsetY], terrainData); break; case TerrainModificationType.Smooth: SmoothTerrainOperation(1, heightData, i, j); break; } } } }
/// <summary> /// Constructor of the Terrain Brush /// </summary> /// <param name="minHeight">Lower modification bound for height</param> /// <param name="maxHeight">High modification bound for height</param> /// <param name="shape">The desired shape of the brush</param> /// <param name="modificationType">The type of the Modification</param> /// <param name="brushWidth">The width of the brush</param> /// <param name="brushHeight">The height of the brush</param> /// <param name="modSpeed">Speed of the Terrain Modification</param> public TerrainBrush(float minHeight, float maxHeight, TerrainModificationShape shape = TerrainModificationShape.Square, TerrainModificationType modificationType = TerrainModificationType.Raise, int brushWidth = 50, int brushHeight = 50, float modSpeed = 10f) { m_Shape = shape; m_BrushWidth = brushWidth; m_BrushHeight = brushHeight; m_ModificationSpeed = modSpeed; m_ModificationType = modificationType; m_MinHeight = minHeight; m_MaxHeight = maxHeight; }
public TerrainModification_BlueprintData(TerrainModificationCondition condition) { this.name = condition.transform.name; this.position = condition.transform.localPosition; this.rotation = condition.transform.localRotation; this.scale = condition.transform.localScale; this.revertOnDestroy = condition.revertOnDestroy; this.modificationType = condition.modificationType; this.xScale = condition.xScale; this.zScale = condition.zScale; this.offset = condition.offset; this.assingAlphaMaps = condition.assignTextureOnFlattenArea; this.alphaMap = condition.flattenAreaTextureIndex; this.alphaMapStrength = condition.flattenAreaTextureStrength; }
/// <summary> /// The method which takes care of the on-line painting /// </summary> /// <param name="texture">The name of the texture we are going to paint</param> /// <param name="type">The type of painting we are doing</param> /// <param name="colour">The colour we are painting with</param> /// <param name="inner">The size of the inner circle</param> /// <param name="outer">The size of the outer circle</param> /// <param name="X">X coordinate</param> /// <param name="Y">Y coordinate</param> /// <param name="Z">Z coordinate</param> private void paintTexture(string texture, TerrainModificationType type, int colour, float inner, float outer, float X, float Y, float Z) { try { Vector3 vec = new Vector3(X, Y, Z); Vector3 vec2 = new Vector3(X, Y, Z); NWN2NetDisplayManager.Instance.TerrainBrush(areaViewer.AreaNetDisplayWindow.Scene, 1, 0, vec, inner, outer, NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue, NWN2ToolsetMainForm.App.TerrainEditor.TerrainValue2, NWN2ToolsetMainForm.App.TerrainEditor.TerrainBrushColor, colour, texture, type); NWN2NetDisplayManager.Instance.TerrainModify(areaViewer.AreaNetDisplayWindow.Scene, type, NWN2ToolsetMainForm.App.TerrainEditor.TextureMode); byte[] buffer2 = null; bool bCancel = false; NWN2NetDisplayManager.Instance.BeginSynchronizedOperation(); int num6 = NWN2NetDisplayManager.Instance.TerrainSelection(areaViewer.AreaNetDisplayWindow.Scene, vec2); NWN2NetDisplayManager.Instance.WaitForMessageSynchronous(NetDisplayMessageType.TerrainSelectResults, out buffer2, num6); NWN2NetDisplayManager.Instance.EndSynchronizedOperation(); if (buffer2 != null) { NWN2ToolsetMainForm.App.TerrainEditor.HandleSelectTerrain(buffer2, ref bCancel); } } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// The method that prepares to call the Method that does the actual paiting /// This include finding the coordinates that are to be painted, in what order, and the size of the outer and inner brush /// </summary> /// <param name="coor">The coordiantes we are going to start from</param> /// <param name="modType">The type of painting we are to do</param> /// <param name="localTexture">The texture we are going to paint</param> private void texturePreperation(SFX.YATT.Tools.Vector<float> coor, TerrainModificationType modType, textureData localTexture) { float valueX = coor[0]; float valueY = coor[1]; float valueZ = coor[2]; int radius = (data.outerCircle + data.innerCircle) / 2; double roundModifier = 2 - (rounds / 11); float localOuter = (float)((newOuter / rounds) * roundModifier); float localInner = (float)((newInner / rounds) * roundModifier); opTexture.Checked = true; outerRadius.Value = Math.Min((int)localOuter, outerRadius.Maximum); innerRadius.Value = Math.Min((int)localInner, innerRadius.Maximum); float baseCoordinatesX = Math.Max(0, valueX - (radius / 2)); float baseCoordinatesY = Math.Max(0, valueY - (radius / 2)); float step = (radius / rounds); float coorX; float coorY; int ran = 0; // Make sure we have a new random number random = new Random(System.DateTime.Now.Millisecond); System.Collections.Generic.List<Pair<float, float>> coordinates = new System.Collections.Generic.List<Pair<float, float>>(); for(int index1 = 1; index1 <= rounds; index1++ ) { coorX = baseCoordinatesX + (step * index1); for (int index2 = 1; index2 <= rounds; index2++) { coorY = baseCoordinatesY + (step * index2); coordinates.Add(new Pair<float, float>(coorX, coorY)); } } int coverage = 0; string textureStr = localTexture.texture; int col = Color.White.ToArgb(); if (modType == TerrainModificationType.Texture) { // CoverageChange must be bigger than 0 and less than 100 coverage = localTexture.Coverage; // Set the presure of the current texture barPressure.Value = localTexture.Presure * 100; } else if (modType == TerrainModificationType.Grass) { coverage = data.grassCoverage; } else if (modType == TerrainModificationType.Color) { coverage = data.colourCoverage; col = data.col.ToArgb(); } else { throw new Exception("Wrong Terrain Modification Type"); } foreach (Pair<float, float> point in coordinates) { coorX = point.X; coorY = point.Y; ran = random.Next(1, 100); NWN2NetDisplayManager.Instance.BeginSynchronizedOperation(); if (ran <= coverage) { paintTexture(textureStr, modType, col, localInner, localOuter, coorX, coorY, valueZ); } NWN2NetDisplayManager.Instance.EndSynchronizedOperation(); } }
/// <summary> /// The method that prepares to call the Method that does the actual paiting /// This include finding the coordinates that are to be painted, in what order, and the size of the outer and inner brush /// </summary> /// <param name="coor">The coordiantes we are going to start from</param> /// <param name="modType">The type of painting we are to do</param> /// <param name="localTexture">The texture we are going to paint</param> private void texturePreperation(SFX.YATT.Tools.Vector <float> coor, TerrainModificationType modType, textureData localTexture) { float valueX = coor[0]; float valueY = coor[1]; float valueZ = coor[2]; int radius = (data.outerCircle + data.innerCircle) / 2; double roundModifier = 2 - (rounds / 11); float localOuter = (float)((newOuter / rounds) * roundModifier); float localInner = (float)((newInner / rounds) * roundModifier); opTexture.Checked = true; outerRadius.Value = Math.Min((int)localOuter, outerRadius.Maximum); innerRadius.Value = Math.Min((int)localInner, innerRadius.Maximum); float baseCoordinatesX = Math.Max(0, valueX - (radius / 2)); float baseCoordinatesY = Math.Max(0, valueY - (radius / 2)); float step = (radius / rounds); float coorX; float coorY; int ran = 0; // Make sure we have a new random number random = new Random(System.DateTime.Now.Millisecond); System.Collections.Generic.List <Pair <float, float> > coordinates = new System.Collections.Generic.List <Pair <float, float> >(); for (int index1 = 1; index1 <= rounds; index1++) { coorX = baseCoordinatesX + (step * index1); for (int index2 = 1; index2 <= rounds; index2++) { coorY = baseCoordinatesY + (step * index2); coordinates.Add(new Pair <float, float>(coorX, coorY)); } } int coverage = 0; string textureStr = localTexture.texture; int col = Color.White.ToArgb(); if (modType == TerrainModificationType.Texture) { // CoverageChange must be bigger than 0 and less than 100 coverage = localTexture.Coverage; // Set the presure of the current texture barPressure.Value = localTexture.Presure * 100; } else if (modType == TerrainModificationType.Grass) { coverage = data.grassCoverage; } else if (modType == TerrainModificationType.Color) { coverage = data.colourCoverage; col = data.col.ToArgb(); } else { throw new Exception("Wrong Terrain Modification Type"); } foreach (Pair <float, float> point in coordinates) { coorX = point.X; coorY = point.Y; ran = random.Next(1, 100); NWN2NetDisplayManager.Instance.BeginSynchronizedOperation(); if (ran <= coverage) { paintTexture(textureStr, modType, col, localInner, localOuter, coorX, coorY, valueZ); } NWN2NetDisplayManager.Instance.EndSynchronizedOperation(); } }