From 02029c9da6a208be01f23e84404594bdaa76b221 Mon Sep 17 00:00:00 2001 From: dpethes Date: Tue, 14 Oct 2014 01:57:58 +0200 Subject: [PATCH] hob parser: properly distinguish between quad and triangle faces --- doc/file_hob_spec.txt | 7 +++---- hob_parser/hob_parser.pas | 17 ++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/doc/file_hob_spec.txt b/doc/file_hob_spec.txt index 5fd9f51..2461b1f 100644 --- a/doc/file_hob_spec.txt +++ b/doc/file_hob_spec.txt @@ -61,16 +61,15 @@ NOF * face block 4B int face count FC FC * face { - 4B int ? + 4B int face flags? if bit 3 is set, the face is a quad, otherwise triangle 1B int 46/49/4B 1B int 51/71 1B int 0C 1B int block size / 4: A = 40B, 9 = 36, etc. 2B int zero? 2B int texture/material index? - 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 + 4x 2B vertex indices, relative to the face group. The last index is zero in triangle faces + x bytes until block size: most probably texture coordinates and some other stuff? } } diff --git a/hob_parser/hob_parser.pas b/hob_parser/hob_parser.pas index c53f75a..5419e01 100644 --- a/hob_parser/hob_parser.pas +++ b/hob_parser/hob_parser.pas @@ -8,7 +8,7 @@ uses type THobFace = record - dw1: integer; + flags: integer; b1, b2, b3: byte; bsize: byte; ftype: byte; //3 - tri, 4 - quad @@ -84,7 +84,7 @@ begin SetLength(group.faces, group.face_count); for i := 0 to group.face_count - 1 do begin file_pos := f.Position; - face.dw1 := f.ReadDWord; //? + face.flags := f.ReadDWord; //? face.b1 := f.ReadByte; //46/49/4B face.b2 := f.ReadByte; //51/71 face.b3 := f.ReadByte; //0C @@ -105,18 +105,17 @@ begin 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 + //face type: quad or triangle + if face.flags and %1000 > 0 then + face.ftype := 4 else - face.ftype := 4; + face.ftype := 3; group.faces[i] := face; if DumpFaces then begin - write(face.dw1:8, face.b1:3, face.b2:3, face.b3:3, face.bsize:3); + if face.ftype = 3 then write('t') else write('q'); + write(face.flags:5, 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