Nav mesh progress

This commit is contained in:
dexyfex
2018-05-02 00:28:47 +10:00
Unverified
parent bab6668021
commit b18b1e7672
4 changed files with 64 additions and 38 deletions
+38 -12
View File
@@ -115,14 +115,6 @@ namespace CodeWalker.GameFiles
poly.Init(this, polys[i]);
poly.Index = i;
Polys.Add(poly);
if (poly.PortalType > 0)
{
if (poly.PortalType != 2) //seems to be what portal links need to understand..
{ }
}
}
}
if (Nav.Portals != null)
@@ -212,6 +204,7 @@ namespace CodeWalker.GameFiles
var edgelist = new List<NavMeshEdge>();
var polylist = new List<NavMeshPoly>();
var portallist = new List<NavMeshPortal>();
var portallinks = new List<ushort>();
var vertdict = new Dictionary<Vector3, ushort>();
var blankedgepart1 = new NavMeshEdgePart() { Value = 0x0FFFE1 };//1, -, 1, 0
@@ -243,6 +236,12 @@ namespace CodeWalker.GameFiles
edgelist.Add(e);
}
poly._RawData.IndexCount = vc;
poly._RawData.PortalLinkID = (uint)portallinks.Count;//these shouldn't be directly editable!
poly._RawData.PortalLinkCount = (byte)(poly.PortalLinks?.Length ?? 0);
if (poly.PortalLinks != null)
{
portallinks.AddRange(poly.PortalLinks);
}
poly.Index = i;//this should be redundant...
polylist.Add(poly.RawData);
}
@@ -303,7 +302,8 @@ namespace CodeWalker.GameFiles
Nav.Portals = (portallist.Count > 0) ? portallist.ToArray() : null;
Nav.PortalsCount = (uint)(Nav.Portals?.Length ?? 0);
//TODO: update portal links data.....
Nav.PortalLinks = (portallinks.Count > 0) ? portallinks.ToArray() : null;
Nav.PortalLinksCount = (uint)(Nav.PortalLinks?.Length ?? 0);
for (int i = 0; i < Nav.Polys.ListParts.Count; i++) //reassign part id's on all the polys...
@@ -572,8 +572,8 @@ namespace CodeWalker.GameFiles
public ushort AreaID { get { return _RawData.AreaID; } set { _RawData.AreaID = value; } }
public ushort PartID { get { return _RawData.PartID; } set { _RawData.PartID = value; } }
public ushort PortalLinkID { get { return _RawData.PortalLinkID; } set { _RawData.PortalLinkID = value; } }
public byte PortalType { get { return _RawData.PortalType; } set { _RawData.PortalType = value; } }
public uint PortalLinkID { get { return _RawData.PortalLinkID; } set { _RawData.PortalLinkID = value; } }
public byte PortalLinkCount { get { return _RawData.PortalLinkCount; } set { _RawData.PortalLinkCount = value; } }
public byte Flags1 { get { return (byte)(_RawData.Unknown_00h & 0xFF); } set { _RawData.Unknown_00h = (ushort)((_RawData.Unknown_00h & 0xFF00) | (value & 0xFF)); } }
public byte Flags2 { get { return (byte)((_RawData.Unknown_24h.Value >> 0) & 0xFF); } set { _RawData.Unknown_24h = ((_RawData.Unknown_24h.Value & 0xFFFFFF00u) | ((value & 0xFFu) << 0)); } }
public byte Flags3 { get { return (byte)((_RawData.Unknown_24h.Value >> 9) & 0xFF); } set { _RawData.Unknown_24h = ((_RawData.Unknown_24h.Value & 0xFFFE01FFu) | ((value & 0xFFu) << 9)); } }
@@ -621,6 +621,7 @@ namespace CodeWalker.GameFiles
public ushort[] Indices { get; set; }
public Vector3[] Vertices { get; set; }
public NavMeshEdge[] Edges { get; set; }
public ushort[] PortalLinks { get; set; }
public void Init(YnvFile ynv, NavMeshPoly poly)
@@ -629,6 +630,7 @@ namespace CodeWalker.GameFiles
RawData = poly;
LoadIndices();
LoadPortalLinks();
CalculatePosition(); //calc poly center for display purposes..
}
@@ -669,6 +671,30 @@ namespace CodeWalker.GameFiles
}
}
public void LoadPortalLinks()
{
if (PortalLinkCount == 0)
{ return; }
var links = Ynv.Nav?.PortalLinks;
if (links == null)
{ return; }
var ll = links.Length;
PortalLinks = new ushort[PortalLinkCount];
int offset = (int)PortalLinkID;
for (int i = 0; i < PortalLinkCount; i++)
{
int idx = offset + i;
PortalLinks[i] = (idx < ll) ? links[idx] : (ushort)0;
}
if (PortalLinkCount != 2)
{ }//debug
}
public void SetPosition(Vector3 pos)
{
@@ -725,7 +751,7 @@ namespace CodeWalker.GameFiles
//if ((u5 & 8388608) > 0) colour.Red += 1.0f; //slope facing -X,-Y (southwest)
//if (u5 >= 16777216) { } //other bits unused
var u1 = _RawData.PortalType;
var u1 = _RawData.PortalLinkCount;
//if ((u1 & 1) > 0) colour.Red += 1.0f; //portal - don't interact?
//if ((u1 & 2) > 0) colour.Green += 1.0f; //portal - ladder/fence interaction?
//if ((u1 & 4) > 0) colour.Blue += 1.0f; //portal - fence interaction / go away from?
+5 -5
View File
@@ -643,16 +643,16 @@ namespace CodeWalker.GameFiles
public NavMeshAABB CellAABB { get; set; }
public FlagsUint Unknown_24h { get; set; }
public FlagsUint Unknown_28h { get; set; }
public ushort PartFlags { get; set; }
public ushort PortalLinkID { get; set; }
public uint PartFlags { get; set; }
//public int IndexUnk { get { return (IndexFlags >> 0) & 31; } } //always 0
public int IndexCount { get { return (IndexFlags >> 5); } set { IndexFlags = (ushort)((IndexFlags & 31) | ((value & 0x7FF) << 5)); } }
//public int PartUnk1 { get { return (PartFlags >> 0) & 0xF; } } //always 0
public ushort PartID { get { return (ushort)((PartFlags >> 4) & 0xFF); } set { PartFlags = (ushort)((PartFlags & 0xF00F) | ((value & 0xFF) << 4)); } }
public byte PortalType { get { return (byte)((PartFlags >> 12) & 0xF); } set { PartFlags = (ushort)((PartFlags & 0x0FFF) | ((value & 0xF) << 12)); } }
public ushort PartID { get { return (ushort)((PartFlags >> 4) & 0xFF); } set { PartFlags = ((PartFlags & 0xFFFFF00F) | (((uint)value & 0xFF) << 4)); } }
public byte PortalLinkCount { get { return (byte)((PartFlags >> 12) & 0x7); } set { PartFlags = ((PartFlags & 0xFFFF8FFF) | (((uint)value & 0x7) << 12)); } }
public uint PortalLinkID { get { return ((PartFlags >> 15) & 0x1FFFF); } set { PartFlags = ((PartFlags & 0x7FFF) | ((value & 0x1FFFF) << 15)); } }
public ushort Unknown_28h_16 { get { return (ushort)((Unknown_28h.Value & 0xFFFF)); } set { Unknown_28h = (Unknown_28h.Value & 0xFFFF0000) | (value & 0xFFFFu); } }
@@ -673,7 +673,7 @@ namespace CodeWalker.GameFiles
Unknown_28h.Hex + ", " +
//PartFlags.ToString() + ", " + //PartUnk1.ToString() + ", " +
PartID.ToString() + ", " +
PortalType.ToString() + ", " +
PortalLinkCount.ToString() + ", " +
PortalLinkID.ToString();
}
}