示例#1
0
        private void btnTexSave_Click(object sender, EventArgs e)
        {
            TSOTex tex = GetSelectedTexture();

            if (tex == null)
            {
                return;
            }

            saveFileDialog1.FileName = tex.FileName.Trim('"');
            saveFileDialog1.Filter   = "Texture files (*.tga;*.bmp)|*.tga;*.bmp|All files (*.*)|*.*";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string ext = Path.GetExtension(saveFileDialog1.FileName).ToLower();
                using (BinaryWriter bw = new BinaryWriter(saveFileDialog1.OpenFile()))
                {
                    if (ext == ".tga")
                    {
                        tex.SaveTGA(bw);
                    }
                    else
                    if (ext == ".bmp")
                    {
                        tex.SaveBMP(bw);
                    }
                }
            }
        }
示例#2
0
        // テクスチャを指定し、Bitmapとして記憶し、参照可能なようにインデックス
        // をつける。ただし、以前記憶したものの中に同じBitmapがあるなら、新規の
        // Bitmapは作成せず、インデックスのみつける。
        public void Add(TSOTex tex, int tso_id)
        {
            // 幅が0な、不正なテクスチャの場合処理しない
            if (tex.width == 0 || tex.height == 0)
            {
                return;
            }

            // byte列をBitmapに変換
            Bitmap bmp = new Bitmap(tex.width, tex.height);

            ByteArray2Bitmap(tex.data, bmp);

            // bmp_listと比較して、同じものがあればそれのアドレスのみ参照しておく
            foreach (Bitmap tmp_bmp in bmp_list)
            {
                if (EqualBitmap(bmp, tmp_bmp) == 0)
                {
                    bmp_index.Add(tso_id.ToString() + "-" + tex.Name, tmp_bmp);
                    return;
                }
            }

            // 同じものがなければ、新規にbmp_listにBitmapを追加
            bmp_list.Add(bmp);
            bmp_index.Add(tso_id.ToString() + "-" + tex.Name, bmp);

            // 同時にこれを出力するときのファイル名を作成
            file_name.Add(bmp, "t" + (bmp_list.Count - 1).ToString("000") + ".bmp");
        }
示例#3
0
        private void btnTexLoad_Click(object sender, EventArgs e)
        {
            TSOTex tex = GetSelectedTexture();

            if (tex == null)
            {
                return;
            }

            openFileDialog1.FileName = tex.FileName.Trim('"');
            openFileDialog1.Filter   = "Texture files (*.tga;*.bmp)|*.tga;*.bmp|All files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string ext = Path.GetExtension(openFileDialog1.FileName).ToLower();
                using (BinaryReader br = new BinaryReader(openFileDialog1.OpenFile()))
                {
                    if (ext == ".tga")
                    {
                        tex.LoadTGA(br);
                    }
                    else
                    if (ext == ".bmp")
                    {
                        tex.LoadBMP(br);
                    }
                }
                pbTexThumbnail.Image = GetImage(tex);
                if (OpenTextureEvent != null)
                {
                    OpenTextureEvent(this, EventArgs.Empty);
                }
            }
        }
示例#4
0
        private void lvTextures_SelectedIndexChanged(object sender, EventArgs e)
        {
            TSOTex tex = GetSelectedTexture();

            if (tex == null)
            {
                return;
            }

            Debug.WriteLine("selected " + tex.Name);
            pbTexThumbnail.Image = GetImage(tex);
        }
示例#5
0
        public TSOTex GetSelectedTexture()
        {
            if (lvTextures.SelectedItems.Count == 0)
            {
                return(null);
            }

            ListViewItem li  = lvTextures.SelectedItems[0];
            TSOTex       tex = li.Tag as TSOTex;

            return(tex);
        }
示例#6
0
        static Image GetImage(TSOTex tex)
        {
            if (tex.data.Length == 0)
            {
                return(null);
            }
            Image        image;
            MemoryStream ms = new MemoryStream();

            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                tex.SaveBMP(bw);
                bw.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                image = Bitmap.FromStream(ms);
            }
            return(image);
        }
示例#7
0
        public void Add(TSOTex tso_tex, int tso_num)
        {
            if (tso_tex.width == 0 || tso_tex.height == 0)
            {
                return;
            }

            Bitmap bmp = new Bitmap(tso_tex.width, tso_tex.height);

            SetBitmapBytes(bmp, tso_tex.data);

            PMD_Texture tex = new PMD_Texture(GenName(tso_num, tso_tex.Name));

            tex.Bitmap = bmp;

            foreach (PMD_Texture other in items)
            {
                if (other.Bitmap != null && EqualBitmaps(bmp, other.Bitmap))
                {
                    map[tex.Code] = other;

                    if (use_spheremap && other.IsToon)
                    {
                        PMD_Texture tex_sphere = new PMD_Texture(GenName(tso_num, tso_tex.Name), tex);

                        map[tex_sphere.Code] = other.Sphere;
                    }
                    return;
                }
            }

            tex.SetID((sbyte)items.Count);
            items.Add(tex);
            map[tex.Code] = tex;

            if (use_spheremap && tex.IsToon)
            {
                PMD_Texture tex_sphere = new PMD_Texture(GenName(tso_num, tso_tex.Name), tex);

                tex_sphere.SetID((sbyte)items.Count);
                items.Add(tex_sphere);
                map[tex_sphere.Code] = tex_sphere;
            }
        }
