Mesh Class Reference

Class representing a mesh and containing the geometric (and optionally texture) data of the scene captured by the spatial mapping module. More...

Functions

list[Chunkchunks (self)
 List of chunks constituting the sl.Mesh.
 
Chunk __getitem__ (self, x)
 Gets a chunk from chunks.
 
bool filter (self, params=MeshFilterParameters(), update_chunk_only=False)
 Filters the mesh. More...
 
bool apply_texture (self, texture_format=MESH_TEXTURE_FORMAT.RGB)
 Applies a texture to the mesh. More...
 
bool save (self, str filename, typeMesh=MESH_FILE_FORMAT.OBJ, id=[])
 Saves the current sl.Mesh into a file. More...
 
bool load (self, str filename, update_mesh=False)
 Loads the mesh from a file. More...
 
None clear (self)
 Clears all the data.
 
np.array[float] vertices (self)
 NumPy array of vertices. More...
 
np.array[int] triangles (self)
 NumPy array of triangles/faces. More...
 
np.array[float] normals (self)
 NumPy array of normals. More...
 
np.array[int] colors (self)
 NumPy array of colors. More...
 
np.array[float] uv (self)
 UVs defines the 2D projection of each vertices onto the texture. More...
 
Mat texture (self)
 Texture of the sl.Mesh. More...
 
int get_number_of_triangles (self)
 Computes the total number of triangles stored in all chunks. More...
 
np.array[int] get_boundaries (self)
 Compute the indices of boundary vertices. More...
 
None merge_chunks (self, int faces_per_chunk)
 Merges current chunks. More...
 
np.array[float] get_gravity_estimate (self)
 Estimates the gravity vector. More...
 
list[int] get_visible_list (self, Transform camera_pose)
 Computes the id list of visible chunks from a specific point of view. More...
 
list[int] get_surrounding_list (self, Transform camera_pose, float radius)
 Computes the id list of chunks close to a specific point of view. More...
 
None update_mesh_from_chunklist (self, id=[])
 Updates vertices / normals / triangles / uv from chunk data pointed by the given list of id. More...
 

Detailed Description

Class representing a mesh and containing the geometric (and optionally texture) data of the scene captured by the spatial mapping module.

By default the mesh is defined as a set of chunks.
This way we update only the data that has to be updated avoiding a time consuming remapping process every time a small part of the sl.Mesh is updated.

Functions

◆ filter()

bool filter (   self,
  params = MeshFilterParameters(),
  update_chunk_only = False 
)

Filters the mesh.

The resulting mesh is smoothed, small holes are filled, and small blobs of non-connected triangles are deleted.

Parameters
params: Filtering parameters. Default: a preset of sl.MeshFilterParameters.
update_chunk_only: Whether to only update chunks (and not vertices / normals / triangles).
Default: False.
Returns
True if the mesh was successfully filtered, otherwise False.
Note
The filtering is a costly operation.
It is not recommended to call it every time you retrieve a mesh but only at the end of your spatial mapping process.

◆ apply_texture()

bool apply_texture (   self,
  texture_format = MESH_TEXTURE_FORMAT.RGB 
)

Applies a texture to the mesh.

By using this method you will get access to uv, and texture.
The number of triangles in the mesh may slightly differ before and after calling this method due to missing texture information.
There is only one texture for the mesh, the uv of each chunk are expressed for it in its entirety.
NumPy arrays of vertices / normals and uv have now the same size.

Parameters
texture_format: Number of channels desired for the computed texture.
Default: sl.MESH_TEXTURE_FORMAT.RGB.
Returns
True if the mesh was successfully textured, otherwise False.
Note
This method can be called as long as you do not start a new spatial mapping process (due to shared memory).
This method can require a lot of computation time depending on the number of triangles in the mesh.
It is recommended to call it once at the end of your spatial mapping process.
Warning
The sl.SpatialMappingParameters.save_texture parameter must be set to True when enabling the spatial mapping to be able to apply the textures.
The mesh should be filtered before calling this method since filter() will erase the textures.
The texturing is also significantly slower on non-filtered meshes.

◆ save()

bool save (   self,
str  filename,
  typeMesh = MESH_FILE_FORMAT.OBJ,
  id = [] 
)

Saves the current sl.Mesh into a file.

Parameters
filename: Path of the file to store the mesh in.
typeMesh: File extension type. Default: sl.MESH_FILE_FORMAT.OBJ.
id: Set of chunks to be saved. Default: (empty) (all chunks are saved)
Returns
True if the file was successfully saved, otherwise False.
Note
Only sl.MESH_FILE_FORMAT.OBJ supports textures data.
This method operates on the sl.Mesh not on chunks.
This way you can save different parts of your sl.Mesh by updating it with update_mesh_from_chunklist().

◆ load()

bool load (   self,
str  filename,
  update_mesh = False 
)

Loads the mesh from a file.

Parameters
filename: Path of the file to load the mesh from.
update_mesh: Whether to only load data in chunks (and not vertices / normals / triangles).
Default: False.
Returns
True if the mesh was successfully loaded, otherwise False.
Note
Updating a sl::Mesh is time consuming. Consider using only chunks for better performances.

◆ vertices()

np.array[float] vertices (   self)

NumPy array of vertices.

Vertices are defined by a 3D point [x, y, z].

◆ triangles()

np.array[int] triangles (   self)

NumPy array of triangles/faces.

Triangle defined as a set of three vertices indexes [v1, v2, v3].

◆ normals()

np.array[float] normals (   self)

NumPy array of normals.

Normals are defined by three components [nx, ny, nz].

Note
A normal is defined for each vertex.

◆ colors()

np.array[int] colors (   self)

NumPy array of colors.

Colors are defined by three components [r, g, b].

Note
A color is defined for each vertex.

◆ uv()

np.array[float] uv (   self)

UVs defines the 2D projection of each vertices onto the texture.

Values are normalized [0, 1] and start from the bottom left corner of the texture (as requested by OpenGL). In order to display a textured mesh you need to bind the texture and then draw each triangle by picking its uv values.

Note
Contains data only if your mesh has textures (by loading it or calling sl.Mesh.apply_texture()).

◆ texture()

Mat texture (   self)

Texture of the sl.Mesh.

Note
Contains data only if your mesh has textures (by loading it or calling sl.Mesh.apply_texture()).

◆ get_number_of_triangles()

int get_number_of_triangles (   self)

Computes the total number of triangles stored in all chunks.

Returns
The number of triangles stored in all chunks.

◆ get_boundaries()

np.array[int] get_boundaries (   self)

Compute the indices of boundary vertices.

Returns
The indices of boundary vertices.

◆ merge_chunks()

None merge_chunks (   self,
int  faces_per_chunk 
)

Merges current chunks.

This method can be used to merge chunks into bigger sets to improve rendering process.

Parameters
faces_per_chunk: Number of faces per chunk.
Note
This method is useful for Unity, which does not handle chunks with more than 65K vertices.
Warning
This method should not be called during spatial mapping process since mesh updates will revert this changes.

◆ get_gravity_estimate()

np.array[float] get_gravity_estimate (   self)

Estimates the gravity vector.

This method looks for a dominant plane in the whole mesh considering that it is the floor (or a horizontal plane).

Returns
The estimated gravity vector (NumPy array).
Note
This can be used to find the gravity to create realistic physical interactions.

◆ get_visible_list()

list[int] get_visible_list (   self,
Transform  camera_pose 
)

Computes the id list of visible chunks from a specific point of view.

Parameters
camera_pose: Point of view (given in the same reference as the vertices).
Returns
The list of id of visible chunks.

◆ get_surrounding_list()

list[int] get_surrounding_list (   self,
Transform  camera_pose,
float  radius 
)

Computes the id list of chunks close to a specific point of view.

Parameters
camera_pose: Point of view (given in the same reference as the vertices).
radius: Radius determining closeness (given in the same unit as the mesh).
Returns
The list of id of chunks close to the given point.

◆ update_mesh_from_chunklist()

None update_mesh_from_chunklist (   self,
  id = [] 
)

Updates vertices / normals / triangles / uv from chunk data pointed by the given list of id.

Parameters
id: Indices of chunks which will be concatenated. Default: (empty).
Note
If the given list of id is empty, all chunks will be used to update the current sl.Mesh.