示例#1
0
def parse_gamemtl(data):
    materials = {}
    for (cid, data) in ChunkedReader(data):
        if cid == 4098:
            for (_, cdata) in ChunkedReader(data):
                name, desc = None, None
                for (cccid, ccdata) in ChunkedReader(cdata):
                    if cccid == 0x1000:
                        reader = PackedReader(ccdata)
                        material_index = reader.getf('I')[0]
                        name = reader.gets()
                        materials[material_index] = name
                    if cccid == 0x1005:
                        desc = PackedReader(ccdata).gets()
    return materials
示例#2
0
def main():
    from optparse import OptionParser
    parser = OptionParser(usage='Usage: dump_anm.py <.anm-file> [options]')
    (options, args) = parser.parse_args()
    if not args:
        parser.print_help()
        sys.exit(2)
    with io.open(sys.argv[1], mode='rb') as f:
        dump_anm(ChunkedReader(f.read()), print, options)
示例#3
0
def main():
    from optparse import OptionParser
    parser = OptionParser(usage='Usage: dump-object.py <.object-file> [options]')
    parser.add_option("-d", "--diff", action='store_true', default=False, help='generate diff-ready dump')
    (options, args) = parser.parse_args()
    if not args:
        parser.print_help()
        sys.exit(2)
    with io.open(sys.argv[1], mode='rb') as f:
        dump_object(ChunkedReader(f.read()), print, options)
示例#4
0
def main():
    parser = optparse.OptionParser(
        usage='Usage: dump_omf.py <.omf-file> [options]')
    (options, args) = parser.parse_args()
    if not args:
        parser.print_help()
        input('press enter...')
        sys.exit(2)
    with open(sys.argv[1], mode='rb') as file:
        data = file.read()
        reader = ChunkedReader(data)
        dump_omf(reader, print, options)
示例#5
0
def main():
    from optparse import OptionParser
    parser = OptionParser(usage='Usage: dump_skl.py <.skl|.skls-file>')
    (options, args) = parser.parse_args()
    if not args:
        parser.print_help()
        sys.exit(2)
    with io.open(args[0], mode='rb') as f:
        ext = os.path.splitext(args[0])[-1].lower()
        if ext == '.skl':
            dump_skl(ChunkedReader(f.read()), print)
        elif ext == '.skls':
            dump_skls(PackedReader(f.read()), print)
        else:
            raise Exception('unknown file type: ' + ext)
