public Object3DGroup Read(Stream s, ModelInfo info = default(ModelInfo))
{
using (this.Reader = new StreamReader(s))
{
this.currentLineNo = 0;
while (!this.Reader.EndOfStream)
{
this.currentLineNo++;
var line = this.Reader.ReadLine();
if (line == null)
{
break;
}
line = line.Trim();
while (line.EndsWith("\\"))
{
var nextLine = this.Reader.ReadLine();
while (nextLine.Length == 0)
{
nextLine = this.Reader.ReadLine();
}
line = line.TrimEnd('\\') + nextLine;
}
if (line.StartsWith("#") || line.Length == 0)
{
continue;
}
string keyword, values;
SplitLine(line, out keyword, out values);
try
{
switch (keyword.ToLower())
{
// Vertex data
case "v": // geometric vertices
this.AddVertex(values);
break;
case "vt": // texture vertices
this.AddTexCoord(values);
break;
case "vn": // vertex normals
this.AddNormal(values);
break;
case "vp": // parameter space vertices
case "cstype": // rational or non-rational forms of curve or surface type: basis matrix, Bezier, B-spline, Cardinal, Taylor
case "degree": // degree
case "bmat": // basis matrix
case "step": // step size
// not supported
break;
// Elements
case "f": // face
this.AddFace(values);
break;
case "p": // point
case "l": // line
case "curv": // curve
case "curv2": // 2D curve
case "surf": // surface
// not supported
break;
// Free-form curve/surface body statements
case "parm": // parameter name
case "trim": // outer trimming loop (trim)
case "hole": // inner trimming loop (hole)
case "scrv": // special curve (scrv)
case "sp": // special point (sp)
case "end": // end statement (end)
// not supported
break;
// Connectivity between free-form surfaces
case "con": // connect
// not supported
break;
// Grouping
case "g": // group name
this.AddGroup(values);
break;
case "s": // smoothing group
this.SetSmoothingGroup(values);
break;
case "mg": // merging group
break;
case "o": // object name
// not supported
break;
// Display/render attributes
case "mtllib": // material library
this.LoadMaterialLib(values);
break;
case "usemtl": // material name
this.EnsureNewMesh();
this.SetMaterial(values);
break;
case "usemap": // texture map name
this.EnsureNewMesh();
break;
case "bevel": // bevel interpolation
case "c_interp": // color interpolation
case "d_interp": // dissolve interpolation
case "lod": // level of detail
case "shadow_obj": // shadow casting
case "trace_obj": // ray tracing
case "ctech": // curve approximation technique
case "stech": // surface approximation technique
// not supported
break;
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(string.Format("Error loading object: {0}", ex.Message), "Error", MessageBoxButton.OKCancel);
}
}
}
return this.BuildModel();
}