HelixToolkit.Wpf.ObjReader.Read C# (CSharp) Method

Read() public method

Reads the model from the specified stream.
public Read ( Stream s ) : System.Windows.Media.Media3D.Model3DGroup
s Stream The stream.
return System.Windows.Media.Media3D.Model3DGroup
        public override Model3DGroup Read(Stream s)
        {
            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);

                    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;
                    }
                }
            }

            return this.BuildModel();
        }

Same methods

ObjReader::Read ( string path ) : System.Windows.Media.Media3D.Model3DGroup

Usage Example

 public void Read_CornellBox_ValidModel()
 {
     var r = new ObjReader();
     var model = r.Read(@"Models\obj\cornell_box.obj");
     Assert.AreEqual(9, model.Children.Count);
     var gm1 = model.Children[1] as GeometryModel3D;
     Assert.NotNull(gm1);
     var mg1 = gm1.Geometry as MeshGeometry3D;
     Assert.NotNull(mg1);
     //// Assert.AreEqual(69451, mg1.TriangleIndices.Count / 3);
 }
All Usage Examples Of HelixToolkit.Wpf.ObjReader::Read