2
0
mirror of https://github.com/dpethes/rerogue.git synced 2025-06-07 18:58:32 +02:00

HOB parser: change how triangle / quad faces are determined

This commit is contained in:
dpethes 2014-10-13 23:58:06 +02:00
parent 91b625d677
commit 7075f10021
2 changed files with 31 additions and 23 deletions

View File

@ -66,10 +66,10 @@ NOF * face block
1B int 51/71
1B int 0C
1B int block size / 4: A = 40B, 9 = 36, etc.
if block size = 9, this is a triangle, else quad
2B int zero?
2B int texture/material index?
4x 2B vertex indices, if triangle, the last index is zero. Vertex indices are relative to the face group
4x 2B vertex indices, relative to the face group
-if the last index is zero, the face is most probably a triangle
x bytes until block size
}
}

View File

@ -46,6 +46,9 @@ function ParseHobFile(const fname: string): THobFile;
//**************************************************************************************************
implementation
const
DumpFaces = false;
function NameToString(name: array of byte): string;
var
i: Integer;
@ -63,6 +66,7 @@ var
face: THobFace;
unknown: integer;
file_pos: integer;
buf: array[0..255] of byte;
begin
unknown := f.ReadDWord;
if (unknown <> 0) then
@ -84,36 +88,43 @@ begin
face.b2 := f.ReadByte; //51/71
face.b3 := f.ReadByte; //0C
face.bsize := f.ReadByte * 4; //block size: A = 40B, 9 = 36
if face.bsize = 36 then
face.ftype := 3
else
face.ftype := 4;
write(face.dw1:8, face.b1:3, face.b2:3, face.b3:3, face.bsize:3);
unknown := f.ReadWord;
if (unknown <> 0) then
writeln('unusual file: unknown');
face.tex_index := f.ReadWord;
write(' ti: ', face.tex_index);
//read vertex indices
write(' coords: ');
for k := 0 to 3 do begin
for k := 0 to 3 do
face.indices[k] := f.ReadWord;
write(face.indices[k]:4);
end;
//read rest of the face block
write(' rest: ');
for k := f.Position to file_pos + face.bsize - 1 do begin
unknown := f.ReadByte;
write(unknown: 4);
end;
writeln;
unknown := file_pos + face.bsize - f.Position;
for k := 0 to unknown - 1 do
buf[k] := f.ReadByte;
//face type: don't know how to distinguish between quad and triangle, so hack:
//if last vertex index is 0, consider this to be a triangle, quad otherwise.
//Breaks faces that really use the 0 vertex.
if face.indices[3] = 0 then
face.ftype := 3
else
face.ftype := 4;
group.faces[i] := face;
if DumpFaces then begin
write(face.dw1:8, face.b1:3, face.b2:3, face.b3:3, face.bsize:3);
write(' ti: ', face.tex_index);
write(' coords: ');
for k := 0 to 3 do
write(face.indices[k]:4);
write(' rest: ');
for k := 0 to unknown - 1 do
write(buf[k]:4);
writeln;
end;
end;
end;
@ -172,9 +183,7 @@ var
f: TMemoryStream;
hob: THobFile;
i: integer;
vertex_count: integer;
obj_count, face_block_offset: integer;
meshdef_offset: integer;
obj_count: integer;
unknown: integer;
begin
f := TMemoryStream.Create;
@ -203,7 +212,6 @@ begin
hob.face_group_count0 := f.ReadWord;
if hob.face_group_count <> hob.face_group_count0 then begin
writeln('reading failed: facegroup counts don''t match!: ', hob.face_group_count, hob.face_group_count0:5);
halt;
end;
//read face group defs