void addBrush(object sender, EventArgs e) { /* * There is no theoretical limit on the number of repeat textures, but there needs to be a balance between * the number of textures you can select and the time it will take to paint them all. */ if (textureList.Items.Count < NUM_TEXTURE_TOTAL) { if (canAdd()) { textureData texture = new textureData(brushTextureList.SelectedItem.ToString()); textureList.Items.Add(texture); textureList.SelectedItem = texture; } } }
XmlElement makeTextureElement(string name, textureData data, XmlDocument xmlDoc) { XmlElement textureElem = xmlDoc.CreateElement(name); textureElem.InnerXml = data.texture; textureElem.SetAttribute("presure", data.presure.ToString()); textureElem.SetAttribute("coverage", data.coverage.ToString()); // The variance textureElem.SetAttribute("varCoverageFrom", data.varCoverage.X.ToString()); textureElem.SetAttribute("varCoverageTo", data.varCoverage.Y.ToString()); textureElem.SetAttribute("varPresureFrom", data.varPresure.X.ToString()); textureElem.SetAttribute("varPresureTo", data.varPresure.Y.ToString()); return(textureElem); }
/// <summary> /// The eyeDropCode allows us to find out what kind of textures are used in a megatile /// </summary> private void eyeDropCode() { LinkedList <textureData> textures = new LinkedList <textureData>(); for (int i = 0; i < 6; i++) { Label opTexture = (Label)TE.Controls.Find("labelRadioButtonTexture" + (i + 1), true)[0]; if (opTexture.Text != "") { textureData texture = new textureData(opTexture.Text); textures.AddFirst(texture); } } data.textures = textures; Multibrush.PluginContainer.makeMultiForm(data); }
void AcceptBrushClick(object sender, EventArgs e) { if (canAdd()) { int index = textureList.SelectedIndex; Point cov = new Point((int)fromCoverageVar.Value, (int)toCoverageVar.Value); Point pres = new Point((int)fromPresureVar.Value, (int)toPresureVar.Value); textureData texture = new textureData(brushTextureList.SelectedItem.ToString(), presureTrack.Value, coverageTrack.Value, cov, pres); skipReload = true; textureList.Items.Remove(textureList.SelectedItem); textureList.Items.Insert(index, texture); textureList.SelectedIndex = index; } }
void TextureListSelectedIndexChanged(object sender, EventArgs e) { if (!skipReload) { textureData texture = (textureData)textureList.SelectedItem; if (texture != null) { brushTextureList.setListByName(texture.texture); presureTrack.Value = texture.presure; coverageTrack.Value = texture.coverage; // Variance // I need to do this in "reverse" order, to ensure I won't get into any trouble with the minimum and maximum settings setVariance(toCoverageVar, texture.varCoverage.Y); setVariance(fromCoverageVar, texture.varCoverage.X); setVariance(toPresureVar, texture.varPresure.Y); setVariance(fromPresureVar, texture.varPresure.X); } } skipReload = false; }
/// <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 eyeDropCode allows us to find out what kind of textures are used in a megatile /// </summary> private void eyeDropCode() { LinkedList<textureData> textures = new LinkedList<textureData>(); for(int i = 0; i < 6; i++) { Label opTexture = (Label)TE.Controls.Find("labelRadioButtonTexture" + (i + 1), true)[0]; if (opTexture.Text != "") { textureData texture = new textureData(opTexture.Text); textures.AddFirst(texture); } } data.textures = textures; Multibrush.PluginContainer.makeMultiForm(data); }
private static XmlElement makeTextureElement(string name, textureData data, XmlDocument xmlDoc) { XmlElement textureElem = xmlDoc.CreateElement(name); textureElem.InnerXml = data.texture; textureElem.SetAttribute("presure", data.getPresureUnmodified().ToString()); textureElem.SetAttribute("coverage", data.getCoverageUnmodified().ToString()); // The variance textureElem.SetAttribute("varCoverageFrom", data.varCoverage.X.ToString()); textureElem.SetAttribute("varCoverageTo", data.varCoverage.Y.ToString()); textureElem.SetAttribute("varPresureFrom", data.varPresure.X.ToString()); textureElem.SetAttribute("varPresureTo", data.varPresure.Y.ToString()); return textureElem; }
public void ApplyTextureAsNewChannel(int x, int y, textureData texture, Multibrush.LineSegment linesegment, Rectangle coverRectangle, double inner) { Rectangle rec = new Rectangle(x, y, this.Width, this.Height); Random ran = new Random(); int channel = 0; int coverage = 0; bool firstCheck = true; bool painted = false; double presure = (float)texture.Presure / 100.0; if (coverRectangle.IntersectsWith(rec)) { for(int xCoor = x; xCoor < x + this.Width ; xCoor++) { double adjustedXCoor = xCoor * Constants.TextureSpacing; painted = false; for(int yCoor = y; yCoor < y + this.Height; yCoor++) { double adjustedYCoor = yCoor * Constants.TextureSpacing; Pair<double, double> point = new Multibrush.Pair<double, double>(adjustedXCoor, adjustedYCoor); if (linesegment.distance(point) <= inner) { coverage = ran.Next(1, 100); if (coverage <= texture.Coverage) { if (firstCheck) { firstCheck = false; painted = true; if (this.TextureNames.Count >= 6) return; this.TextureNames.Add(texture.ToString()); channel = this.TextureNames.Count - 1; } try { this[xCoor % this.Width, yCoor % this.Height, channel] = (byte)(presure * 255f); } catch (Exception e) { throw new Exception("DDSGroup error: X:" + xCoor + ", Y:" + yCoor +" Channel: " + channel + ". Error Message: " + e.Message); } } /* Since we are going over this in a linear fashion, we if we ever paint something, and then stop painting, then we can be sure that we do not need to paint any more */ } else if (painted) { break; } } } } }
public void ApplyTextureAsNewChannel(int x, int y, textureData texture, Multibrush.Triangle inside, Rectangle coverRectangle, Random ran) { Rectangle rec = new Rectangle(x, y, this.Width, this.Height); int channel = 0; int coverage = 0; bool firstCheck = true; double presure = (float)texture.Presure / 100.0; if (coverRectangle.IntersectsWith(rec)) { for(int xCoor = x; xCoor < x + this.Width ; xCoor++) { double adjustedXCoor = xCoor * Constants.TextureSpacing; for(int yCoor = y; yCoor < y + this.Height; yCoor++) { double adjustedYCoor = yCoor * Constants.TextureSpacing; if (inside.insideTriangle(new Pair<double, double>(adjustedXCoor, adjustedYCoor))) { coverage = ran.Next(1, 100); if (coverage <= texture.Coverage) { if (firstCheck) { firstCheck = false; if (this.TextureNames.Count >= 6) return; this.TextureNames.Add(texture.ToString()); channel = this.TextureNames.Count - 1; } try { this[xCoor % this.Width, yCoor % this.Height, channel] = (byte)(presure * 255f); } catch (Exception e) { throw new Exception("DDSGroup error: X:" + xCoor + ", Y:" + yCoor +" Channel: " + channel + ". Error Message: " + e.Message); } } } } } } }
/// <summary> /// The code for painting on-line3 /// </summary> /// <param name="X"></param> /// <param name="Y"></param> private void TerrianCode(int X, int Y) { try { areaViewer = getAreaViewer(); SFX.YATT.Tools.Vector <float> coor = findAreaCoor(X, Y, areaViewer.Area); Random ran = new Random(); if (coor != null) { NWN2ToolsetMainForm.App.TerrainEditor.SetBrushType(NWN2TerrainEditorForm.BrushType.StandardTerrain); // Textures: opTexture.Checked = true; if (data.randomize) { ran = new Random(System.DateTime.Now.Millisecond); ArrayList texData = new ArrayList(data.textures.Count); texData.AddRange(data.textures); while (texData.Count > 0) { int num = ran.Next(0, texData.Count - 1); textureData texture = (textureData)texData[num]; texturePreperation(coor, TerrainModificationType.Texture, texture); texData.RemoveAt(num); } } else { LinkedListNode <textureData> node = data.textures.Last; while (node != null) { DateTime dateTime = DateTime.Now; double start = ((double)dateTime.Ticks) / 1000000.0; texturePreperation(coor, TerrainModificationType.Texture, node.Value); dateTime = DateTime.Now; node = node.Previous; } } if (data.grassOption == grassOption.Paint) { opGrass.Checked = true; barPressure.Value = data.grassDensity * 100; grassSize.Value = (data.grassSize / 30); grassSizeVariation.Value = (data.grassSizeVariation / 10); object[] objList = new object[grassListBox.Items.Count]; grassListBox.Items.CopyTo(objList, 0); int index = 0; grassListBox.SelectedIndices.Clear(); foreach (TextureListItem textureItem in objList) { string textStr = textureItem.Text; if (textStr == data.grassTexture[0] || textStr == data.grassTexture[1] || textStr == data.grassTexture[2]) { grassListBox.SelectedItem = textureItem; index++; if (index == 3) { break; } } } NWN2ToolsetMainForm.App.TerrainEditor.SetBrushType(NWN2TerrainEditorForm.BrushType.FloraGrass); texturePreperation(coor, TerrainModificationType.Grass, data.textures.First.Value); } if (data.colourOption == colourOption.Colour) { opTerrain.Checked = true; opColour.Checked = true; colourButton.BackColor = data.col; barPressure.Value = data.colourPresure * 100; texturePreperation(coor, TerrainModificationType.Color, data.textures.First.Value); } } } 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(); } }