Conditions | 7 |
Total Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
6 | def __init__(self, fileName): |
||
7 | ''' Wavefront .obj file parser.''' |
||
8 | fcount = 0 |
||
9 | vcount = 0 |
||
10 | vtcount = 0 |
||
11 | vncount = 0 |
||
12 | matcount = 0 |
||
13 | |||
14 | __objpath = files.resolve_path('data', 'models', 'fileName' + '.obj') |
||
15 | __mtlpath = files.resolve_path('data', 'models', 'fileName' + '.mtl') |
||
16 | |||
17 | # Load the mtl file |
||
18 | self.mtlfile = MTL(__mtlpath) |
||
19 | |||
20 | # Load the obj file |
||
21 | objfile = open(fileName, "r") |
||
22 | |||
23 | # Do a head count |
||
24 | for line in objfile: |
||
25 | value = line[:2] |
||
26 | if value == 'f ': |
||
27 | fcount += 1 |
||
28 | elif value == 'v ': |
||
29 | vcount += 1 |
||
30 | elif value == 'vt': |
||
31 | vtcount += 1 |
||
32 | elif value == 'vn': |
||
33 | vncount += 1 |
||
34 | elif value == 'g ': |
||
35 | matcount += 1 |
||
36 | |||
37 | # Close the file |
||
38 | objfile.close() |
||
39 | |||
40 | fcount *= 3 |
||
41 | vcount *= 3 |
||
42 | vtcount *= 3 |
||
43 | vncount *= 3 |
||
44 | |||
45 | self.tempVertices = [None] * vcount |
||
46 | self.tempNormals = [None] * vncount |
||
47 | self.tempUVs = [None] * fcount |
||
48 | self.tempMaterials = [None] * matcount |
||
49 | |||
50 | self.vertexIndices = [None] * fcount |
||
51 | self.normalIndices = [None] * fcount |
||
52 | self.uvIndices = [None] * fcount |
||
53 | |||
54 | self.finalVertices = [None] * fcount |
||
55 | self.finalNormals = [None] * fcount |
||
56 | self.finalUVs = [None] * fcount |
||
57 | self.usedMaterials = [None] * matcount |
||
58 | |||
59 | self.fnumber = 0 |
||
60 | self.vnumber = 0 |
||
61 | self.vtnumber = 0 |
||
62 | self.vnnumber = 0 |
||
63 | self.matnumber = 0 |
||
64 | |||
65 | self.tmvnig = {} |
||
66 | self.fmvnig = {} |
||
67 | |||
68 | # Process the data |
||
69 | self.__process_in_house(__objpath) |
||
70 | # Finalize |
||
71 | self.get_final_data() |
||
72 | |||
154 |