class
MeshRepresents a mesh shape.
Contents
- Reference
Represents a loaded mesh file. A mesh can be seen as an object template. In order to be rendered, you need to instantiate it (see Object).
Typical usage
import stillleben as sl sl.init() # Load a mesh mesh = sl.Mesh('my_meshfile.gltf') # Add an object referencing the mesh to the scene obj = sl.Object(mesh) scene = sl.Scene((1920, 1080)) scene.add_object(obj)
Accessing and manipulating vertex data
You can use points, faces, colors, normals to access common vertex attributes. update_positions() and friends can be used to write vertex attributes.
Sub-Meshes
Some mesh file formats (such as .obj) may contain multiple sub-meshes with different properties and textures. Stillleben fully supports loading and working with such files. If you work with the mesh data itself (see points, faces), it will feel like working with a big concatenated mesh. This is more convenient in most situations and removes a level of indirection when performing vertex updates. All meshes live in the same coordinate system.
Enums
- class Flag: NONE = 0 PHYSICS_FORCE_CONVEX_HULL = 1
- Mesh flags
Static methods
- def load_threaded(filenames: typing.List[object], visual: bool = True, physics: bool = True, flags: typing.List[Flag] = []) -> typing.List[Mesh]
- Load multiple meshes using a thread pool.
Methods
- def center_bbox(self, /) -> None
- Center mesh.
- def dump_physics_meshes(self, arg0: str, /) -> None
- Write physics meshes in PLY format into the given directory.
- def scale_to_bbox_diagonal(self, target_diagonal: float, mode: str = 'exact') -> None
- Rescale mesh.
- def set_new_colors(self, new_colors: at::Tensor) -> None
- Set new vertex colors.
- def set_new_positions(self, new_positions: at::Tensor) -> None
- Set new vertex positions.
- def update_colors(self, vertex_indices: at::Tensor, color_update: at::Tensor) -> None
- Updates the mesh vertex colors.
- def update_positions(self, vertex_indices: at::Tensor, position_update: at::Tensor) -> None
- Updates the mesh vertex positions.
- def update_positions_and_colors(self, vertex_indices: at::Tensor, position_update: at::Tensor, color_update: at::Tensor) -> None
- Updates the mesh verticex positions and vertex colors.
Special methods
Properties
- bbox: Range3D get
- Mesh bounding box.
- class_index: int get set
- Class index for training semantic segmentation.
- colors: at::Tensor get
- The mesh colors as (Nx4) float tensor.
- faces: at::Tensor get
- The mesh faces as (N*3) int32 tensor.
- filename: str get
- The mesh filename
- normals: at::Tensor get
- The mesh normals as (Nx3) float tensor.
- physics_mesh_data: list get
- The convex decomposition used for physics simulation. This is a list of dicts, with the keys positions and indices.
- points: at::Tensor get
- The mesh vertices as (Nx3) float tensor.
- pretransform: at::Tensor get set
- The current pretransform matrix.
Method documentation
def stillleben. Mesh. load_threaded(filenames: typing.List[object],
visual: bool = True,
physics: bool = True,
flags: typing.List[Flag] = []) -> typing.List[Mesh] staticmethod
Load multiple meshes using a thread pool.
Parameters | |
---|---|
filenames | List of file names to load |
visual | Should we load visual components? |
physics | Should we load collision meshes? |
flags | Flags |
Returns | List of mesh instances |
def stillleben. Mesh. center_bbox(self, /) -> None
Center mesh.
Modifies the pretransform such that the bounding box (see bbox) is centered at the origin.
def stillleben. Mesh. scale_to_bbox_diagonal(self,
target_diagonal: float,
mode: str = 'exact') -> None
Rescale mesh.
Parameters | |
---|---|
target_diagonal | Target diagonal |
mode | Scaling mode (default 'exact'). If 'order_of_magnitude', the resulting scale factor is the nearest power of 10 that fits. This is useful for detecting the scale of arbitrary mesh files. |
Modifies the pretransform such that the bounding box diagonal (see bbox) is equal to target_diagonal.
def stillleben. Mesh. set_new_colors(self,
new_colors: at::Tensor) -> None
Set new vertex colors.
Parameters | |
---|---|
new_colors | Nx4 |
def stillleben. Mesh. set_new_positions(self,
new_positions: at::Tensor) -> None
Set new vertex positions.
Parameters | |
---|---|
new_positions | Nx3 |
def stillleben. Mesh. update_colors(self,
vertex_indices: at::Tensor,
color_update: at::Tensor) -> None
Updates the mesh vertex colors.
Parameters | |
---|---|
vertex_indices | N (dim=1) |
color_update | Nx4 |
def stillleben. Mesh. update_positions(self,
vertex_indices: at::Tensor,
position_update: at::Tensor) -> None
Updates the mesh vertex positions.
Parameters | |
---|---|
vertex_indices | N (dim=1) |
position_update | Nx3 |
def stillleben. Mesh. update_positions_and_colors(self,
vertex_indices: at::Tensor,
position_update: at::Tensor,
color_update: at::Tensor) -> None
Updates the mesh verticex positions and vertex colors.
Parameters | |
---|---|
vertex_indices | N (dim=1) |
position_update | Nx3 |
color_update | Nx4 |
Property documentation
stillleben. Mesh. class_index: int get set
Class index for training semantic segmentation.
Zero is usually reserved for the background class. Unlike Object.instance_index, this property is not set automatically.
stillleben. Mesh. colors: at::Tensor get
The mesh colors as (Nx4) float tensor.
stillleben. Mesh. faces: at::Tensor get
The mesh faces as (N*3) int32 tensor.
stillleben. Mesh. pretransform: at::Tensor get set
The current pretransform matrix.
This is initialized to identity and can be set directly or through center_bbox() and scale_to_bbox_diagonal().