| Conditions | 7 |
| Total Lines | 57 |
| 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 | # Load the file |
||
| 15 | objfile = open(fileName, "r") |
||
| 16 | |||
| 17 | # Do a head count |
||
| 18 | for line in objfile: |
||
| 19 | value = line[:2] |
||
| 20 | if value == 'f ': |
||
| 21 | fcount += 1 |
||
| 22 | elif value == 'v ': |
||
| 23 | vcount += 1 |
||
| 24 | elif value == 'vt': |
||
| 25 | vtcount += 1 |
||
| 26 | elif value == 'vn': |
||
| 27 | vncount += 1 |
||
| 28 | elif value == 'g ': |
||
| 29 | matcount += 1 |
||
| 30 | |||
| 31 | fcount *= 3 |
||
| 32 | vcount *= 3 |
||
| 33 | vtcount *= 3 |
||
| 34 | vncount *= 3 |
||
| 35 | |||
| 36 | self.tempVertices = [None] * vcount |
||
| 37 | self.tempNormals = [None] * vncount |
||
| 38 | self.tempUVs = [None] * fcount |
||
| 39 | self.tempMaterials = [None] * matcount |
||
| 40 | |||
| 41 | self.vertexIndices = [None] * fcount |
||
| 42 | self.normalIndices = [None] * fcount |
||
| 43 | self.uvIndices = [None] * fcount |
||
| 44 | |||
| 45 | self.finalVertices = [None] * fcount |
||
| 46 | self.finalNormals = [None] * fcount |
||
| 47 | self.finalUVs = [None] * fcount |
||
| 48 | self.usedMaterials = [None] * matcount |
||
| 49 | |||
| 50 | self.fnumber = 0 |
||
| 51 | self.vnumber = 0 |
||
| 52 | self.vtnumber = 0 |
||
| 53 | self.vnnumber = 0 |
||
| 54 | self.matnumber = 0 |
||
| 55 | |||
| 56 | # Process the data |
||
| 57 | self.__process_in_house(objfile) |
||
| 58 | # Finalize |
||
| 59 | self.get_final_data() |
||
| 60 | |||
| 61 | # Close the file |
||
| 62 | objfile.close() |
||
| 63 | |||
| 135 |