def dump_ogf4_m04(cr, out, opts): dump_ogf4_m05(cr, out, opts) pr = PackedReader(cr.next(Chunks.SWIDATA)) out('swidata: {') out(' ?:', pr.getf('IIII')) sc = pr.getf('I')[0] if opts.diff: out( ' swis-info:', 'count=' + str(sc) + ', hash=' + calc_hash(pr.getb((4 + 2 + 2) * sc))) else: out(' swis: [') for _ in range(sc): out(' {offs: %i, tris: %i, vtxs: %i}' % pr.getf('IHH')) out(' ]') out('}')
def dump_ogf4_m05(cr, out, opts): pr = PackedReader(cr.next(Chunks.TEXTURE)) out('texture: {') out(' image:', pr.gets()) out(' shader:', pr.gets()) out('}') pr = PackedReader(cr.next(Chunks.VERTICES)) out('vertices: {') vf, vc = pr.getf('II') if vf == VertexFormat.FVF_1L or vf == VertexFormat.FVF_1L_CS: out(' format:', 'fvf_2l' if vf == VertexFormat.FVF_1L else 'fvf_1l_cs') if opts.diff: out( ' data-info:', 'count=' + str(vc) + ', hash=' + calc_hash(pr.getb(15 * 4 * vc))) else: out(' data: [') for _ in range(vc): out(' {v: %s, n: %s, tg: %s, bn: %s, tx: %s, b: %i' % (pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf('ff'), pr.getf('I')[0])) out(' ]') elif vf == VertexFormat.FVF_2L or vf == VertexFormat.FVF_2L_CS: out(' format:', 'fvf_2l' if vf == VertexFormat.FVF_2L else 'fvf_2l_cs') if opts.diff: out( ' data-info:', 'count=' + str(vc) + ', hash=' + calc_hash(pr.getb(16 * 4 * vc))) else: out(' data: [') for _ in range(vc): out(' {b: %s, v: %s, n: %s, tg: %s, bn: %s, bw: %f, tx: %s' % (pr.getf('HH'), pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf('f')[0], pr.getf('ff'))) out(' ]') elif vf == VertexFormat.FVF_3L_CS or vf == VertexFormat.FVF_4L_CS: nl = 3 if vf == VertexFormat.FVF_3L_CS else 4 out(' format:', 'fvf_' + str(nl) + 'l_cs') if opts.diff: out( ' data-info:', 'count=' + str(vc) + ', hash=' + calc_hash(pr.getb(((14 + nl - 1) * 4 + nl * 2) * vc))) else: out(' data: [') for _ in range(vc): out(' {b: %s, v: %s, n: %s, tg: %s, bn: %s, bw: %s, tx: %s' % (pr.getf(str(nl) + 'H'), pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf('fff'), pr.getf(str(nl - 1) + 'f'), pr.getf('ff'))) out(' ]') else: raise Exception('unexpected vertex format: {:#x}'.format(vf)) out('}') pr = PackedReader(cr.next(Chunks.INDICES)) ic = pr.getf('I')[0] // 3 if opts.diff: out('indices-info:', 'count=' + str(ic) + ', hash=' + calc_hash(pr.getb(3 * 2 * ic))) else: out('indices: {') for _ in range(ic): out(' ', pr.getf('HHH')) out('}')
def dump_mesh(cr, out, opts): ver = cr.nextf(Chunks.Mesh.VERSION, 'H')[0] if ver != 0x11: raise Exception('unsupported MESH format version: {}'.format(ver)) out('version:', ver) for (cid, data) in cr: pr = PackedReader(data) if cid == Chunks.Mesh.MESHNAME: out('meshname:', pr.gets()) elif cid == Chunks.Mesh.BBOX: out('bbox:', pr.getf('fff'), '-', pr.getf('fff')) elif cid == Chunks.Mesh.FLAGS: out('flags:', pr.getf('B')[0]) elif cid == Chunks.Mesh.OPTIONS: out('options:', pr.getf('II')) elif cid == Chunks.Mesh.VERTS: vc = pr.getf('I')[0] if opts.diff: out('vertices-info:', 'count=' + str(vc) + ', hash=' + calc_hash(data)) continue out('vertices: [') for _ in range(vc): out(' ', pr.getf('fff')) out(']') elif cid == Chunks.Mesh.FACES: if opts.diff: out('faces-info:', 'count=' + str(pr.getf('I')[0]) + ', hash=' + calc_hash(data)) continue out('faces: [') for _ in range(pr.getf('I')[0]): fr = pr.getf('IIIIII') f = ((fr[0], fr[2], fr[4]), (fr[1], fr[3], fr[5])) out(' ', f) out(']') elif cid == Chunks.Mesh.SG: if opts.diff: out('sgroups-hash:', calc_hash(data)) continue out('sgroups:', [pr.getf('I')[0] for _ in range(len(data) // 4)]) elif cid == Chunks.Mesh.VMREFS: if opts.diff: out('vmrefs-hash:', calc_hash(data)) continue out('vmrefs: [') for _ in range(pr.getf('I')[0]): sz = pr.getf('B')[0] out(' ', [pr.getf('II') for __ in range(sz)]) out(']') elif cid == Chunks.Mesh.SFACE: out('sfaces: [{') for _ in range(pr.getf('H')[0]): if _: out('}, {') out(' name:', pr.gets()) sz = pr.getf('I')[0] if opts.diff: out(' faces-info:', 'count=' + str(sz) + ', hash=' + calc_hash(pr.getb(sz * 4))) continue out(' faces:', [pr.getf('I')[0] for __ in range(sz)]) out('}]') elif cid == Chunks.Mesh.VMAPS0: out('vmaps0: [{') for _ in range(pr.getf('I')[0]): if _: out('}, {') out(' name:', pr.gets()) sz = pr.getf('I')[0] if opts.diff: out(' uvs-hash:', calc_hash(pr.getb(sz * 2 * 4))) out(' vtx-hash:', calc_hash(pr.getb(sz * 1 * 4))) continue out(' uvs:', [pr.getf('ff') for __ in range(sz)]) out(' vtx:', [pr.getf('I')[0] for __ in range(sz)]) out('}]') elif cid == Chunks.Mesh.VMAPS2: out('vmaps2: [{') for _ in range(pr.getf('I')[0]): if _: out('}, {') out(' name:', pr.gets()) out(' dim:', pr.getf('B')[0] & 0x3) dsc = pr.getf('B')[0] & 0x1 out(' dsc:', dsc) typ = pr.getf('B')[0] & 0x3 # enum {VMT_UV,VMT_WEIGHT} out(' type:', typ) sz = pr.getf('I')[0] if opts.diff: if typ == 0: out(' uvs-hash:', calc_hash(pr.getb(sz * 2 * 4))) elif typ == 1: out(' wgh-hash:', calc_hash(pr.getb(sz * 4))) out(' vtx-hash:', calc_hash(pr.getb(sz * 4))) if dsc != 0: out(' fcs-hash:', calc_hash(pr.getb(sz * 4))) continue if typ == 0: out(' uvs:', [pr.getf('ff') for __ in range(sz)]) elif typ == 1: out(' wgh:', [pr.getf('f')[0] for __ in range(sz)]) out(' vtx:', [pr.getf('I')[0] for __ in range(sz)]) if dsc != 0: out(' fcs:', [pr.getf('I')[0] for __ in range(sz)]) out('}]') else: out('UNKNOWN MESH CHUNK: {:#x}'.format(cid))