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; }
internal string toString(MQOObject mqoObj) { StringBuilder sb = new StringBuilder(); string _space = ""; sb.Append(VertexID.Length); sb.Append(" V("); for (int i = 0; i < VertexID.Length; i++) { if (i > 0) { _space = " "; } sb.AppendFormat(_space + "{0}", VertexID[i]); } sb.AppendFormat(") M({0})", MatID); if (UVID.Length == VertexID.Length) { sb.Append(" UV("); for (int i = 0; i < UVID.Length; i++) { if (i > 0) { _space = " "; } sb.AppendFormat(_space + "{0}", mqoObj.UV[UVID[i]]); } sb.Append(")"); } return(sb.ToString()); }
internal string toString(MQOObject mqoObj) { StringBuilder sb = new StringBuilder(); sb.Append(VertexID.Length); sb.Append(" V("); for (int i = 0; i < VertexID.Length; i++) sb.AppendFormat(" {0}", VertexID[i]); sb.AppendFormat(") M({0})", MatID); if (UVID.Length == VertexID.Length) { sb.Append(" UV("); for (int i = 0; i < UVID.Length; i++) sb.AppendFormat(" {0}", mqoObj.UV[UVID[i]]); sb.Append(")"); } return sb.ToString(); }
private bool parse(TextReader tr, bool triangle_only = false) { try { if (!parseHeader(tr)) return false; string str; while ((str = tr.ReadLine()) != null) { str = str.Trim(); if (str.StartsWith("Eof")) return true; if (str.StartsWith("Scene")) { Scene = new MQOScene(); if (!Scene.parse(tr)) return false; continue; } if (str.StartsWith("BackImage")) { if (!parseBackImage(tr)) return false; continue; } if (str.StartsWith("Material")) { if (!parseMaterial(tr)) return false; continue; } if (str.StartsWith("Object")) { Match m = MQORegex.Object.Match(str); if (!m.Success) return false; MQOObject mo = new MQOObject(m.Groups[1].Value); if (!mo.parse(tr, triangle_only)) { mo.Dispose(); mo = null; return false; } Object.Add(mo); continue; } // unknown block if (str.EndsWith("{")) { if (!skipBlock(tr)) return false; continue; } // unknown line } // "Eof"行が出現する前に終端に達した場合 return false; } catch (Exception ex) { MessageBox.Show(ex.ToString(),"エラー",MessageBoxButtons.OK,MessageBoxIcon.Error); return false; } }
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); }
private bool parse(TextReader tr, bool triangle_only = false) { try { if (!parseHeader(tr)) { return(false); } string str; while ((str = tr.ReadLine()) != null) { str = str.Trim(); if (str.StartsWith("Eof")) { return(true); } if (str.StartsWith("Scene")) { Scene = new MQOScene(); if (!Scene.parse(tr)) { return(false); } continue; } if (str.StartsWith("BackImage")) { if (!parseBackImage(tr)) { return(false); } continue; } if (str.StartsWith("Material")) { if (!parseMaterial(tr)) { return(false); } continue; } if (str.StartsWith("Object")) { Match m = MQORegex.Object.Match(str); if (!m.Success) { return(false); } MQOObject mo = new MQOObject(m.Groups[1].Value); if (!mo.parse(tr, triangle_only)) { mo.Dispose(); mo = null; return(false); } Object.Add(mo); continue; } // unknown block if (str.EndsWith("{")) { if (!skipBlock(tr)) { return(false); } continue; } // unknown line } // "Eof"行が出現する前に終端に達した場合 return(false); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }