예제 #1
0
        private bool SectionFace(string[] tokens)
        {
            if (tokens[0] == "}")
            {
                return(false);
            }

            if (3 != int.Parse(tokens[0]))
            {
                return(true);
            }

            StringBuilder sb = new StringBuilder();

            foreach (string i in tokens)
            {
                sb.Append(' ').Append(i);
            }

            string  line = sb.ToString().Trim();
            MqoFace f    = new MqoFace();

            tokens = SplitString(line);
            current.faces.Add(f);

            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 = Point2.Parse(t3, 1);
                    f.tb = Point2.Parse(t3, 3);
                    f.tc = Point2.Parse(t3, 5);
                }
            }

            return(true);
        }
예제 #2
0
        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];

                    if (t.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 (t.StartsWith("M("))
                    {
                        string[] t3 = SplitParam(t);
                        f.spec = ushort.Parse(t3[1]);
                    }
                    else if (t.StartsWith("UV("))
                    {
                        string[] t3 = SplitParam(t);
                        f.ta = Point2.Parse(t3, 1);
                        f.tb = Point2.Parse(t3, 3);
                        f.tc = Point2.Parse(t3, 5);
                    }
                }
                obj.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];

                    if (t.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 (t.StartsWith("M("))
                    {
                        string[] t3 = SplitParam(t);
                        f.spec  = ushort.Parse(t3[1]);
                        f2.spec = f.spec;
                    }
                    else if (t.StartsWith("UV("))
                    {
                        string[] t3 = SplitParam(t);
                        f.ta  = Point2.Parse(t3, 1);
                        f.tb  = Point2.Parse(t3, 3);
                        f.tc  = Point2.Parse(t3, 5);
                        f2.ta = f.ta;
                        f2.tb = f.tc;
                        f2.tc = Point2.Parse(t3, 7);
                    }
                }
                obj.faces.Add(f);
                obj.faces.Add(f2);
            }
            break;

            default:
                Console.WriteLine("unsupported: nface {0}", nface);
                break;
            }
            return(true);
        }