public YnvEdge(YnvEdge copy, YnvPoly poly) { _RawData = copy._RawData; _RawData._Poly1.PolyID = 0x3FFF; _RawData._Poly2.PolyID = 0x3FFF; Poly1 = poly; Poly2 = poly; AreaID1 = 0x3FFF; AreaID2 = 0x3FFF; }
public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); Nav = rd.ReadBlock <NavMesh>(); if (Nav != null) { Vector3 posoffset = Nav.SectorTree?.AABBMin.XYZ() ?? Vector3.Zero; Vector3 aabbsize = Nav.AABBSize; if (Nav.Vertices != null) { var verts = Nav.Vertices.GetFullList(); Vertices = new List <Vector3>(verts.Count); for (int i = 0; i < verts.Count; i++) { var ov = verts[i].ToVector3(); Vertices.Add(posoffset + ov * aabbsize); } } if (Nav.Indices != null) { Indices = Nav.Indices.GetFullList(); } if (Nav.AdjPolys != null) { AdjPolys = Nav.AdjPolys.GetFullList(); } if (Nav.Polys != null) { var polys = Nav.Polys.GetFullList(); Polys = new List <YnvPoly>(polys.Count); for (int i = 0; i < polys.Count; i++) { YnvPoly poly = new YnvPoly(); poly.Init(this, polys[i]); poly.Index = i; poly.CalculatePosition(); //calc poly center for display purposes.. Polys.Add(poly); if (poly.PortalType > 0) { if (poly.PortalType != 2) //seems to be what portal links need to understand.. { } } } } if (Nav.Portals != null) { var portals = Nav.Portals; Portals = new List <YnvPortal>(portals.Length); for (int i = 0; i < portals.Length; i++) { YnvPortal portal = new YnvPortal(); portal.Init(this, portals[i]); portal.Index = i; portal.PositionFrom = posoffset + portal._RawData.PositionFrom.ToVector3() * aabbsize; portal.PositionTo = posoffset + portal._RawData.PositionTo.ToVector3() * aabbsize; Portals.Add(portal); } } ////### add points to the list and calculate positions... var treestack = new Stack <NavMeshSector>(); var pointi = 0; if (Nav.SectorTree != null) { treestack.Push(Nav.SectorTree); } while (treestack.Count > 0) { var sector = treestack.Pop(); if (sector.Data != null) { var points = sector.Data.Points; if (points != null) { if (Points == null) { Points = new List <YnvPoint>(); } for (int i = 0; i < points.Length; i++) { YnvPoint point = new YnvPoint(); point.Init(this, points[i]); point.Index = pointi; pointi++; point.Position = posoffset + point._RawData.Position * aabbsize; Points.Add(point); } } } if (sector.SubTree1 != null) { treestack.Push(sector.SubTree1); } if (sector.SubTree2 != null) { treestack.Push(sector.SubTree2); } if (sector.SubTree3 != null) { treestack.Push(sector.SubTree3); } if (sector.SubTree4 != null) { treestack.Push(sector.SubTree4); } } } UpdateAllNodePositions(); UpdateTriangleVertices(); BuildBVH(); Loaded = true; LoadQueued = true; }
public bool RemovePoly(YnvPoly poly) { return(false); }
public void Load(byte[] data, RpfFileEntry entry) { Name = entry.Name; RpfFileEntry = entry; RpfResourceFileEntry resentry = entry as RpfResourceFileEntry; if (resentry == null) { throw new Exception("File entry wasn't a resource! (is it binary data?)"); } ResourceDataReader rd = new ResourceDataReader(resentry, data); Nav = rd.ReadBlock <NavMesh>(); if ((Nav != null) && (Nav.SectorTree != null)) { if (Nav.Vertices != null) { Vector3 posoffset = Nav.SectorTree.AABBMin.XYZ(); Vector3 aabbsize = Nav.AABBSize; var verts = Nav.Vertices.GetFullList(); Vertices = new List <Vector3>(verts.Count); for (int i = 0; i < verts.Count; i++) { var ov = verts[i].ToVector3(); Vertices.Add(posoffset + ov * aabbsize); } } if (Nav.Indices != null) { Indices = Nav.Indices.GetFullList(); } if (Nav.Polys != null) { var polys = Nav.Polys.GetFullList(); Polys = new List <YnvPoly>(polys.Count); for (int i = 0; i < polys.Count; i++) { YnvPoly poly = new YnvPoly(); poly.Init(this, polys[i]); poly.Index = i; Polys.Add(poly); //calc poly center. if ((Indices == null) || (Vertices == null)) { continue; } var vc = Vertices.Count; var ic = poly._RawData.IndexCount; var startid = poly._RawData.IndexID; var endid = startid + ic; if (startid >= Indices.Count) { continue; } if (endid > Indices.Count) { continue; } Vector3 pcenter = Vector3.Zero; float pcount = 0.0f; for (int id = startid; id < endid; id++) { var ind = Indices[id]; if (ind >= vc) { continue; } pcenter += Vertices[ind]; pcount += 1.0f; } poly.Position = pcenter * (1.0f / pcount); } } } UpdateAllNodePositions(); UpdateTriangleVertices(); Loaded = true; LoadQueued = true; }