Bonjour à tous,

J'aimerais parser un fichier BSP (map Quake3) mais je ne sais pas du tout comment m'y prendre.

J'ai :
- la structure du fichier,
- un exemple en python (recherche de textures utilisées):

Code python : Sélectionner tout - Visualiser dans une fenêtre à part
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
import sys
import construct as cs
 
class _VMod4(cs.Validator):
    def _validate(self, obj, ctx):
        return obj % 4 == 0
 
_bsp_f = cs.Struct('bsp',
                   cs.Struct('header',
                             cs.OneOf(cs.String('magic', 4, encoding=None, padchar='\x00'), ["IBSP"]),
                             cs.OneOf(cs.SLInt32('version'), [46]),
                             cs.Array(17,
                                      cs.Struct('direntry',
                                                cs.SLInt32('offset'),
                                                _VMod4(cs.SLInt32('length')),
                                               ),
                                      ),
                            ),
                   cs.Pointer(lambda ctx : ctx.header.direntry[1].offset,
                              cs.MetaRepeater(lambda ctx : ctx.header.direntry[1].length / 72,
                                              cs.Struct('texture',
                                                        cs.String('name', 64, encoding=None, padchar='\x00'),
                                                        cs.SLInt32('flags'),
                                                        cs.SLInt32('content'),
                                                       ),
                                             ),
                             ),
 
                   )
 
 
def main():
    if len(sys.argv) < 2:
        print 'usage : python bsp.py map.bsp'
        exit(1)
 
    input = open(sys.argv[1], 'r')
    bsp = _bsp_f.parse(input.read())
    print "\n".join(t.name for t in bsp.texture)
    input.close()
 
if __name__ == '__main__':
    main()

- un fichier BSP.

Merci pour votre aide.