private void assembleVertices() { var poly = xMesh.Element($"{ns}triangles"); var typeCount = poly.Elements($"{ns}input").Count(); var id = ArrayParsers.ParseInts(poly.Element($"{ns}p").Value); for (int i = 0; i < id.Count / typeCount; i++) { var textureIndex = -1; var colorIndex = -1; var index = 0; var posIndex = id[i * typeCount + index]; index++; var normalIndex = id[i * typeCount + index]; index++; if (Textures != null) { textureIndex = id[i * typeCount + index]; index++; } if (Colors != null) { colorIndex = id[i * typeCount + index]; index++; } processVertex(posIndex, normalIndex, textureIndex, colorIndex); } }
private List <T> readVecArray <T>(string id) { var data = xMesh .Elements($"{ns}source").FirstOrDefault(x => x.Attribute("id").Value == id) .Element($"{ns}float_array"); var count = int.Parse(data.Attribute("count").Value); var array = ArrayParsers.ParseFloats(data.Value); var result = new List <T>(); if (typeof(T) == typeof(Vector3)) { for (var i = 0; i < count / 3; i++) { result.Add((T)(object)new Vector3( array[i * 3], array[i * 3 + 2], array[i * 3 + 1] )); } } else if (typeof(T) == typeof(Vector2)) { for (var i = 0; i < count / 2; i++) { result.Add((T)(object)new Vector2( array[i * 2], array[i * 2 + 1] )); } } return(result); }