Mesh Class Reference

A mesh contains the geometric (and optionally texture) data of the scene captured by spatial mapping. More...

Functions

def chunks (self)
 contains the list of chunks
 
def __getitem__ (self, x)
 gets a chunk from the list
 
def filter (self, params=MeshFilterParameters(), update_chunk_only=True)
 Filters the mesh. More...
 
def apply_texture (self, texture_format=MESH_TEXTURE_FORMAT.RGB)
 Applies texture to the mesh. More...
 
def save (self, str filename, typeMesh=MESH_FILE_FORMAT.OBJ, id=[])
 Saves the current Mesh into a file. More...
 
def load (self, str filename, update_mesh=False)
 Loads the mesh from a file. More...
 
def clear (self)
 Clears all the data.
 
def vertices (self)
 Vertices are defined by a 3D point (numpy array)
 
def triangles (self)
 List of triangles, defined as a set of three vertices. More...
 
def normals (self)
 Normals are defined by three components, {nx, ny, nz}. More...
 
def uv (self)
 UVs define the 2D projection of each vertex onto the texture . More...
 
def texture (self)
 Texture of the Mesh  . More...
 
def get_number_of_triangles (self)
 Computes the total number of triangles stored in all chunks. More...
 
def get_boundaries (self)
 Computes the indices of boundary vertices. More...
 
def merge_chunks (self, int faces_per_chunk)
 Merges current chunks. More...
 
def get_gravity_estimate (self)
 Estimates the gravity vector. More...
 
def get_visible_list (self, Transform camera_pose)
 Computes the list of visible chunks from a specific point of view. More...
 
def get_surrounding_list (self, Transform camera_pose, float radius)
 Computes the list of chunks which are close to a specific point of view. More...
 
def update_mesh_from_chunklist (self, id=[])
 Updates vertices / normals / triangles uv from chunk data pointed by given chunkList. More...
 

Detailed Description

A mesh contains the geometric (and optionally texture) data of the scene captured by spatial mapping.

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 Mesh is updated.

Functions

◆ filter()

def filter (   self,
  params = MeshFilterParameters(),
  update_chunk_only = True 
)

Filters the mesh.

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

Parameters
params: defines the filtering parameters, for more info checkout the MeshFilterParameters documentation. default : preset.  
update_chunk_only: if set to false the mesh data (vertices/normals/triangles) is updated otherwise only the chunk data is updated. default : true.
Returns
True if the filtering was successful, false otherwise.

 

Note
The filtering is a costly operation, its not recommended to call it every time you retrieve a mesh but at the end of your spatial mapping process.

◆ apply_texture()

def apply_texture (   self,
  texture_format = MESH_TEXTURE_FORMAT.RGB 
)

Applies texture to the mesh.

 By using this function you will get access to uv, and texture.  The number of triangles in the mesh may slightly differ before and after calling this function 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. Vectors of vertices/normals and uv have now the same size.  

Parameters
texture_format: defines the number of channels desired for the computed texture. default : MESH_TEXTURE_FORMAT.RGB.
Note
This function can be called as long as you do not start a new spatial mapping process, due to shared memory.
This function can require a lot of computation time depending on the number of triangles in the mesh. Its recommended to call it once a the end of your spatial mapping process.
Warning
The save_texture parameter in SpatialMappingParameters must be set as true when enabling the spatial mapping to be able to apply the textures.
The mesh should be filtered before calling this function since filter will erase the textures, the texturing is also significantly slower on non-filtered meshes.

◆ save()

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

Saves the current Mesh into a file.

Parameters
filename: the path and filename of the mesh.
typeMesh: defines the file type (extension). default : MESH_FILE_FORMAT.OBJ.  
id: specifies a set of chunks to be saved, if none provided all chunks are saved. default : (empty)
Returns
True if the file was successfully saved, false otherwise.    
Note
Only MESH_FILE_FORMAT.OBJ supports textures data.
This function operates on the Mesh not on the chunks. This way you can save different parts of your Mesh (update your Mesh with update_mesh_from_chunkList).

◆ load()

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

Loads the mesh from a file.

Parameters
filename: the path and filename of the mesh (do not forget the extension).  
update_mesh: if set to false the mesh data (vertices/normals/triangles) are updated otherwise only the chunk's data are updated. default : false.  
Returns
True if the loading was successful, false otherwise.

 

Note
Updating the Mesh is time consuming, consider using only Chunks for better performances.

◆ triangles()

def triangles (   self)

List of triangles, defined as a set of three vertices.

The information is stored in a numpy array

◆ normals()

def normals (   self)

Normals are defined by three components, {nx, ny, nz}.

Normals are defined for each vertex. (numpy array)

◆ uv()

def uv (   self)

UVs define the 2D projection of each vertex onto the texture .

(numpy array)  Values are normalized [0;1], starting 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 apply_texture

◆ texture()

def texture (   self)

Texture of the Mesh  .

Returns
a Mat containing the texture of the Mesh  
Note
Contains data only if your mesh has textures (by loading it or calling apply_texture).

◆ get_number_of_triangles()

def 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()

def get_boundaries (   self)

Computes the indices of boundary vertices.

 

Returns
The indices of boundary vertices.

◆ merge_chunks()

def merge_chunks (   self,
int  faces_per_chunk 
)

Merges current chunks.

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

Parameters
faces_per_chunk: defines the new number of faces per chunk (useful for Unity that doesn't handle chunks over 65K vertices).    
Note
You should not use this function during spatial mapping process because mesh updates will revert this changes.

◆ get_gravity_estimate()

def get_gravity_estimate (   self)

Estimates the gravity vector.

This function looks for a dominant plane in the whole mesh considering that it is the floor (or a horizontal plane). This can be used to find the gravity and then create realistic physical interactions.  

Returns
The gravity vector. (numpy array)

◆ get_visible_list()

def get_visible_list (   self,
Transform  camera_pose 
)

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

 

Parameters
camera_pose: the point of view, given in world reference.  
Returns
The list of visible chunks.

◆ get_surrounding_list()

def get_surrounding_list (   self,
Transform  camera_pose,
float  radius 
)

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

 

Parameters
camera_pose: the point of view, given in world reference.  
radius: the radius in defined UNIT  
Returns
The list of chunks close to the given point.

◆ update_mesh_from_chunklist()

def update_mesh_from_chunklist (   self,
  id = [] 
)

Updates vertices / normals / triangles uv from chunk data pointed by given chunkList.

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