/// <summary> /// Parses and loads a line from an OBJ file. /// Currently only supports V, VT, F and MTLLIB prefixes /// </summary> private void processLine2(string line) { string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); gf CurrentGroup = Objects[Objects.Count - 1].groups[Objects[Objects.Count - 1].groups.Count - 1]; if (parts.Length > 0) { switch (parts[0]) { case "usemtl": UseMtl = parts[1]; break; case "mtllib": Mtl = parts[1]; break; case "v": Vertex v = new Vertex(); v.LoadFromStringArray(parts); VertexList.Add(v); v.Index = VertexList.Count(); //CurrentGroup.vertexList.Add(v); //v.Index = CurrentGroup.vertexList.Count(); break; case "f": Face f = new Face(); f.LoadFromStringArray(parts); f.UseMtl = UseMtl; //FaceList.Add(f); GroupFaces[GroupFaces.Count - 1].faces.Add(f); break; case "vt": TextureVertex vt = new TextureVertex(); vt.LoadFromStringArray(parts); TextureList.Add(vt); vt.Index = TextureList.Count(); break; case "g": if (gVerified) { GroupFaces.Add(new gf()); } else { gVerified = true; } GroupFaces[GroupFaces.Count - 1].name = parts[1]; break; case "o": //objects and groups are usually considered indetical, however objects in T2T are used to represent shapes, while groups are used to represent primitives //when an o is encountered, we create a new o into the object list and set our global o pointer to the newly made o //when we do the import, a group faces is a primitive so we can loop through all o's(shapes) and get all GroupFaces(primitives) //there is always a default group 0, and if the user imports an obj with no groups or objects, we just push them all into object 0 group 0 if (oVerified) { Objects.Add(new obj()); } else { oVerified = true; } Objects[Objects.Count - 1].name = parts[1]; Objects[Objects.Count - 1].groups.Add(GroupFaces[GroupFaces.Count - 1]); break; } } }
/// <summary> /// Parses and loads a line from an OBJ file. /// Currently only supports V, VT, F and MTLLIB prefixes /// </summary> private void processLine(string line) { string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { switch (parts[0]) { case "usemtl": UseMtl = parts[1]; if (CurrentGroup == null) { GroupFaces.Add(new gf()); CurrentGroup = GroupFaces[GroupFaces.Count - 1]; CurrentGroup.name = parts[1]; CurrentObject.groups.Add(CurrentGroup); } CurrentGroup.materialName = UseMtl; break; case "mtllib": Mtl = parts[1]; if (Mtl.IndexOf("\\") == -1) { Mtl = Path.GetDirectoryName(ObjPath) + "\\" + Mtl; } break; case "o": //check if we dont already have an active object, aka we arent on the first one if (oVerified) { Objects.Add(new obj()); } else { oVerified = true; } //set global to updated object CurrentObject = Objects[Objects.Count() - 1]; CurrentObject.name = parts[1]; //now any new v, vt, f or g will be added into this object break; case "v": Vertex v = new Vertex(); v.LoadFromStringArray(parts); //VertexList.Add(v); //v.Index = VertexList.Count(); //because we are now doing it my way, we only add to the current object CurrentObject.vertexList.Add(v); break; case "vt": TextureVertex vt = new TextureVertex(); vt.LoadFromStringArray(parts); CurrentObject.textureList.Add(vt); break; case "g": if (gVerified) { GroupFaces.Add(new gf()); } else { gVerified = true; } CurrentGroup = GroupFaces[GroupFaces.Count - 1]; CurrentGroup.name = parts[1]; CurrentObject.groups.Add(CurrentGroup); break; case "f": Face f = new Face(); f.LoadFromStringArray(parts); f.UseMtl = UseMtl; //FaceList.Add(f); CurrentGroup.faces.Add(f); break; } } }