Esempio n. 1
0
    def parse_f(self, args):
        if (len(self.tex_coords) > 1) and (len(self.normals) == 1):
            # does the spec allow for texture coordinates without normals?
            # if we allow this condition, the user will get a black screen
            # which is really confusing
            raise PywavefrontException(
                'Found texture coordinates, but no normals')

        if self.mesh is None:
            self.mesh = mesh.Mesh()
            self.wavefront.add_mesh(self.mesh)
        if self.material is None:
            self.material = material.Material()
            self.material.colors = []
            self.wavefront.materials[self.material.name] = self.material
        self.mesh.add_material(self.material)

        # For fan triangulation, remember first and latest vertices
        v1 = None
        vlast = None
        points = []
        has_color = isinstance(self.material.colors, list)
        for i, v in enumerate(args[0:]):
            if type(v) is bytes:
                v = v.decode()
            v_index, t_index, n_index = \
                (list(map(int, [j or 0 for j in v.split('/')])) + [0, 0])[:3]
            if v_index < 0:
                v_index += len(self.vertices) - 1
            if t_index < 0:
                t_index += len(self.tex_coords) - 1
            if n_index < 0:
                n_index += len(self.normals) - 1
            vertex = list(self.tex_coords[t_index]) + \
                     list(self.normals[n_index]) + \
                     list(self.vertices[v_index])

            if has_color:
                self.material.colors += list(self.colors[v_index])

            if i >= 3:
                # Triangulate
                self.material.vertices += v1 + vlast
            self.material.vertices += vertex

            if i == 0:
                v1 = vertex
            vlast = vertex
Esempio n. 2
0
 def parse_o(self, args):
     [o] = args
     self.mesh = mesh.Mesh(o)
     self.wavefront.add_mesh(self.mesh)