示例#6
0
def dump_ogf4_m10(cr, out, opts):
    def oout(*args):
        out(' ', *args)

    def ooout(*args):
        oout(' ', *args)

    def dump_box(pr, out):
        out('box: {')
        out('  rotation:', pr.getf('fffffffff'))
        out('  position:', pr.getf('fff'))
        out('  halfsize:', pr.getf('fff'))
        out('}')

    bonescount = 0
    for cid, data in cr:
        pr = PackedReader(data)
        if cid == Chunks.S_DESC:
            out('s desc: {')
            out('  src:', pr.gets())
            out('  export tool:', pr.gets())
            out('  export time:', pr.getf('I')[0])
            out('  create time:', pr.getf('I')[0])
            out('  modify time:', pr.getf('I')[0])
            out('}')
        elif cid == Chunks.CHILDREN:
            out('children: [{')
            for _, ccr in ChunkedReader(data):
                if _: out('}, {')
                dump_ogf(ChunkedReader(ccr), oout, opts)
            out('}]')
        elif cid == Chunks.S_USERDATA:
            out('userdata:', pr.gets())
        elif cid == Chunks.S_BONE_NAMES:
            out('s bone names: [{')
            bonescount = pr.getf('I')[0]
            for _ in range(bonescount):
                if _: out('}, {')
                out('  name:', pr.gets())
                out('  parent:', pr.gets())
                dump_box(pr, oout)
            out('}]')
        elif cid == Chunks.S_IKDATA:
            out('s ikdata: [{')
            for _ in range(bonescount):
                if _: out('}, {')
                ver = pr.getf('I')[0]
                if ver != 0x1:
                    raise Exception(
                        'unexpected ikdata version: {:#x}'.format(ver))
                out('  gamemtl:', pr.gets())
                out('  shape: {')
                out('    type:', pr.getf('H')[0])
                out('    flags:', pr.getf('H')[0])
                dump_box(pr, ooout)
                out('    sphere: {')
                out('      center:', pr.getf('fff'))
                out('      radius:', pr.getf('f')[0])
                out('    }')
                out('    cylinder: {')
                out('      center:', pr.getf('fff'))
                out('      direction:', pr.getf('fff'))
                out('      height:', pr.getf('f')[0])
                out('      radius:', pr.getf('f')[0])
                out('    }')
                out('  }')
                out('  joint: {')
                out('    type:', pr.getf('I')[0])
                out('    limits: [')
                out('      {%s, s: %f, d: %f}' %
                    (pr.getf('ff'), pr.getf('f')[0], pr.getf('f')[0]))
                out('      {%s, s: %f, d: %f}' %
                    (pr.getf('ff'), pr.getf('f')[0], pr.getf('f')[0]))
                out('      {%s, s: %f, d: %f}' %
                    (pr.getf('ff'), pr.getf('f')[0], pr.getf('f')[0]))
                out('    ]')
                out('    spring:', pr.getf('f')[0])
                out('    damping:', pr.getf('f')[0])
                out('    flags:', pr.getf('I')[0])
                out('    break: {')
                out('      force:', pr.getf('f')[0])
                out('      torque:', pr.getf('f')[0])
                out('    }')
                out('    friction:', pr.getf('f')[0])
                out('  }')
                out('  rotation:', pr.getf('fff'))
                out('  position:', pr.getf('fff'))
                out('  mass: {')
                out('    value:', pr.getf('f')[0])
                out('    center:', pr.getf('fff'))
                out('  }')
            out('}]')
        elif cid == Chunks.S_MOTION_REFS_0:
            out('s motion refs 0:', pr.gets())
        elif cid == Chunks.S_MOTIONS:
            out('s motions: len={}, hash={}'.format(len(data),
                                                    calc_hash(data)))
        elif cid == Chunks.S_SMPARAMS:
            out('s smparams: {')
            ver = pr.getf('H')[0]
            if (ver != 3) and (ver != 4):
                print('unsupported smparams version={}'.format(ver))
            out('  version:', ver)
            out('  partitions: [{')
            for pi in range(pr.getf('H')[0]):
                if pi: out('  }, {')
                pn = pr.gets()
                out('    name:', pn)
                out('    bones: [{')
                for bi in range(pr.getf('H')[0]):
                    if bi: out('    }, {')
                    out('      name:', pr.gets())
                    out('      id:', pr.getf('I')[0])
                out('    }]')
                break
            out('  }]')
            out('}')
        else:
            print('unknown ogf4_m10 chunk={:#x}, len={}, hash={}'.format(
                cid, len(data), calc_hash(data)))
