예제 #1
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("}");
            }
        }
예제 #2
0
        private bool SectionFace(string[] tokens)
        {
            if (tokens[0] == "}")
            {
                return(false);
            }

            int nface = int.Parse(tokens[0]);

            {
                StringBuilder sb = new StringBuilder();
                foreach (string i in tokens)
                {
                    sb.Append(' ').Append(i);
                }
                string line = sb.ToString().Trim();
                tokens = SplitString(line);
            }
            switch (nface)
            {
            case 3:
            {
                MqoFace f = new MqoFace();

                for (int i = 1; i < tokens.Length; ++i)
                {
                    string t  = tokens[i];
                    string t2 = t.ToLower();

                    if (t2.StartsWith("v("))
                    {
                        string[] t3 = SplitParam(t);
                        f.a = ushort.Parse(t3[1]);
                        f.b = ushort.Parse(t3[2]);
                        f.c = ushort.Parse(t3[3]);
                    }
                    else
                    if (t2.StartsWith("m("))
                    {
                        string[] t3 = SplitParam(t);
                        f.mtl = ushort.Parse(t3[1]);
                    }
                    else
                    if (t2.StartsWith("uv("))
                    {
                        string[] t3 = SplitParam(t);
                        f.ta = ParsePoint2(t3, 1);
                        f.tb = ParsePoint2(t3, 3);
                        f.tc = ParsePoint2(t3, 5);
                    }
                }
                current.faces.Add(f);
            }
            break;

            case 4:
            {
                MqoFace f  = new MqoFace();
                MqoFace f2 = new MqoFace();

                for (int i = 1; i < tokens.Length; ++i)
                {
                    string t  = tokens[i];
                    string t2 = t.ToLower();

                    if (t2.StartsWith("v("))
                    {
                        string[] t3 = SplitParam(t);
                        f.a  = ushort.Parse(t3[1]);
                        f.b  = ushort.Parse(t3[2]);
                        f.c  = ushort.Parse(t3[3]);
                        f2.a = f.a;
                        f2.b = f.c;
                        f2.c = ushort.Parse(t3[4]);
                    }
                    else
                    if (t2.StartsWith("m("))
                    {
                        string[] t3 = SplitParam(t);
                        f.mtl  = ushort.Parse(t3[1]);
                        f2.mtl = f.mtl;
                    }
                    else
                    if (t2.StartsWith("uv("))
                    {
                        string[] t3 = SplitParam(t);
                        f.ta  = ParsePoint2(t3, 1);
                        f.tb  = ParsePoint2(t3, 3);
                        f.tc  = ParsePoint2(t3, 5);
                        f2.ta = f.ta;
                        f2.tb = f.tc;
                        f2.tc = ParsePoint2(t3, 7);
                    }
                }
                current.faces.Add(f);
                current.faces.Add(f2);
            }
            break;
            }
            return(true);
        }