public TMTerrainDesc(DatLoader.Entity.TMTerrainDesc terrainDesc) { _terrainDesc = terrainDesc; TerrainType = (LandDefs.TerrainType)terrainDesc.TerrainType; TerrainTex = new TerrainTex(_terrainDesc.TerrainTex); }
private void list_SelectedIndexChanged(object sender, EventArgs e) { if (list.SelectedItem != null) { UpdateImage(TerrainTex.Get(list.SelectedItem.ToString())); } }
private void br_CheckedChanged(object sender, EventArgs e) { if (be.Checked) { PatchMap.SelectedColor = PatchMap.BLACK; return; } if (br.Checked) { PatchMap.SelectedColor = PatchMap.RED; tiles.Text = PatchMap.CurrentInfo.RTiles[PatchMap.SelectedLayer - 1].ToString(); list.SelectedItem = TerrainTex.Get(PatchMap.CurrentInfo.R[PatchMap.SelectedLayer - 1]); } if (bg.Checked) { PatchMap.SelectedColor = PatchMap.GREEN; tiles.Text = PatchMap.CurrentInfo.GTiles[PatchMap.SelectedLayer - 1].ToString(); list.SelectedItem = TerrainTex.Get(PatchMap.CurrentInfo.G[PatchMap.SelectedLayer - 1]); } if (bb.Checked) { PatchMap.SelectedColor = PatchMap.BLUE; tiles.Text = PatchMap.CurrentInfo.BTiles[PatchMap.SelectedLayer - 1].ToString(); list.SelectedItem = TerrainTex.Get(PatchMap.CurrentInfo.B[PatchMap.SelectedLayer - 1]); } UpdateImage(null); }
public static TMTerrainDesc Read(StreamReader data, StreamWriter outputData, bool write = true) { TMTerrainDesc obj = new TMTerrainDesc(); obj.terrainType = Utils.readAndWriteUInt32(data, outputData, write); obj.terrainTex = TerrainTex.Read(data, outputData, write); return(obj); }
private void l1_CheckedChanged(object sender, EventArgs e) { //Selected layer? int l = 1; if (l1.Checked) { l = 1; } else if (l2.Checked) { l = 2; } else if (l3.Checked) { l = 3; } else if (l4.Checked) { l = 4; } else if (l5.Checked) { l = 5; } PatchMap.SelectedLayer = l; //Black if (l == 1) { be.Checked = false; be.Enabled = false; be.Visible = false; br.Checked = true; } else { be.Enabled = true; be.Visible = true; be.Checked = true; } lr.Text = TerrainTex.Get(PatchMap.CurrentInfo.R[l - 1]); lg.Text = TerrainTex.Get(PatchMap.CurrentInfo.G[l - 1]); lb.Text = TerrainTex.Get(PatchMap.CurrentInfo.B[l - 1]); }
public static TerrainTex Read(StreamReader data, StreamWriter outputData, bool write = true) { TerrainTex obj = new TerrainTex(); obj.TexGID = Utils.readAndWriteUInt32(data, outputData, write); obj.TexTiling = Utils.readAndWriteUInt32(data, outputData, write); obj.MaxVertBright = Utils.readAndWriteUInt32(data, outputData, write); obj.MinVertBright = Utils.readAndWriteUInt32(data, outputData, write); obj.MaxVertSaturate = Utils.readAndWriteUInt32(data, outputData, write); obj.MinVertSaturate = Utils.readAndWriteUInt32(data, outputData, write); obj.MaxVertHue = Utils.readAndWriteUInt32(data, outputData, write); obj.MinVertHue = Utils.readAndWriteUInt32(data, outputData, write); obj.DetailTexTiling = Utils.readAndWriteUInt32(data, outputData, write); obj.DetailTexGID = Utils.readAndWriteUInt32(data, outputData, write); return(obj); }
private void bChange_Click(object sender, EventArgs e) { if (list.SelectedItem == null) { return; } string file = list.SelectedItem.ToString(); Texture t = TerrainTex.Get(file); int val; if (!int.TryParse(tiles.Text, out val) || val <= 0) { val = 256; } tiles.Text = val.ToString(); if (br.Checked) { PatchMap.CurrentInfo.R[PatchMap.SelectedLayer - 1] = t; PatchMap.CurrentInfo.RTiles[PatchMap.SelectedLayer - 1] = val; } if (bg.Checked) { PatchMap.CurrentInfo.G[PatchMap.SelectedLayer - 1] = t; PatchMap.CurrentInfo.GTiles[PatchMap.SelectedLayer - 1] = val; } if (bb.Checked) { PatchMap.CurrentInfo.B[PatchMap.SelectedLayer - 1] = t; PatchMap.CurrentInfo.BTiles[PatchMap.SelectedLayer - 1] = val; } UpdateData(); UpdateImage(null); }
/// <summary> /// Init /// </summary> public static void Init() { if (m_Shader != null) { return; } //Init string err; string shaderSrc = Encoding.Default.GetString(Resources.patchmap); Effect s = Effect.FromString(Program.FORM.renderControl1.DEVICE, shaderSrc, null, null, ShaderFlags.Debug, null, out err); if (s == null || !string.IsNullOrEmpty(err)) { // There are Compilation errors show them and then close app MessageBox.Show(err ?? "ERROR"); return; } s.Technique = "PM"; var sh = new Shader(); sh.Effect = s; sh.Patch = sh.Effect.GetParameter(null, "tex"); sh.R = sh.Effect.GetParameter(null, "texR"); sh.G = sh.Effect.GetParameter(null, "texG"); sh.B = sh.Effect.GetParameter(null, "texB"); sh.RTiles = sh.Effect.GetParameter(null, "numR"); sh.GTiles = sh.Effect.GetParameter(null, "numG"); sh.BTiles = sh.Effect.GetParameter(null, "numB"); sh.Layer = sh.Effect.GetParameter(null, "layer"); m_Shader = sh; effCursor = s.GetParameter(null, "cursor"); effRadius = s.GetParameter(null, "radius"); effMode = s.GetParameter(null, "mode"); effBorders = s.GetParameter(null, "border"); //Load patchmap data.. string pTer = Program.ZONE.PATH + string.Format(@"\ter{0}.mpk\", Program.ZONE.ZoneID.ToString("D3")); var r = new StreamReader(pTer + "textures.csv"); r.ReadLine(); int cX = -1; int cY = -1; PatchMapInfo cur = null; while (!r.EndOfStream) { string l = r.ReadLine(); if (String.IsNullOrEmpty(l)) { continue; } string[] split = l.Split(','); int pX = int.Parse(split[0]); int pY = int.Parse(split[1]); string tex = split[2] + ".dds"; float tiles = int.Parse(split[9]); if (cX != pX || cY != pY || cur == null) { cur = new PatchMapInfo(); cur.Exists = true; cur.X = pX; cur.Y = pY; cur.Changed = false; m_PatchInfos[pX, pY] = cur; cX = pX; cY = pY; string ppp = pTer + "patch{0:D2}{1:D2}-{2:D2}.dds"; for (int i = 0; i < COUNT; i++) { if (File.Exists(string.Format(ppp, pX, pY, i))) { Texture p = LocalTextures.Get(string.Format(ppp, pX, pY, i), false); cur.Patch[i] = p; } } } Texture t = TerrainTex.Get(tex); float n = tiles; for (int i = 0; i < COUNT; i++) { if (cur.R[i] == null) { cur.R[i] = t; cur.RTiles[i] = n; break; } if (cur.G[i] == null) { cur.G[i] = t; cur.GTiles[i] = n; break; } if (cur.B[i] == null) { cur.B[i] = t; cur.BTiles[i] = n; break; } } } r.Close(); //Cur Thingies SelectCurrent(0, 0); SelectedLayer = 1; SelectedColor = Color.Red; }
/// <summary> /// Draw /// </summary> /// <param name="mX"></param> /// <param name="mY"></param> public static void Paint(int mX, int mY) { Program.TexturTool.eGradient mode = Program.TOOL_TEXTURE.PaintMode; int radius = Program.TOOL_TEXTURE.Radius; m_Changed = true; string curTex = null; if (Program.TOOL_TEXTURE.IntelligentLayers) { curTex = TerrainTex.Get(GetTex(CurrentInfo, SelectedLayer, SelectedColor)); } foreach (PatchMapInfo info in m_PatchInfos) { int cx = mX - info.X * 8192; int cy = mY - info.Y * 8192; if (Program.TOOL_TEXTURE.LimitSubzones) { if (cx < 0 || cy < 0 || cx >= 8192 || cy >= 8192) { continue; } } if (SelectedLayer < 1 || SelectedLayer > COUNT) { return; } if (!(radius > 4096 || (cx >= 0 && cy >= 0 && cx < 8192 && cy < 8192) || info.Exists)) { continue; } int layer = SelectedLayer; Color col = SelectedColor; //Intelligent Layers.. if (!string.IsNullOrEmpty(curTex)) { //1. Look for exact match if (TerrainTex.Get(GetTex(info, layer, col)) != curTex) { bool found = false; //2. Look for alternative for (int i = 1; i <= COUNT; i++) { for (int cc = 1; cc <= 3; cc++) { Color ccc = BLACK; switch (cc) { case 1: ccc = RED; break; case 2: ccc = GREEN; break; case 3: ccc = BLUE; break; } if (TerrainTex.Get(GetTex(info, i, ccc)) == curTex) { layer = i; col = ccc; found = true; break; } } } if (!found) { continue; //next map } } } Texture t = info.Patch[layer - 1]; if (t == null) { t = new Texture(Program.FORM.renderControl1.DEVICE, 256, 256, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default); Surface ss = t.GetSurfaceLevel(0); Graphics gg = ss.GetGraphics(); Color cc = layer > 1 ? Color.Black : Color.Red; gg.FillRectangle(new SolidBrush(cc), 0, 0, t.GetLevelDescription(0).Width, t.GetLevelDescription(0).Height); ss.ReleaseGraphics(); info.Patch[layer - 1] = t; } lock (info) { info.Changed = true; } Surface s = t.GetSurfaceLevel(0); SurfaceDescription sd = s.Description; int alpha = Math.Min(Program.TOOL_TEXTURE.Strength, 255); Color c = Color.FromArgb(alpha, col); Graphics g; try { g = s.GetGraphics(); } catch (Exception) { return; //Cancel this tick } g.SmoothingMode = SmoothingMode.AntiAlias; //g.CompositingMode = CompositingMode.SourceOver; int px = cx * sd.Width / 8192; int py = cy * sd.Height / 8192; int relX = radius * sd.Width / 8192; int relY = radius * sd.Height / 8192; relX = Math.Max(relX, 1); relY = Math.Max(relY, 1); Brush b = new SolidBrush(c); if (mode != 0) { //Paths.. var ell = new GraphicsPath(); ell.AddEllipse(px - relX, py - relY, relX * 2, relY * 2); var GradientShaper = new PathGradientBrush(ell); var GradientSpecifications = new ColorBlend(3); float intens = 0.5f; if (mode == Program.TexturTool.eGradient.Cubic) { intens = 0.25f; } GradientSpecifications.Positions = new[] { 0, intens, 1 }; GradientSpecifications.Colors = new[] { Color.FromArgb(0, c), Color.FromArgb(alpha / 2, c), Color.FromArgb(alpha, c) }; // Pass off color blend to PathGradientBrush to instruct it how to generate the gradient GradientShaper.InterpolationColors = GradientSpecifications; // Draw polygon (circle) using our point array and gradient brush g.FillPolygon(GradientShaper, ell.PathPoints); } else { g.FillEllipse(b, px - relX, py - relY, relX * 2, relY * 2); } s.ReleaseGraphics(); } }
/// <summary> /// Save /// </summary> /// <param name="path"></param> /// <param name="backup"></param> public static void Save(string path, bool backup) { if (m_Shader == null || !m_Changed) { return; //not even loaded... } if (!backup) { m_Changed = false; } bool changed = false; #region patchmaps Loading.Update("Saving " + Path.GetFileName(path) + " - Patchmaps"); foreach (PatchMapInfo pi in m_PatchInfos) { if (!pi.Changed) { continue; } pi.Exists = true; changed = true; if (!backup) { pi.Changed = false; } for (int i = 0; i < COUNT; i++) { if (pi.Patch[i] != null) { Texture p = pi.Patch[i]; string pp = path + string.Format("patch{0:D2}{1:D2}-{2:D2}.dds", pi.X, pi.Y, i); TextureLoader.Save(pp, ImageFileFormat.Dds, p); //Mips try { using ( Texture mip = TextureLoader.FromFile(p.Device, pp, 0, 0, 0, Usage.Dynamic, Format.A8R8G8B8, Pool.Default, Filter.Linear, Filter.Linear, 0)) { //mip.GenerateMipSubLevels(); TextureLoader.Save(pp, ImageFileFormat.Dds, mip); mip.Dispose(); } } catch (Exception ex) { CrashDialog.Show(ex); } } } } #endregion #region textures.csv if (changed) { Loading.Update("Saving " + Path.GetFileName(path) + "... - textures.csv"); var w = new StreamWriter(string.Format("{0}textures.csv", path), false); w.WriteLine( "patch x,patch y,base texture filename,rotate,u translate,v translate,u scale,v scale,visible,num tiles,tileable,normal map filename,specular tint color,specular power,mask type,mask window size"); w.WriteLine(); for (int y = 0; y < m_PatchInfos.GetLength(1); y++) { for (int x = 0; x < m_PatchInfos.GetLength(0); x++) { PatchMapInfo i = m_PatchInfos[x, y]; const string format = "{0},{1},{2},0.00,0.00,0.00,1.00,1.00,1,{3},{4},,0,32.0,0,16"; for (int j = 0; j < COUNT; j++) { if (i.Patch[j] != null) { w.WriteLine(string.Format(format, x, y, Path.GetFileNameWithoutExtension(TerrainTex.Get(i.R[j])), i.RTiles[j], i.RTiles[j] > 1 ? "1" : "0")); w.WriteLine(string.Format(format, x, y, Path.GetFileNameWithoutExtension(TerrainTex.Get(i.G[j])), i.GTiles[j], i.GTiles[j] > 1 ? "1" : "0")); w.WriteLine(string.Format(format, x, y, Path.GetFileNameWithoutExtension(TerrainTex.Get(i.B[j])), i.BTiles[j], i.BTiles[j] > 1 ? "1" : "0")); w.WriteLine(); } } } } w.Flush(); w.Close(); } #endregion }