public void Add(MetalXTexture texture) { foreach (MetalXTexture mxt in items) { if (mxt.Name == texture.Name) { return; } } //if (items.Contains(texture)) //{ // return; //} items.Add(texture); }
public void Del(MetalXTexture texture) { items.Remove(texture); }
public void Add(MetalXTexture texture,string name) { texture.Name = name; items.Add(texture); }
private void ui_savepath_Click(object sender, EventArgs e) { List<string> dirName = new List<string>(); Util.EnumDir(textBox1.Text, dirName); foreach (string pName in dirName) { DirectoryInfo di = new DirectoryInfo(pName); FileInfo[] fis = di.GetFiles("*.png"); foreach (FileInfo fi in fis) { textBox1.Text = fi.FullName; textBox2.Text = System.IO.Path.GetDirectoryName(fi.FullName) + @"\" + System.IO.Path.GetFileNameWithoutExtension(fi.FullName) + ".MXT"; textBox5.Text = System.IO.Path.GetFileNameWithoutExtension(textBox1.Text); using (Image img = Image.FromFile(fi.FullName)) { pictureBox1.Size = img.Size; label1.Text = img.Size.ToString(); pictureBox1.Image = img; } using (MetalXTexture mxt = new MetalXTexture()) { mxt.Name = textBox5.Text; mxt.Size = pictureBox1.Size; mxt.TextureData = System.IO.File.ReadAllBytes(textBox1.Text); mxt.TileSize = new System.Drawing.Size(w, h); Util.SaveObject(textBox2.Text, mxt); } } } }
private void ui_save_Click(object sender, EventArgs e) { if (textBox2.Text == string.Empty) { return; } using (MetalXTexture mxt = new MetalXTexture()) { mxt.Name = textBox5.Text; mxt.Size = pictureBox1.Size; mxt.TextureData = System.IO.File.ReadAllBytes(textBox1.Text); mxt.TileSize = new System.Drawing.Size(w, h); Util.SaveObject(textBox2.Text, mxt); MessageBox.Show("输出成功"); } }
public MetalXTexture LoadDotMXTexture(Bitmap bm) { MetalXTexture texture = new MetalXTexture(); texture.MEMTexture = new Texture(Devices.D3DDev, bm, Usage.None, Pool.Managed); return texture; }
/// 加载.PNG文件 /// </summary> /// <param name="fileName">文件路径+文件名</param> /// <returns>MetalX纹理</returns> public MetalXTexture LoadDotPNG(string fileName, Size defTileSize) { MetalXTexture texture = new MetalXTexture(); texture.FileIndexer = new FileIndexer(fileName); texture.Name = texture.FileIndexer.FileName; texture.TextureData = System.IO.File.ReadAllBytes(fileName); Image img = Image.FromStream(new MemoryStream(texture.TextureData)); Bitmap bmp = new Bitmap(img); texture.Size = bmp.Size; //bmp.MakeTransparent(Color.Pink); texture.TileSize = defTileSize; //texture.MEMTexture = new Texture(g.Devices.D3DDev, bmp, Usage.None, Pool.Managed); texture.MEMTexture = TextureLoader.FromStream(Devices.D3DDev, new MemoryStream(texture.TextureData), texture.Size.Width, texture.Size.Height, 0, Usage.None, Microsoft.DirectX.Direct3D.Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, Color.Pink.ToArgb()); Bitmap bmp2x = new Bitmap(bmp.Size.Width * 2, bmp.Size.Height * 2); ////bmp2x.MakeTransparent(Color.Pink); //Graphics graph = Graphics.FromImage(bmp2x); //graph.InterpolationMode = InterpolationMode.NearestNeighbor; //graph.DrawImage(bmp, new Rectangle(new Point(), bmp2x.Size), new Rectangle(new Point(), bmp.Size), GraphicsUnit.Pixel); ////texture.MEMTexture2X = new Texture(g.Devices.D3DDev, bmp2x, Usage.None, Pool.Managed); //MemoryStream ms = new MemoryStream(); //bmp2x.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //ms.Position = 0; texture.MEMTexture2X = TextureLoader.FromStream(Devices.D3DDev, new MemoryStream(texture.TextureData), bmp2x.Width, bmp2x.Height, 0, Usage.None, Microsoft.DirectX.Direct3D.Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, Color.Pink.ToArgb()); bmp.Dispose(); img.Dispose(); bmp2x.Dispose(); //graph.Dispose(); //g.Textures.Add(texture); return texture; }
//public MetalXTexture LoadDotPNG(Bitmap bm, Size defTileSize) //{ // MetalXTexture texture = new MetalXTexture(); // Bitmap bmp = bm; // texture.SizePixel = bmp.Size; // texture.TileSizePixel = defTileSize; // texture.MEMTexture = new Texture(Devices.D3DDev, bmp, Usage.None, Pool.Managed); // Bitmap bmp2x = new Bitmap(bmp.Size.Width * 2, bmp.Size.Height * 2); // texture.MEMTexture2X = new Texture(Devices.D3DDev, bmp2x, Usage.None, Pool.Managed); // //texture.MEMTexture2X. // bmp.Dispose(); // //img.Dispose(); // bmp2x.Dispose(); // //graph.Dispose(); // //g.Textures.Add(texture); // return texture; //} /// <summary> /// 加载.MXT文件 /// </summary> /// <param name="fileName">文件路径+文件名</param> /// <returns>MetalX纹理</returns> public MetalXTexture LoadDotMXTexture(string fileName) { MetalXTexture texture = new MetalXTexture(); texture = (MetalXTexture)Util.LoadObject(fileName); texture.Init(Devices.D3DDev); return texture; }
public void DrawMetalXTexture(MetalXTexture t, Rectangle dz, Vector3 v3, Size size, float rotation, Color color) { if (Options.TextureDrawMode == TextureDrawMode.Direct3D) DrawMetalXTextureDirect3D(t, dz, v3, size, rotation, color); else if (Options.TextureDrawMode == TextureDrawMode.Direct2D) DrawMetalXTextureDirect2D(t, dz, Util.Vector32Point(v3), size, rotation, color); }
public void DrawMetalXTexture(MetalXTexture t, Rectangle dz, Point point, Size size, float rotation, Color color) { if (Options.TextureDrawMode == TextureDrawMode.Direct3D) DrawMetalXTextureDirect3D(t, dz, new Vector3(point.X, point.Y, 0), size, rotation, color); else if (Options.TextureDrawMode == TextureDrawMode.Direct2D) DrawMetalXTextureDirect2D(t, dz, point, size,rotation, color); }
/// <summary> /// 绘制MetalX格式纹理 /// </summary> /// <param name="t">MetalX格式纹理</param> /// <param name="loc">位置</param> /// <param name="c">颜色</param> void DrawMetalXTextureDirect3D(MetalXTexture t, Rectangle dz, Vector3 loc, Size size, float rotation, Color color) { if (Devices.D3DDev.Disposed) { return; } if (t == null) { return; } Devices.D3DDev.SetTexture(0, t.MEMTexture); int w, h; w = Devices.D3DDev.PresentationParameters.BackBufferWidth; h = Devices.D3DDev.PresentationParameters.BackBufferHeight; loc.X -= w / 2; loc.Y -= h / 2; loc.Y = -loc.Y; Size s = t.Size; float fx, fy, tx, ty; //if (Util.Is2PowSize(t.SizePixel)) //{ // fx = (float)dz.Left / (float)s.Width; // tx = (float)dz.Right / (float)s.Width; // fy = (float)dz.Top / (float)s.Height; // ty = (float)dz.Bottom / (float)s.Height; //} //else { fx = ((float)dz.Left + (float)Options.UVOffsetX) / (float)s.Width; tx = ((float)dz.Right + (float)Options.UVOffsetX) / (float)s.Width; fy = ((float)dz.Top + (float)Options.UVOffsetY) / (float)s.Height; ty = ((float)dz.Bottom + (float)Options.UVOffsetY) / (float)s.Height; } //Vector3 cp = new Vector3(0, 0, 0); Vector3 cp = loc; vertexs[0] = new CustomVertex.PositionColoredTextured(cp, color.ToArgb(), fx, fy); vertexs[1] = new CustomVertex.PositionColoredTextured(cp.X + size.Width, cp.Y - size.Height, cp.Z, color.ToArgb(), tx, ty); vertexs[2] = new CustomVertex.PositionColoredTextured(cp.X, cp.Y - size.Height, cp.Z, color.ToArgb(), fx, ty); vertexs[3] = new CustomVertex.PositionColoredTextured(cp, color.ToArgb(), fx, fy); vertexs[4] = new CustomVertex.PositionColoredTextured(cp.X + size.Width, cp.Y, cp.Z, color.ToArgb(), tx, fy); vertexs[5] = new CustomVertex.PositionColoredTextured(cp.X + size.Width, cp.Y - size.Height, cp.Z, color.ToArgb(), tx, ty); //loc = Util.Vector3MulInt(loc, 2); //Devices.D3DDev.Transform.World = Matrix.RotationX(0.5f); //Devices.D3DDev.Transform.World = Matrix.RotationX(-2); Devices.D3DDev.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertexs); //Devices.VertexBuffer.SetData(vertexs, 0, LockFlags.None); //Devices.D3DDev.DrawPrimitives(PrimitiveType.TriangleList, 0, 2); }
void DrawMetalXTextureDirect2D(MetalXTexture t, Rectangle dz, Point loc, Size size, float rotation, Color color) { if (Devices.D3DDev.Disposed) { return; } if (t == null) { return; } Texture mxt = null; if (dz.Width == 0) { return; } if (size.Width / dz.Width == 2) { dz.X = dz.X * 2; dz.Y = dz.Y * 2; dz.Size = size; mxt = t.MEMTexture2X; } else { dz.Size = size; mxt = t.MEMTexture; } Devices.Sprite.Draw(mxt, dz, new Vector3(), Util.Point2Vector3(loc), color); //Devices.Sprite.Draw2D(mxt, dz, new Rectangle(dz.Location, size), new Point(), 0, loc, color); }