def _load_vertex_buffers(self): """Load each vertex buffer into each material""" fd = gzip.open(cache_name(self.file_name), 'rb') for buff in self.meta.vertex_buffers: mat = self.wavefront.materials.get(buff['material']) if not mat: mat = Material(name=buff['material'], is_default=True) self.wavefront.materials[mat.name] = mat mat.vertex_format = buff['vertex_format'] self.load_vertex_buffer(fd, mat, buff['byte_length']) fd.close()
def parse_f(self): # Add default material if not created if self.material is None: self.material = Material( "default{}".format(len(self.wavefront.materials)), is_default=True, has_faces=self.collect_faces ) self.wavefront.materials[self.material.name] = self.material # Support objects without `o` statement if self.mesh is None: self.mesh = Mesh(has_faces=self.collect_faces) self.wavefront.add_mesh(self.mesh) self.mesh.add_material(self.material) self.mesh.add_material(self.material) collected_faces = [] consumed_vertices = self.consume_faces(collected_faces if self.collect_faces else None) self.material.vertices += list(consumed_vertices) if self.collect_faces: self.mesh.faces += list(collected_faces) # Since list() also consumes StopIteration we need to sanity check the line # to make sure the parser advances if self.values and self.values[0] == "f": self.next_line()
def parse_usemtl(self): name = " ".join(self.values[1:]) self.material = self.wavefront.materials.get(name, None) if self.material is None: if not self.create_materials: raise PywavefrontException('Unknown material: %s' % name) # Create a new default material if configured to resolve missing ones self.material = Material(name, is_default=True, has_faces=self.collect_faces) self.wavefront.materials[name] = self.material if self.mesh is not None: self.mesh.add_material(self.material)
def parse_f(self): # Support objects without `o` statement if self.mesh is None: self.mesh = Mesh() self.wavefront.add_mesh(self.mesh) # Add default material if not created if self.material is None: self.material = Material(is_default=True) self.wavefront.materials[self.material.name] = self.material self.mesh.add_material(self.material) self.material.vertices += list(self.consume_faces()) # Since list() also consumes StopIteration we need to sanity check the line # to make sure the parser advances if self.values[0] == "f": self.next_line()