Example #1
0
 internal static MQOFace parse(MQOObject mobj, string str)
 {
     MatchCollection mc;
     Match m = MQORegex.Face.Match(str);
     if (!m.Success) return null;
     int n = int.Parse(m.Groups[1].Value);
     MQOFace f = new MQOFace();
     f.VertexID = new int[n];
     f.UVID = new int[n];
     f.MatID = -1;
     bool noUV = true;
     foreach(Match p in MQORegex.Param.Matches(m.Groups[2].Value))
     {
         switch (p.Groups["key"].Value)
         {
             case "M":
                 f.MatID = int.Parse(p.Groups["val"].Value);
                 break;
             case "V":
                 mc = MQORegex.Decimal.Matches(p.Groups["val"].Value);
                 if (mc.Count != n) { f.Dispose(); return null; }
                 for (int i = 0; i < n; i++) f.VertexID[i] = int.Parse(mc[i].Value);
                 break;
             case "UV":
                 mc = MQORegex.Decimal.Matches(p.Groups["val"].Value);
                 if (mc.Count != 2*n) { f.Dispose(); return null; }
                 noUV = false;
                 for (int i = 0; i < n; i++) f.UVID[i] = mobj.getUVIndex(Decimal.Parse(mc[2*i].Value), Decimal.Parse(mc[2*i+1].Value));
                 break;
         }
     }
     // UVがない場合は(0,0)を割り当てる
     if (noUV) for (int i = 0; i < n; i++) f.UVID[i] = mobj.getUVIndex(0, 0);
     return f;
 }
Example #2
0
        internal List <MQOFace> triangle_divide()
        {
            var tri = new List <MQOFace>();

            switch (VertexID.Length)
            {
            case 3:
                tri.Add(this);
                break;

            case 4:
                var f = new MQOFace();
                f.MatID    = MatID;
                f.VertexID = new int[] { VertexID[0], VertexID[1], VertexID[2] };
                f.UVID     = new int[] { UVID[0], UVID[1], UVID[2] };
                tri.Add(f);
                f          = new MQOFace();
                f.MatID    = MatID;
                f.VertexID = new int[] { VertexID[0], VertexID[2], VertexID[3] };
                f.UVID     = new int[] { UVID[0], UVID[2], UVID[3] };
                tri.Add(f);
                break;
            }
            return(tri);
        }
Example #3
0
 internal bool parseFace(TextReader tr, bool triangle_only = false)
 {
     while (true)
     {
         string str = tr.ReadLine().Trim();
         if (str.EndsWith("}"))
         {
             return(true);
         }
         else
         {
             MQOFace f = MQOFace.parse(this, str);
             if (f == null)
             {
                 return(false);
             }
             if (triangle_only)
             {
                 Face.AddRange(f.triangle_divide());
             }
             else
             {
                 Face.Add(f);
             }
             continue;
         }
     }
 }
Example #4
0
 internal List<MQOFace> triangle_divide()
 {
     var tri = new List<MQOFace>();
     switch (VertexID.Length)
     {
         case 3:
             tri.Add(this);
             break;
         case 4:
             var f = new MQOFace();
             f.MatID = MatID;
             f.VertexID = new int[]{VertexID[0], VertexID[1], VertexID[2]};
             f.UVID = new int[] { UVID[0], UVID[1], UVID[2] };
             tri.Add(f);
             f = new MQOFace();
             f.MatID = MatID;
             f.VertexID = new int[]{VertexID[0], VertexID[2], VertexID[3]};
             f.UVID = new int[] { UVID[0], UVID[2], UVID[3] };
             tri.Add(f);
             break;
     }
     return tri;
 }
Example #5
0
        internal static MQOFace parse(MQOObject mobj, string str)
        {
            MatchCollection mc;
            Match           m = MQORegex.Face.Match(str);

            if (!m.Success)
            {
                return(null);
            }
            int     n = int.Parse(m.Groups[1].Value);
            MQOFace f = new MQOFace();

            f.VertexID = new int[n];
            f.UVID     = new int[n];
            f.MatID    = -1;
            bool noUV = true;

            foreach (Match p in MQORegex.Param.Matches(m.Groups[2].Value))
            {
                switch (p.Groups["key"].Value)
                {
                case "M":
                    f.MatID = int.Parse(p.Groups["val"].Value);
                    break;

                case "V":
                    mc = MQORegex.Decimal.Matches(p.Groups["val"].Value);
                    if (mc.Count != n)
                    {
                        f.Dispose(); return(null);
                    }
                    for (int i = 0; i < n; i++)
                    {
                        f.VertexID[i] = int.Parse(mc[i].Value);
                    }
                    break;

                case "UV":
                    mc = MQORegex.Decimal.Matches(p.Groups["val"].Value);
                    if (mc.Count != 2 * n)
                    {
                        f.Dispose(); return(null);
                    }
                    noUV = false;
                    for (int i = 0; i < n; i++)
                    {
                        f.UVID[i] = mobj.getUVIndex(Decimal.Parse(mc[2 * i].Value), Decimal.Parse(mc[2 * i + 1].Value));
                    }
                    break;
                }
            }
            // UVがない場合は(0,0)を割り当てる
            if (noUV)
            {
                for (int i = 0; i < n; i++)
                {
                    f.UVID[i] = mobj.getUVIndex(0, 0);
                }
            }
            return(f);
        }