示例#7
0
def dump_object(cr, out, opts):
    def oout(*args):
        out(' ', *args)

    cr = ChunkedReader(cr.next(Chunks.Object.MAIN))
    ver = cr.nextf(Chunks.Object.VERSION, 'H')[0]
    if ver != 0x10:
        raise Exception('unsupported OBJECT format version: {}'.format(ver))
    out('version:', ver)

    getserr = ''

    def gets_error(e):
        global getserr
        getserr = ' //!' + str(e)

    def sgets(pr):
        global getserr
        getserr = ''
        return pr.gets(onerror=gets_error) + getserr

    for (cid, data) in cr:
        pr = PackedReader(data)
        if cid == Chunks.Object.USERDATA:
            out('userdata:', sgets(pr))
        elif cid == Chunks.Object.LOD_REF:
            out('lod_ref:', pr.gets())
        elif cid == Chunks.Object.FLAGS:
            out('flags:', pr.getf('I')[0])
        elif cid == Chunks.Object.MESHES:
            out('meshes: [{')
            for (_, d) in ChunkedReader(data):
                if _: out('}, {')
                dump_mesh(ChunkedReader(d), oout, opts)
            out('}]')
        elif (cid == Chunks.Object.SURFACES1) or (cid == Chunks.Object.SURFACES2):
            out('surfaces{}'.format(cid - Chunks.Object.SURFACES1 + 1) + ': [{')
            for _ in range(pr.getf('I')[0]):
                if _: out('}, {')
                out('  name:', pr.gets())
                out('  eshader:', pr.gets())
                out('  cshader:', pr.gets())
                if cid == Chunks.Object.SURFACES2:
                    out('  gamemtl:', pr.gets())
                out('  texture:', pr.gets())
                out('  vmap:', pr.gets())
                out('  flags:', pr.getf('I')[0])
                fvf = pr.getf('I')[0]
                out('  fvf:', 'default' if fvf == 0x112 else fvf)
                out('  ?=1:', pr.getf('I')[0])
            out('}]')
        elif cid == Chunks.Object.BONES:
            out('bones: [{')
            pr = PackedReader(data)
            for _ in range(pr.getf('I')[0]):
                if _: out('}, {')
                out('  def: {')
                out('    name:', pr.gets())
                out('    parent:', pr.gets())
                out('    vmap:', pr.gets())
                out('  }')
                out('  pose: {')
                out('    offset:', pr.getf('fff'))
                out('    rotate:', pr.getf('fff'))
                out('    length:', pr.getf('f')[0])
                out('  }')
            out('}]')
        elif cid == Chunks.Object.BONES1:
            out('bones: [{')
            for (_, d) in ChunkedReader(data):
                if _: out('}, {')
                dump_bone(ChunkedReader(d), oout)
            out('}]')
        elif cid == Chunks.Object.TRANSFORM:
            out('transform: {')
            out('  position:', pr.getf('fff'))
            out('  rotation:', pr.getf('fff'))
            out('}')
        elif cid == Chunks.Object.PARTITIONS0:
            out('partitions1: [{')
            for _ in range(pr.getf('I')[0]):
                if _: out('}, {')
                out('  name:', pr.gets())
                sz = pr.getf('I')[0]
                out('  bones:', pr.getf('%dI' % sz))
            out('}]')
        elif cid == Chunks.Object.PARTITIONS1:
            out('partitions1: [{')
            for _ in range(pr.getf('I')[0]):
                if _: out('}, {')
                out('  name:', pr.gets())
                sz = pr.getf('I')[0]
                out('  bones:', [pr.gets() for __ in range(sz)])
            out('}]')
        elif cid == Chunks.Object.MOTION_REFS:
            out('motion_refs:', pr.gets())
        elif cid == Chunks.Object.REVISION:
            out('revision: {')
            out('  owner:', pr.gets())
            out('  ctime:', time.ctime(pr.getf('I')[0]))
            out('  moder:', pr.gets())
            out('  mtime:', time.ctime(pr.getf('I')[0]))
            out('}')
        elif cid == Chunks.Object.MOTIONS:
            if opts.diff:
                out('motions-info:', 'count=' + str(pr.getf('I')[0]) + ', hash=' + calc_hash(data))
                continue
            out('motions: [{')
            for _ in range(pr.getf('I')[0]):
                if _: out('}, {')
                dump_motion(pr, oout)
            out('}]')
        elif cid == Chunks.Object.SMOTIONS3:
            out('smotions3:', [pr.gets() for _ in range(pr.getf('I')[0])])
        elif cid == Chunks.Object.LIB_VERSION:
            out('lib_version:', pr.getf('Q')[0])
        else:
            out('UNKNOWN OBJ CHUNK: {:#x}'.format(cid))