Ejemplo n.º 1
0
 def __init__(self, filePath):
     self.width = 0
     self.height = 0
     self.materials = []
     self.lights = []
     self.spheres = []
     f = open(filePath)
     section = ''
     for line in f:
         l = line.strip()
         if section == '':
             if len(l) != 0:
                 if l[:2] != '//':
                     section = l
         else:
             if section.find('Scene') != -1:
                 if l == '{':
                     pass
                 elif l == '}':
                     section = ''
                 else:
                     words = l.split('=')
                     if words[0] == 'Width':
                         self.width = convertStr(words[1])
                     elif words[0] == 'Height':
                         self.height = convertStr(words[1])
             elif section.find('Material') != -1:
                 if l == '{':
                     tempMat = Material()
                 elif l == '}':
                     self.materials.append(tempMat)
                     section = ''
                 else:
                     words = l.split('=')
                     if words[0] == 'Diffuse':
                         params = words[1].split()
                         tempMat.setDiffuse(Color(convertStr(params[0]),convertStr(params[1]),convertStr(params[2])))
                     elif words[0] == 'Reflection':
                         tempMat.setReflection(convertStr(words[1]))
                     elif words[0] == 'Id':
                         tempMat.setId(convertStr(words[1]))
             elif section.find('Sphere') != -1:
                 if l == '{':
                     tempSphere = Sphere()
                 elif l == '}':
                     self.spheres.append(tempSphere)
                     section = ''
                 else:
                     words = l.split('=')
                     if words[0] == 'Center':
                         params = words[1].split()
                         tempSphere.setPosition(Point(convertStr(params[0]),convertStr(params[1]),convertStr(params[2])))
                     elif words[0] == 'Size':
                         tempSphere.setSize(convertStr(words[1]))
                     elif words[0] == 'Material':
                         tempSphere.setMaterial(convertStr(words[1]))
             elif section.find('Light') != -1:
                 if l == '{':
                     tempLight = Light()
                 elif l == '}':
                     self.lights.append(tempLight)
                     section = ''
                 else:
                     words = l.split('=')
                     if words[0] == 'Position':
                         params = words[1].split()
                         tempLight.setPosition(Point(convertStr(params[0]),convertStr(params[1]),convertStr(params[2])))
                     elif words[0] == 'Intensity':
                         params = words[1].split()
                         tempLight.setIntensity(Color(convertStr(params[0]),convertStr(params[1]),convertStr(params[2])))