pyFM.mesh.file_utils¶
Functions
|
Extracts UV coordinates for a mesh for a .obj file |
|
Read a .obj file containing a mesh. |
|
read a standard .off file |
|
Read a .tri file from TOSCA dataset |
|
Read a .vert file from TOSCA dataset |
|
Writes a .mtl file for a .obj mesh. |
|
Writes a .obj file with texture. |
|
Writes a .obj file with texture, with a simpler interface than write_obj. |
|
Writes a mesh to a .off file |
- pyFM.mesh.file_utils.read_off(filepath, read_colors=False)¶
read a standard .off file
Read a .off file containing vertex and face information, and possibly face colors.
- Parameters:
file (str) – path to a ‘.off’-format file
read_colors (bool, optional) – bool - whether to read colors if present
- Returns:
vertices (np.ndarray) – (n,3) array of vertices coordinates
faces (np.ndarray) – (m,3) array of indices of face vertices
colors (np.ndarray, optional) – (m,3) Only if read_colors is True. Array of colors for each face. None if not found.
- pyFM.mesh.file_utils.read_obj(filepath, load_normals=False, load_texture=False, load_texture_normals=False)¶
Read a .obj file containing a mesh.
- Parameters:
filepath (str) – path to the .obj file
load_normals (bool, optional) – whether to load vertex normals if present
load_texture (bool, optional) – whether to load texture coordinates if present. Reads both uv coordinates and face to texture vertex indices
load_texture_normals (bool, optional) – whether to load texture normals if present. Reads face to texture normal indices
- Returns:
vertices (np.ndarray) – (n,3) array of vertices coordinates
faces (np.ndarray) – (m,3) array of indices of face vertices, None if not present
normals (np.ndarray, optional) – Only if load_normals is True. (n,3) array of vertex normals, None if not present
uv (np.ndarray, optional) – Only if load_texture is True (n,2) array of uv coordinates, None if not present
fvt (np.ndarray, optional) – Only if load_texture is True (m,3) array of indices of face to vertex texture (vt) indices, None if not present
fnt (np.ndarray, optional) – Only if load_texture_normals is True (m,3) array of indices of face to texture normal indices, None if not present
- pyFM.mesh.file_utils.write_off(filepath, vertices, faces, precision=None, face_colors=None)¶
Writes a mesh to a .off file
The number of significant digit to use can be specified for memory saving.
- Parameters:
filepath (str) – path to the .off file to write
vertices (np.ndarray) – (n,3) array of vertices coordinates
faces (np.ndarray) – (m,3) array of indices of face vertices
precision (int, optional) – number of significant digits to write for each float. Defaults to 16
face_colors (np.ndarray, optional) – (m,3) array of colors for each face
- pyFM.mesh.file_utils.write_obj(filepath, vertices, faces=None, uv=None, fvt=None, fnt=None, vertex_normals=None, mtl_path=None, mtl_name='material_0', precision=None)¶
Writes a .obj file with texture.
If material is used, the .mtl file will be copied to the same directory as the .obj file.
- Parameters:
filepath (str) – path to the .obj file to write
vertices (np.ndarray) – (n,3) array of vertices coordinates
faces (np.ndarray, optional) – (m,3) array of indices of face vertices
uv (np.ndarray, optional) – (n,2) array of uv coordinates
fvt (np.ndarray, optional) – (m,3) array of indices of face to vertex texture indices
fnt (np.ndarray, optional) – (m,3) array of indices of face to texture normal indices
vertex_normals (np.ndarray, optional) – (n,3) array of vertex normals
mtl_path (str, optional) – path to the .mtl file defining the material
mtl_name (str, optional) – name of the material in the .mtl file
precision (int, optional) – number of significant digits to write for each float
- pyFM.mesh.file_utils.read_vert(filepath)¶
Read a .vert file from TOSCA dataset
- Parameters:
filepath (str) – path to file
- Returns:
vertices – (n,3) array of vertices coordinates
- Return type:
np.ndarray
- pyFM.mesh.file_utils.read_tri(filepath, from_matlab=True)¶
Read a .tri file from TOSCA dataset
- Parameters:
filepath (str) – path to file
from_matlab (bool, optional) – If True, file indexing starts at 1
- Returns:
faces – (m,3) array of vertices indices to define faces
- Return type:
np.ndarray
- pyFM.mesh.file_utils.write_mtl(filepath, texture_im='texture_1.jpg')¶
Writes a .mtl file for a .obj mesh.
Use the name of a texture image to define the material.
- Parameters:
filepath (str) – path to file
texture_im (str, optional) – name of the image of texture. Default to ‘texture_1.jpg’, included in the package
- pyFM.mesh.file_utils.get_uv(vertices, ind1, ind2, mult_const=1)¶
Extracts UV coordinates for a mesh for a .obj file
- Parameters:
vertices – (n,3) coordinates of vertices
ind1 (int) – column index to use as first coordinate
ind2 (int) – column index to use as second coordinate
mult_const (float) – number of time to repeat the pattern
- Returns:
uv – (n,2) UV coordinates of each vertex
- Return type:
float
- pyFM.mesh.file_utils.write_obj_texture(filepath, vertices, faces, uv=None, mtl_file='material.mtl', texture_im='texture_1.jpg', mtl_name=None, precision=6, vertex_normals=None, verbose=False)¶
Writes a .obj file with texture, with a simpler interface than write_obj.
This function writes mtl files and copy textures if necessary
- Parameters:
filepath (str) – path to the .obj file to write
vertices (np.ndarray) – (n,3) coordinates of vertices
faces (np.ndarray) – (m,3) faces defined by vertex indices
uv (np.ndarray, optional) – (n,2) UV coordinates of each vertex
mtl_file (str, optional) – name or path of the .mtl file. If just a name, a default material will be created.
texture_im (str, optional) – name or path of the .jpg file defining texture
mtl_name (str, optional) – name of the material in the .mtl file
precision (int, optional) – number of significant digits to write for each float
vertex_normals (np.ndarray, optional) – (n,3) array of vertex normals
verbose (bool, optional) – whether to print information