예제 #1
0
        private void pictureBox_thumbnail_Click(object sender, EventArgs e)
        {
            var pic = (PictureBox)sender;

            var ofd = new OpenFileDialog();

            ofd.Filter = "画像ファイル|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.tga|すべてのファイル|*.*";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var bitmap = Util.FromImageFile(ofd.FileName);

            if (bitmap == null)
            {
                MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            pic.Image = bitmap;

            var buf = Util.FromBitmap(bitmap);
            var tex = new NwTexture2D()
            {
                Image = buf,
                Hash  = Util.ComputeHash(buf, 12),
                Name  = Path.GetFileNameWithoutExtension(ofd.FileName),
            };

            if (!textures.Exists(t => t.Hash == tex.Hash))
            {
                textures.Add(tex);
            }
        }
예제 #2
0
        public static Texture2D FromNwTexture2D(NwTexture2D tex)
        {
            var bm = Util.ToBitmap(tex.Image);

            var t = new Texture2D(bm, tex.Name, false);

            return(t);
        }
예제 #3
0
        public static NwTexture2D ToNwTexture2D(Bitmap bitmap, string name)
        {
            var bm = new NwTexture2D();

            bm.Name  = name;
            bm.Image = Util.FromBitmap(bitmap);
            bm.Hash  = Util.ComputeHash(bm.Image, 12);

            return(bm);
        }
예제 #4
0
        private void pictureBox_Click(object sender, EventArgs e)
        {
            var pic = (PictureBox)sender;

            var ofd = new OpenFileDialog();

            ofd.Filter = "画像ファイル|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.tga|すべてのファイル|*.*";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var bitmap = Util.FromImageFile(ofd.FileName);

            if (bitmap == null)
            {
                MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            pic.Image = bitmap;
            game.SetTexture(listBox_material.SelectedIndex, (string)pic.Tag, bitmap);

            var buf = Util.FromBitmap(bitmap);
            var tex = new NwTexture2D()
            {
                Image = buf,
                Hash  = Util.ComputeHash(buf, 12),
                Name  = Path.GetFileNameWithoutExtension(ofd.FileName),
            };

            var find = textures.Find(t => t.Hash == tex.Hash);

            if (find == null)
            {
                textures.Add(tex);
            }

            var    mat  = listBox_material.SelectedItem as NwMaterial;
            string hash = null;

            mat.Texture2Ds.TryGetValue((string)pic.Tag, out hash);
            if (find == null && hash == null)
            {
                mat.Texture2Ds[(string)pic.Tag] = tex.Hash;
            }
            else if (find != null && hash == null)
            {
                mat.Texture2Ds[(string)pic.Tag] = find.Hash;
            }
            else if (find != null && hash != null)
            {
                mat.Texture2Ds.Remove((string)pic.Tag);
                mat.Texture2Ds[(string)pic.Tag] = find.Hash;
            }
            else if (find == null && hash != null)
            {
                mat.Texture2Ds.Remove((string)pic.Tag);
                mat.Texture2Ds[(string)pic.Tag] = tex.Hash;
            }
        }