From 4c131fa0af74ea74a1ab3540dfd03c48ea664ff1 Mon Sep 17 00:00:00 2001 From: dexyfex Date: Sun, 6 May 2018 14:55:54 +1000 Subject: [PATCH] Nav mesh progress --- .../FileTypes/Builders/YnvBuilder.cs | 52 ++++++++++++++----- .../GameFiles/FileTypes/YnvFile.cs | 19 +++++++ 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/Builders/YnvBuilder.cs b/CodeWalker.Core/GameFiles/FileTypes/Builders/YnvBuilder.cs index 1173ae4..9bba059 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/Builders/YnvBuilder.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/Builders/YnvBuilder.cs @@ -11,6 +11,30 @@ namespace CodeWalker.Core.GameFiles.FileTypes.Builders { public class YnvBuilder { + /* + * + * YnvBuilder by dexyfex + * + * This class allows for conversion of navmesh data in a generic format into .ynv files. + * The usage is to call AddPoly() with an array of vertex positions for each polygon. + * Polygons should be wound in an anticlockwise direction. + * The returned YnvPoly object needs to have its Edges array set by the importer. + * YnvPoly.Edges is an array of YnvEdge, with one edge for each vertex in the poly. + * The first edge should join the first and second vertices, and the last edge should + * join the last and first vertices. + * The YnvEdge Poly1 and Poly2 both need to be set to the same value, which is the + * corresponding YnvPoly object that was returned by AddPoly. + * Flags values on the polygons and edges also need to be set by the importer. + * + * Once the polygons and edges have all been added, the Build() method should be called, + * which will return a list of YnvFile objects. Call the Save() method on each of those + * to get the byte array for the .ynv file. The correct filename is given by the + * YnvFile.Name property. + * Note that the .ynv building process will split polygons that cross .ynv area borders, + * and assign all the new polygons into the correct .ynv's. + * + */ + private List PolyList = new List(); @@ -413,21 +437,23 @@ namespace CodeWalker.Core.GameFiles.FileTypes.Builders { if (edge.Poly1.AreaID != poly.AreaID) { - //edge._RawData._Poly2.Unk3 = 4;// edge._RawData._Poly2.Unk3 | 4; + edge._RawData._Poly1.Unk2 = 0;//crash without this + edge._RawData._Poly2.Unk2 = 0;//crash without this + edge._RawData._Poly2.Unk3 = 4;////// edge._RawData._Poly2.Unk3 | 4; + border = true; - //DEBUG don't join edges - edge.Poly1 = null; - edge.Poly2 = null; - edge.AreaID1 = 0x3FFF; - edge.AreaID2 = 0x3FFF; - edge._RawData._Poly1.PolyID = 0x3FFF; - edge._RawData._Poly2.PolyID = 0x3FFF; - edge._RawData._Poly1.Unk2 = 1; - edge._RawData._Poly2.Unk2 = 1; - edge._RawData._Poly1.Unk3 = 0; - edge._RawData._Poly2.Unk3 = 0; + ////DEBUG don't join edges + //edge.Poly1 = null; + //edge.Poly2 = null; + //edge.AreaID1 = 0x3FFF; + //edge.AreaID2 = 0x3FFF; + //edge._RawData._Poly1.PolyID = 0x3FFF; + //edge._RawData._Poly2.PolyID = 0x3FFF; + //edge._RawData._Poly1.Unk2 = 1; + //edge._RawData._Poly2.Unk2 = 1; + //edge._RawData._Poly1.Unk3 = 0; + //edge._RawData._Poly2.Unk3 = 0; - //border = true; } } } diff --git a/CodeWalker.Core/GameFiles/FileTypes/YnvFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YnvFile.cs index 5118acb..d36254c 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YnvFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YnvFile.cs @@ -48,6 +48,16 @@ namespace CodeWalker.GameFiles + //getters for property grids viewing of the lists + public Vector3[] AllVertices { get { return Vertices?.ToArray(); } } + public ushort[] AllIndices { get { return Indices?.ToArray(); } } + public YnvEdge[] AllEdges { get { return Edges?.ToArray(); } } + public YnvPoly[] AllPolys { get { return Polys?.ToArray(); } } + public YnvPortal[] AllPortals { get { return Portals?.ToArray(); } } + public YnvPoint[] AllPoints { get { return Points?.ToArray(); } } + + + public YnvFile() : base(null, GameFileType.Ynv) { @@ -216,6 +226,15 @@ namespace CodeWalker.GameFiles var vertdict = new Dictionary(); var areadict = new Dictionary(); var arealist = new List(); + var areaid = Nav.AreaID; + EnsureEdgeAreaID(areaid, areadict, arealist); + EnsureEdgeAreaID(0x3FFF, areadict, arealist); + EnsureEdgeAreaID(areaid - 100, areadict, arealist); + EnsureEdgeAreaID(areaid - 1, areadict, arealist); + EnsureEdgeAreaID(areaid + 1, areadict, arealist); + EnsureEdgeAreaID(areaid + 100, areadict, arealist); + + if (Polys != null) //rebuild vertices, indices, edges and polys lists from poly data. {