Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Check that Edge Linked triangles in navmeshes are pointing to each other
- }
- unit NavMeshCheckExternal;
- var
- arEdge: array [0..2] of string;
- //===========================================================================
- function Initialize: integer;
- begin
- if wbSimpleRecords then begin
- MessageDlg('Simple records must be unchecked in xEdit options', mtInformation, [mbOk], 0);
- Result := 1;
- Exit;
- end;
- arEdge[0] := '0-1';
- arEdge[1] := '1-2';
- arEdge[2] := '2-0';
- end;
- //===========================================================================
- // check that tri1 in navmesh navm1 points to tri2 in navmesh navm2
- function CheckConnection(navm1, navm2: IInterface; tri1, tri2: integer): Boolean;
- var
- tris, tri, EdgeLinks, EdgeLink: IInterface;
- TriLimit, j, flags, EdgeLinkLimit, EdgeLinkIndex: integer;
- begin
- if Signature(navm1) <> 'NAVM' then begin
- AddMessage('Not NAVM!');
- AddMessage(Format('Referenced triangle %d in %s', [tri1, Name(navm1)]));
- Exit;
- end;
- tris := ElementByPath(navm1, 'NVNM\Triangles');
- TriLimit := Pred(ElementCount(tris));
- EdgeLinks := ElementByPath(navm1, 'NVNM\Edge Links');
- EdgeLinkLimit := Pred(ElementCount(EdgeLinks));
- if tri1 > TriLimit then begin
- AddMessage(Format('Referenced triangle (%d > %d) in %s', [tri1, TriLimit, Name(navm1)]));
- Exit;
- end;
- tri := ElementByIndex(tris, tri1);
- flags := GetElementNativeValues(tri, 'Flags');
- if flags and 7 = 0 then begin
- AddMessage('No Edge Links');
- AddMessage(Format('Referenced triangle %d in %s', [tri1, Name(navm1)]));
- Exit;
- end;
- for j := 0 to 2 do
- if flags and (1 shl j) > 0 then begin
- EdgeLinkIndex := GetElementNativeValues(tri, 'Edge ' + arEdge[j]);
- if EdgeLinkIndex > EdgeLinkLimit then begin
- AddMessage(Format('Bad Edge %s link (%d > %d)!', [arEdge[j], EdgeLinkIndex, EdgeLinkLimit]));
- AddMessage(Format('Referenced triangle %d in %s', [tri1, Name(navm1)]));
- end
- else begin
- EdgeLink := ElementByIndex(EdgeLinks, EdgeLinkIndex);
- if (FormID(LinksTo(ElementByName(EdgeLink, 'Mesh'))) = FormID(navm2)) and (GetElementNativeValues(EdgeLink, 'Triangle') = tri2) then begin
- Result := True;
- Exit;
- end;
- end;
- end;
- AddMessage('No Edge Link match!');
- AddMessage(Format('Referenced triangle %d in %s', [tri1, Name(navm1)]));
- end;
- //===========================================================================
- function Process(e: IInterface): integer;
- var
- tris, tri, EdgeLinks, EdgeLink: IInterface;
- i, j, flags, EdgeLinkLimit, EdgeLinkIndex, EdgeLinkFound, EdgeLinkCount, errors: integer;
- begin
- if Signature(e) <> 'NAVM' then
- Exit;
- e := WinningOverride(e);
- tris := ElementByPath(e, 'NVNM\Triangles');
- EdgeLinks := ElementByPath(e, 'NVNM\Edge Links');
- EdgeLinkCount := ElementCount(EdgeLinks);
- EdgeLinkLimit := Pred(ElementCount(EdgeLinks));
- EdgeLinkFound := 0;
- // iterate through triangles
- for i := 0 to Pred(ElementCount(tris)) do begin
- errors := 0;
- tri := ElementByIndex(tris, i);
- flags := GetElementNativeValues(tri, 'Flags');
- for j := 0 to 2 do
- // triangle has EdgeLinks?
- if flags and (1 shl j) > 0 then begin
- EdgeLinkIndex := GetElementNativeValues(tri, 'Edge ' + arEdge[j]);
- if EdgeLinkIndex > EdgeLinkLimit then
- AddMessage(Format('Bad Edge %s link (%d > %d)!', [arEdge[j], EdgeLinkIndex, EdgeLinkLimit]))
- else begin
- Inc(EdgeLinkFound);
- EdgeLink := ElementByIndex(EdgeLinks, EdgeLinkIndex);
- if not CheckConnection(WinningOverride(LinksTo(ElementByName(EdgeLink, 'Mesh'))), e, GetElementNativeValues(EdgeLink, 'Triangle'), i) then begin
- AddMessage(Format('via Edge %s link %d', [arEdge[j], EdgeLinkIndex]));
- Inc(errors);
- end;
- end;
- end;
- if errors > 0 then
- AddMessage(Format('^^^ Error triangle %d in %s', [i, Name(e)]));
- end;
- if (EdgeLinkFound > 0) and (EdgeLinkFound > EdgeLinkCount) then begin
- AddMessage(Format('Too many Edges Linked (%d > %d) in %s', [EdgeLinkFound, EdgeLinkCount, Name(e)]));
- //Result := 1;
- //Exit;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement