-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLinksOptimizer.lpr
More file actions
57 lines (47 loc) · 1.43 KB
/
LinksOptimizer.lpr
File metadata and controls
57 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
program LinksOptimizer;
uses ogf_parser, ChunkedFileParser, sysutils;
procedure SimplifyVertexLinks(fname:string; fname_out:string);
var
f:TChunkedMemory;
child:TOgfChild;
child_id, newlink:cardinal;
data:string;
need_update_data:boolean;
begin
f:=TChunkedMemory.Create();
child:=TOgfChild.Create;
try
if not f.LoadFromFile(fname, 0) then exit;
child_id:=0;
while f.NavigateToChunk('9:'+inttostr(child_id)) do begin
data:=f.GetCurrentChunkRawDataAsString();
need_update_data:=false;
if not child.Deserialize(data) then exit;
newlink:=child.CalculateOptimalLinkType();
writeln(child.GetTextureData().texture+' ('+child.GetTextureData().shader+') : '+inttostr(child.GetCurrentLinkType())+' -> ' + inttostr(newlink));
if (newlink<>OGF_LINK_TYPE_INVALID) and (newlink<>child.GetCurrentLinkType()) then begin
need_update_data:=child.ChangeLinkType(newlink);
end;
if need_update_data then begin
data:=child.Serialize();
f.ReplaceCurrentRawDataWithString(data);
end;
child_id:=child_id+1;
f.ResetSelectedSubChunk();
end;
f.SaveToFile(fname_out);
finally
child.Free;
f.Free;
end;
end;
begin
if ParamCount>0 then begin;
if ParamCount>1 then begin
SimplifyVertexLinks(ParamStr(1), ParamStr(2));
end else begin
SimplifyVertexLinks(ParamStr(1), ParamStr(1));
end;
writeln('Done!');
end;
end.