public static List <Polygon> ReadAllPolygons(BinaryReader sectionReader) { List <Polygon> Polygons = new List <Polygon>(); uint polygonCount = sectionReader.ReadUInt32(); for (int i = 0; i < polygonCount; i++) { Polygon polygon = new Polygon(); for (int j = 0; j < 3; j++) { PolygonIndex polygonIndex = new PolygonIndex(); polygonIndex.Index = sectionReader.ReadUInt32(); polygonIndex.X = sectionReader.ReadSingle(); polygonIndex.Y = sectionReader.ReadSingle(); polygonIndex.Z = sectionReader.ReadSingle(); polygonIndex.U = sectionReader.ReadSingle(); polygonIndex.V = sectionReader.ReadSingle(); polygon.PolygonIndices.Add(polygonIndex); } Polygons.Add(polygon); } return(Polygons); }
public static void LookupParentsByGeometry(List <GeoEntity> data, IEnumerable <GeometryData> crossreferences) { var polyIndex = new PolygonIndex(); polyIndex.AddRange(crossreferences); data.ForEach(x => AddParents(x, polyIndex)); }
/// <summary> /// Helper method to read a single polygon /// </summary> /// <param name="sectionReader">BinaryReader instance</param> /// <param name="version">Version of the Puppet file</param> /// <returns>An instance of <see cref="PangLib.PET.Models.Polygon"/></returns> public static Polygon ReadPolygon(BinaryReader sectionReader, Version version) { Polygon polygon = new Polygon(); polygon.PolygonIndices = new PolygonIndex[3]; for (int i = 0; i < 3; i++) { PolygonIndex polygonIndex = new PolygonIndex { Index = sectionReader.ReadUInt32(), X = sectionReader.ReadSingle(), Y = sectionReader.ReadSingle(), Z = sectionReader.ReadSingle() }; if (version.Minor >= 2) { byte uvMapCount = sectionReader.ReadByte(); polygonIndex.UVMappings = new UVMapping[uvMapCount]; for (int j = 0; j < uvMapCount; j++) { UVMapping uvMapping = new UVMapping { U = sectionReader.ReadSingle(), V = sectionReader.ReadSingle() }; polygonIndex.UVMappings[j] = uvMapping; } } else { polygonIndex.UVMappings = new UVMapping[1]; UVMapping uvMapping = new UVMapping { U = sectionReader.ReadSingle(), V = sectionReader.ReadSingle() }; polygonIndex.UVMappings[0] = uvMapping; } polygon.PolygonIndices[i] = polygonIndex; } return(polygon); }
public static GeoEntity AddParents(GeoEntity entity, PolygonIndex index) { if (entity.Location == null) { return(entity); } var entities = index.Search(entity.Location); entity.Parents = entities.Select(x => new GeoEntityId { DataType = x.DataType, Name = x.Name, Reference = x.Reference }).ToList(); return(entity); }