private FileData Map(ObjFileData obj) { return(new FileData { Id = obj.Id, RootId = obj.RootId, RootType = obj.RootType, OriginalName = obj.OriginalName, FileName = obj.FileName, CreatedId = obj.CreatedId }); }
private ObjFileData Map(FileData file) { var result = new ObjFileData { Id = file.Id, RootId = file.RootId, RootType = file.RootType, OriginalName = file.OriginalName, FileName = file.FileName, CreatedId = file.CreatedId }; if (result.CreatedId.HasValue) { var user = _userRepository.Get(result.CreatedId.Value); result.CreatedName = user.Fio; result.CreatedPhotoUrl = user.Avatar; } return(result); }
private static ObjFileData ParseOBJStringSingle(string[] lines) { List<ObjFileData> objects = new List<ObjFileData>(); List<Vector3> temp_vertices = new List<Vector3>(), temp_normals = new List<Vector3>(); List<Vector2> temp_uvs = new List<Vector2>(); List<float> out_vertex_buffer = new List<float>(); List<uint> index_buffer = new List<uint>(); HashSet<Tuple<int, int, int>> indicesRedecer = new HashSet<Tuple<int, int, int>>(); ; //out_vertex_buffer.AddRange(Enumerable.Repeat<double>(0, 8)); uint vcount = 0; ObjFileData current = new ObjFileData(); Match match = Match.Empty; foreach(string line in lines) { if(line.StartsWith("vt")) { match = Regex.Match(line, @"vt ([0-9.-]+) ([0-9.-]+)"); temp_uvs.Add(new Vector2(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("vn")) { match = Regex.Match(line, @"vn ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_normals.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("v")) { match = Regex.Match(line, @"v ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_vertices.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("f")) { match = Regex.Match(line, @"f ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+)"); if(match.Success) { for(int i = 1; ; ) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector2 uv = temp_uvs[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.AddRange(new float[] { vertex.X, vertex.Y, vertex.Z, uv.X, uv.Y, normal.X, normal.Y, normal.Z }); index_buffer.Add(vcount++); if(i >= 9) break; } } else { match = Regex.Match(line, @"f ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+)"); if(match.Success) { for(int i = 1; ; ) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.AddRange(new float[] { vertex.X, vertex.Y, vertex.Z, 0.0f, 0.0f, normal.X, normal.Y, normal.Z }); index_buffer.Add(vcount++); if(i >= 6) break; } } } } } current.VBO = out_vertex_buffer; current.Indices = index_buffer; objects.Add(current); current = new ObjFileData(); current.Name = match.Groups[1].Value; return objects.First(); }
private static ObjFileData ParseOBJStringSingle(string[] lines) { List <ObjFileData> objects = new List <ObjFileData>(); List <Vector3> temp_vertices = new List <Vector3>(), temp_normals = new List <Vector3>(); List <Vector2> temp_uvs = new List <Vector2>(); List <VertexInfo> out_vertex_buffer = new List <VertexInfo>(); uint vcount = 0; ObjFileData current = new ObjFileData(); Match match = Match.Empty; foreach (string line in lines) { if (line.StartsWith("vt")) { match = Regex.Match(line, @"vt ([0-9.-]+) ([0-9.-]+)"); temp_uvs.Add(new Vector2(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("vn")) { match = Regex.Match(line, @"vn ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_normals.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("v")) { match = Regex.Match(line, @"v ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_vertices.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("f")) { match = Regex.Match(line, @"f ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+)"); if (match.Success) { for (int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector2 uv = temp_uvs[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = uv }); if (i >= 9) { break; } } } else { match = Regex.Match(line, @"f ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+)"); if (match.Success) { for (int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = normal.Xz }); if (i >= 6) { break; } } } } } } current.VBO = out_vertex_buffer; objects.Add(current); current = new ObjFileData(); current.Name = match.Groups[1].Value; return(objects.First()); }
private static List <ObjFileData> ParseOBJString(string[] lines) { List <ObjFileData> objects = new List <ObjFileData>(); List <Vector3> temp_vertices = new List <Vector3>(), temp_normals = new List <Vector3>(); List <Vector2> temp_uvs = new List <Vector2>(); List <VertexInfo> out_vertex_buffer = new List <VertexInfo>(); //out_vertex_buffer.AddRange(Enumerable.Repeat<double>(0, 8)); uint vcount = 0; ObjFileData current = new ObjFileData(); string currentMaterial = ""; string name = ""; // Match match = Match.Empty; foreach (string line in lines) { if (line.StartsWith("o")) { current.VBO = out_vertex_buffer; if (current.VBO.Count >= 1) { current.MaterialName = currentMaterial; objects.Add(current); GC.Collect(); Console.WriteLine("GC MEMORY USED {0} MB", GC.GetTotalMemory(true) / 1024.0 / 1024); Console.OpenStandardOutput().Flush(); } current = new ObjFileData(); current.Name = line.Substring(2); Console.WriteLine("Internal Loading " + current.Name); vcount = 0; //temp_vertices = new List<Vector3>(); //temp_normals = new List<Vector3>(); //temp_uvs = new List<Vector2>(); out_vertex_buffer = new List <VertexInfo>(); } if (line.StartsWith("usemtl")) { currentMaterial = line.Substring(7); } if (line.StartsWith("vt")) { var groups = line.Substring(3).Replace("nan", "0").Split(' '); temp_uvs.Add(new Vector2(float.Parse(groups[0], System.Globalization.CultureInfo.InvariantCulture), float.Parse(groups[1], System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("vn")) { var groups = line.Substring(3).Split(' '); temp_normals.Add(new Vector3( float.Parse(groups[0], System.Globalization.CultureInfo.InvariantCulture), float.Parse(groups[1], System.Globalization.CultureInfo.InvariantCulture), float.Parse(groups[2], System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("v")) { var groups = line.Substring(2).Split(' '); temp_vertices.Add(new Vector3( float.Parse(groups[0], System.Globalization.CultureInfo.InvariantCulture), float.Parse(groups[1], System.Globalization.CultureInfo.InvariantCulture), float.Parse(groups[2], System.Globalization.CultureInfo.InvariantCulture))); } else if (line.StartsWith("f")) { // match = Regex.Match(line, @"f ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+)"); var groups = line.Substring(2).Replace("//", "/").Replace(' ', '/').Split('/'); if (groups.Length == 9) { out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[0]) - 1], UV = temp_uvs[int.Parse(groups[1]) - 1], Normal = temp_normals[int.Parse(groups[2]) - 1] } ); out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[3]) - 1], UV = temp_uvs[int.Parse(groups[4]) - 1], Normal = temp_normals[int.Parse(groups[5]) - 1] } ); out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[6]) - 1], UV = temp_uvs[int.Parse(groups[7]) - 1], Normal = temp_normals[int.Parse(groups[8]) - 1] } ); } else { out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[0]) - 1], UV = Vector2.One, Normal = temp_normals[int.Parse(groups[1]) - 1] } ); out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[2]) - 1], UV = Vector2.One, Normal = temp_normals[int.Parse(groups[3]) - 1] } ); out_vertex_buffer.Add( new VertexInfo() { Position = temp_vertices[int.Parse(groups[4]) - 1], UV = Vector2.One, Normal = temp_normals[int.Parse(groups[5]) - 1] } ); } } } current.VBO = out_vertex_buffer; current.MaterialName = currentMaterial; objects.Add(current); current = new ObjFileData(); return(objects); }
private static ObjFileData ParseOBJStringSingle(string[] lines) { List<ObjFileData> objects = new List<ObjFileData>(); List<Vector3> temp_vertices = new List<Vector3>(), temp_normals = new List<Vector3>(); List<Vector2> temp_uvs = new List<Vector2>(); List<VertexInfo> out_vertex_buffer = new List<VertexInfo>(); uint vcount = 0; ObjFileData current = new ObjFileData(); Match match = Match.Empty; foreach(string line in lines) { if(line.StartsWith("vt")) { match = Regex.Match(line, @"vt ([0-9.-]+) ([0-9.-]+)"); temp_uvs.Add(new Vector2(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("vn")) { match = Regex.Match(line, @"vn ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_normals.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("v")) { match = Regex.Match(line, @"v ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_vertices.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("f")) { match = Regex.Match(line, @"f ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+)"); if(match.Success) { for(int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector2 uv = temp_uvs[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = uv }); if(i >= 9) break; } } else { match = Regex.Match(line, @"f ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+)"); if(match.Success) { for(int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = normal.Xz }); if(i >= 6) break; } } } } } current.VBO = out_vertex_buffer; objects.Add(current); current = new ObjFileData(); current.Name = match.Groups[1].Value; return objects.First(); }
private static List<ObjFileData> ParseOBJString(string[] lines) { List<ObjFileData> objects = new List<ObjFileData>(); List<Vector3> temp_vertices = new List<Vector3>(), temp_normals = new List<Vector3>(); List<Vector2> temp_uvs = new List<Vector2>(); List<VertexInfo> out_vertex_buffer = new List<VertexInfo>(); ; //out_vertex_buffer.AddRange(Enumerable.Repeat<double>(0, 8)); uint vcount = 0; ObjFileData current = new ObjFileData(); string currentMaterial = ""; Match match = Match.Empty; foreach(string line in lines) { if(line.StartsWith("o")) { match = Regex.Match(line, @"o (.+)"); current.VBO = out_vertex_buffer; if(current.VBO.Count >= 1) { current.MaterialName = currentMaterial; objects.Add(current); } current = new ObjFileData(); current.Name = match.Groups[1].Value; vcount = 0; //temp_vertices = new List<Vector3>(); //temp_normals = new List<Vector3>(); //temp_uvs = new List<Vector2>(); out_vertex_buffer = new List<VertexInfo>(); } if(line.StartsWith("usemtl")) { match = Regex.Match(line, @"usemtl (.+)"); currentMaterial = match.Groups[1].Value; } if(line.StartsWith("vt")) { match = Regex.Match(line.Replace("nan", "0"), @"vt ([0-9.-]+) ([0-9.-]+)"); temp_uvs.Add(new Vector2(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), 1.0f - float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("vn")) { match = Regex.Match(line, @"vn ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_normals.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("v")) { match = Regex.Match(line, @"v ([0-9.-]+) ([0-9.-]+) ([0-9.-]+)"); temp_vertices.Add(new Vector3(float.Parse(match.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture), float.Parse(match.Groups[3].Value, System.Globalization.CultureInfo.InvariantCulture))); } else if(line.StartsWith("f")) { match = Regex.Match(line, @"f ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+) ([0-9]+)/([0-9]+)/([0-9]+)"); if(match.Success) { for(int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector2 uv = temp_uvs[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = uv }); if(i >= 9) break; } } else { match = Regex.Match(line, @"f ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+) ([0-9]+)//([0-9]+)"); if(match.Success) { for(int i = 1; ;) { Vector3 vertex = temp_vertices[int.Parse(match.Groups[i++].Value) - 1]; Vector3 normal = temp_normals[int.Parse(match.Groups[i++].Value) - 1]; out_vertex_buffer.Add(new VertexInfo() { Position = vertex, Normal = normal, UV = normal.Xz }); if(i >= 6) break; } } } } } current.VBO = out_vertex_buffer; current.MaterialName = currentMaterial; objects.Add(current); current = new ObjFileData(); current.Name = match.Groups[1].Value; return objects; }