def from_obj(cls, filepath, precision='3f'): network = cls() obj = OBJ(filepath, precision=precision) vertices = obj.parser.vertices edges = obj.parser.lines for i, (x, y, z) in enumerate(vertices): network.add_vertex(i, x=x, y=y, z=z) for u, v in edges: network.add_edge(u, v) return network
def from_obj(cls, filepath): obj = OBJ(filepath) vertices = obj.parser.vertices faces = obj.parser.faces groups = obj.parser.groups cells = [] for name in groups: group = groups[name] cell = [] for item in group: if item[0] != 'f': continue face = faces[item[1]] cell.append(face) cells.append(cell) return cls.from_vertices_and_cells(vertices, cells)
def from_obj(cls, filepath, **kwargs): """Initialise a mesh from the data described in an obj file. Parameters: filepath (str): The path to the obj file. kwargs (dict) : Remaining named parameters. Default is an empty :obj:`dict`. Returns: Mesh: A ``Mesh`` of class ``cls``. >>> mesh = Mesh.from_obj('path/to/file.obj') """ mesh = cls() mesh.attributes.update(kwargs) obj = OBJ(filepath) vertices = obj.parser.vertices faces = obj.parser.faces for x, y, z in vertices: mesh.add_vertex(x=x, y=y, z=z) for face in faces: mesh.add_face(face) return mesh