Welcome to Python-flavored Magnum! Please note that, while already being rather stable, this functionality is still considered experimental and some APIs might get changed without preserving full backwards compatibility.

magnum.meshtools module

Mesh tools

Enums

class CompileFlags: NONE = 0 GENERATE_FLAT_NORMALS = 1 GENERATE_SMOOTH_NORMALS = 2
Mesh compilation flags
class InterleaveFlags: NONE = 0 PRESERVE_INTERLEAVED_ATTRIBUTES = 1 PRESERVE_STRIDED_INDICES = 2
Interleaving behavior flags

Functions

def compile(mesh: trade.MeshData, flags: CompileFlags = CompileFlags.NONE) -> gl.Mesh
Compile 3D mesh data
def compress_indices(mesh: trade.MeshData, *, at_least: MeshIndexType = MeshIndexType.UNSIGNED_SHORT) -> trade.MeshData
Compress mesh data indices
def concatenate(meshes: list[trade.MeshData], flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData
Concatenate meshes together
def copy(mesh: trade.MeshData) -> trade.MeshData
Make an owned copy of the mesh
def duplicate(mesh: trade.MeshData) -> trade.MeshData
Duplicate indexed mesh data
def filter_attributes(mesh: trade.MeshData, attributes_to_keep: corrade.containers.BitArrayView) -> trade.MeshData
Filter a mesh to contain only the selected subset of attributes
def filter_except_attributes(mesh: trade.MeshData, attributes: list[trade.MeshAttribute]) -> trade.MeshData
Filter a mesh to contain everything except the selected subset of named attributes
def filter_only_attributes(mesh: trade.MeshData, attributes: list[trade.MeshAttribute]) -> trade.MeshData
Filter a mesh to contain only the selected subset of named attributes
def generate_indices(mesh: trade.MeshData) -> trade.MeshData
Convert a mesh to plain indexed lines or triangles
def interleave(mesh: trade.MeshData, *, extra: list[trade.MeshAttributeData] = [], flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData
Interleave mesh data
def remove_duplicates(mesh: trade.MeshData) -> trade.MeshData
Remove mesh data duplicates
def remove_duplicates_fuzzy(mesh: trade.MeshData, *, float_epsilon: float = 9.999999747378752e-06, double_epsilon: float = 1e-14) -> trade.MeshData
Remove mesh data duplicates
def transform2d(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData
Transform 2D positions in a mesh data
def transform2d_in_place(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1) -> None
Transform 2D positions in a mesh data in-place
def transform3d(mesh: trade.MeshData, transformation: Matrix4, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData
Transform 3D positions, normals, tangents and bitangents in a mesh data
def transform3d_in_place(mesh: trade.MeshData, transformation: Matrix4, *, id: int = 0, morph_target_id: int = -1) -> None
Transform 3D position, normals, tangents and bitangents in a mesh data in-place
def transform_texture_coordinates2d(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData
Transform 2D texture coordinates in a mesh data
def transform_texture_coordinates2d_in_place(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1) -> None
Transform 2D texture coordinates in a mesh data in-place

Function documentation

def magnum.meshtools.compress_indices(mesh: trade.MeshData, *, at_least: MeshIndexType = MeshIndexType.UNSIGNED_SHORT) -> trade.MeshData

Compress mesh data indices

Exceptions
AssertionError If mesh is not indexed

def magnum.meshtools.concatenate(meshes: list[trade.MeshData], flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData

Concatenate meshes together

Exceptions
AssertionError If meshes is empty
AssertionError If any of the meshes is MeshPrimitive.LINE_STRIP, MeshPrimitive.LINE_LOOP, MeshPrimitive.TRIANGLE_STRIP or MeshPrimitive.TRIANGLE_FAN
AssertionError If all meshes don’t have the same MeshPrimitive

def magnum.meshtools.duplicate(mesh: trade.MeshData) -> trade.MeshData

Duplicate indexed mesh data

Exceptions
AssertionError If mesh is not indexed

def magnum.meshtools.filter_attributes(mesh: trade.MeshData, attributes_to_keep: corrade.containers.BitArrayView) -> trade.MeshData

Filter a mesh to contain only the selected subset of attributes

Exceptions
AssertionError If size of attributes_to_keep is different than mesh attribute count

def magnum.meshtools.generate_indices(mesh: trade.MeshData) -> trade.MeshData

Convert a mesh to plain indexed lines or triangles

Exceptions
AssertionError If mesh is not MeshPrimitive.LINE_STRIP, MeshPrimitive.LINE_LOOP, MeshPrimitive.TRIANGLE_STRIP or MeshPrimitive.TRIANGLE_FAN

def magnum.meshtools.interleave(mesh: trade.MeshData, *, extra: list[trade.MeshAttributeData] = [], flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData

Interleave mesh data

Exceptions
AssertionError If any attribute in extra has the data size different from mesh vertex count

def magnum.meshtools.transform2d(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData

Transform 2D positions in a mesh data

Exceptions
KeyError If mesh doesn’t have trade.MeshAttribute.POSITION of index id (and in morph target morph_target_id if not -1)
AssertionError If trade.MeshAttribute.POSITION are not 2D

def magnum.meshtools.transform2d_in_place(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1) -> None

Transform 2D positions in a mesh data in-place

Exceptions
AssertionError If mesh vertex data aren’t trade.DataFlags.MUTABLE
KeyError If mesh doesn’t have trade.MeshAttribute.POSITION of index id (and in morph target morph_target_id if not -1)
AssertionError If trade.MeshAttribute.POSITION are not VertexFormat.VECTOR2

def magnum.meshtools.transform3d(mesh: trade.MeshData, transformation: Matrix4, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData

Transform 3D positions, normals, tangents and bitangents in a mesh data

Exceptions
KeyError If mesh doesn’t have trade.MeshAttribute.POSITION of index id (and in morph target morph_target_id if not -1)
AssertionError If trade.MeshAttribute.POSITION are not 3D

def magnum.meshtools.transform3d_in_place(mesh: trade.MeshData, transformation: Matrix4, *, id: int = 0, morph_target_id: int = -1) -> None

Transform 3D position, normals, tangents and bitangents in a mesh data in-place

Exceptions
AssertionError If mesh vertex data aren’t trade.DataFlags.MUTABLE
KeyError If mesh doesn’t have trade.MeshAttribute.POSITION of index id (and in morph target morph_target_id if not -1)
AssertionError If trade.MeshAttribute.POSITION are not VertexFormat.VECTOR3

def magnum.meshtools.transform_texture_coordinates2d(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1, flags: InterleaveFlags = InterleaveFlags.PRESERVE_INTERLEAVED_ATTRIBUTES) -> trade.MeshData

Transform 2D texture coordinates in a mesh data

Exceptions
KeyError If mesh doesn’t have trade.MeshAttribute.TEXTURE_COORDINATES of index id (and in morph target morph_target_id if not -1)

def magnum.meshtools.transform_texture_coordinates2d_in_place(mesh: trade.MeshData, transformation: Matrix3, *, id: int = 0, morph_target_id: int = -1) -> None

Transform 2D texture coordinates in a mesh data in-place

Exceptions
AssertionError If mesh vertex data aren’t trade.DataFlags.MUTABLE
KeyError If mesh doesn’t have trade.MeshAttribute.TEXTURE_COORDINATES of index id (and in morph target morph_target_id if not -1)
AssertionError If trade.MeshAttribute.TEXTURE_COORDINATES are not VertexFormat.VECTOR2