示例#8
0
        public void SaveToMqo(TextWriter tw, TSOFile tso)
        {
            tw.WriteLine("Metasequoia Document");
            tw.WriteLine("Format Text Ver 1.0");
            tw.WriteLine("");
            tw.WriteLine("Scene {");
            tw.WriteLine("\tpos -7.0446 4.1793 1541.1764");
            tw.WriteLine("\tlookat 11.8726 193.8590 0.4676");
            tw.WriteLine("\thead 0.8564");
            tw.WriteLine("\tpich 0.1708");
            tw.WriteLine("\tortho 0");
            tw.WriteLine("\tzoom2 31.8925");
            tw.WriteLine("\tamb 0.250 0.250 0.250");
            tw.WriteLine("}");

            tw.WriteLine("Material {0} {{", tso.sub_scripts.Length);

            Dictionary <string, TSOTex> texmap = new Dictionary <string, TSOTex>();

            foreach (TSOTex tex in tso.textures)
            {
                texmap[tex.Name] = tex;
            }

            foreach (TSOSubScript sub in tso.sub_scripts)
            {
                TSOTex tex      = texmap[sub.shader.ColorTexName];
                string tex_file = tex.FileName.Trim('"');
                tex_file = Path.GetFileNameWithoutExtension(tex_file) + ".bmp";
                tw.WriteLine(
                    "\t\"{0}\" shader(3) col(1.00 1.00 1.00 1.00) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00) tex(\"{1}\")",
                    sub.Name, tex_file);
            }

            tw.WriteLine("}");

            foreach (TSOMesh mesh in tso.meshes)
            {
                tw.WriteLine("Object \"{0}\" {{", mesh.Name);
                tw.WriteLine("\tvisible {0}", 15);
                tw.WriteLine("\tlocking {0}", 0);
                tw.WriteLine("\tshading {0}", 1);
                tw.WriteLine("\tfacet {0}", 59.5);
                tw.WriteLine("\tcolor {0} {1} {2}", 0.898f, 0.498f, 0.698f);
                tw.WriteLine("\tcolor_type {0}", 0);

                Heap <UnifiedPositionVertex> vh = new Heap <UnifiedPositionVertex>();
                List <MqoFace> faces            = new List <MqoFace>();
                foreach (TSOSubMesh sub in mesh.sub_meshes)
                {
                    UnifiedPositionVertex[] vertices = new UnifiedPositionVertex[sub.vertices.Length];
                    for (int i = 0; i < vertices.Length; i++)
                    {
                        vertices[i] = new UnifiedPositionVertex(sub.vertices[i]);
                    }
                    for (int i = 2; i < vertices.Length; i++)
                    {
                        UnifiedPositionVertex va, vb, vc;
                        if (i % 2 == 0)
                        {
                            va = vertices[i - 2];
                            vb = vertices[i - 0];
                            vc = vertices[i - 1];
                        }
                        else
                        {
                            va = vertices[i - 2];
                            vb = vertices[i - 1];
                            vc = vertices[i - 0];
                        }

                        ushort a, b, c;
                        a = vh.Add(va);
                        b = vh.Add(vb);
                        c = vh.Add(vc);

                        if (a != b && b != c && c != a)
                        {
                            MqoFace f = new MqoFace();
                            f.a   = a;
                            f.b   = b;
                            f.c   = c;
                            f.ta  = new Vector2(va.u, 1 - va.v);
                            f.tb  = new Vector2(vb.u, 1 - vb.v);
                            f.tc  = new Vector2(vc.u, 1 - vc.v);
                            f.mtl = (ushort)sub.spec;
                            faces.Add(f);
                        }
                    }
                }
                tw.WriteLine("\tvertex {0} {{", vh.Count);
                foreach (UnifiedPositionVertex v in vh.ary)
                {
                    tw.WriteLine("\t\t{0:F6} {1:F6} {2:F6}", v.position.X, v.position.Y, v.position.Z);
                }
                tw.WriteLine("\t}");
                tw.WriteLine("\tface {0} {{", faces.Count);
                foreach (MqoFace f in faces)
                {
                    tw.WriteLine("\t\t{0} V({1} {2} {3}) M({10}) UV({4} {5} {6} {7} {8} {9})", 3, f.a, f.b, f.c, f.ta.X, f.ta.Y, f.tb.X, f.tb.Y, f.tc.X, f.tc.Y, f.mtl);
                }
                tw.WriteLine("\t}");
                tw.WriteLine("}");
            }
        }
示例#9
0
 /// <summary>
 /// 指定テクスチャを開き直します。
 /// </summary>
 /// <param name="tex">テクスチャ</param>
 public void OpenTexture(TSOTex tex)
 {
     tex.Open(device);
 }