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.trade.MeshAttributeData class

Mesh attribute data

Associates a typed data view with a name, vertex format and other mesh attribute properties, which can be subsequently put into a MeshData instance, for example with meshtools.interleave(). The data view can be either one-dimensional, for example a NumPy array:

data = np.array([(-0.5, 0.0),
                 (+0.5, 0.0),
                 ( 0.0, 0.5)], dtype='2f')
positions = trade.MeshAttributeData(
    trade.MeshAttribute.POSITION,
    VertexFormat.VECTOR2,
    data)

Or it can be two-dimensional, for example by expanding a flat array into a list of two-component vectors:

data = array.array('f', [-0.5, 0.0,
                         +0.5, 0.0,
                          0.0, 0.5])
positions = trade.MeshAttributeData(
    trade.MeshAttribute.POSITION,
    VertexFormat.VECTOR2,
    containers.StridedArrayView1D(data).expanded(0, (3, 2)))

Memory ownership and reference counting

On initialization, the instance inherits the containers.StridedArrayView1D.owner object, storing it in the owner field, meaning that calling del on the original data will not invalidate the instance.

Data access

Similarly to MeshData, the class makes use of Python’s dynamic nature and provides direct access to attribute data in their concrete type via data. However, the MeshAttributeData is considered a low level API and thus a containers.StridedArrayView2D is returned always, even for non-array attributes. The returned view inherits the owner and element access coverts to a type corresponding to a particular VertexFormat. For example, extracting the data from the positions attribute created above:

>>> view = positions.data
>>> view.owner is data
True
>>> view[1][0]
Vector(0.5, 0)

Special methods

def __init__(self, name: MeshAttribute, format: VertexFormat, data: corrade.containers.StridedArrayView1D, *, array_size: int = 0, morph_target_id: int = -1) -> None
Construct from a 1D view
def __init__(self, name: MeshAttribute, format: VertexFormat, data: corrade.containers.StridedArrayView2D, *, array_size: int = 0, morph_target_id: int = -1) -> None
Construct from a 2D view

Properties

array_size: int get
Attribute array size
data: corrade.containers.StridedArrayView2D get
Attribute data
format: VertexFormat get
Attribute format
morph_target_id: int get
Morph target ID
name: MeshAttribute get
Attribute name
owner: object get
Memory owner

Method documentation

def magnum.trade.MeshAttributeData.__init__(self, name: MeshAttribute, format: VertexFormat, data: corrade.containers.StridedArrayView1D, *, array_size: int = 0, morph_target_id: int = -1) -> None

Construct from a 1D view

Exceptions
AssertionError If format is not valid for name
AssertionError If data size doesn’t fit into 32 bits
AssertionError If data stride doesn’t fit into 16 bits
AssertionError If data format size is smaller than size of format at given array_size
AssertionError If morph_target_id is less than -1 or greater than 127
AssertionError If morph_target_id is not allowed for name
AssertionError If array_size is zero and name is an array attribute
AssertionError If array_size is non-zero and name can’t be an array attribute

def magnum.trade.MeshAttributeData.__init__(self, name: MeshAttribute, format: VertexFormat, data: corrade.containers.StridedArrayView2D, *, array_size: int = 0, morph_target_id: int = -1) -> None

Construct from a 2D view

Exceptions
AssertionError If format is not valid for name
AssertionError If data first dimension size doesn’t fit into 32 bits
AssertionError If data first dimension stride doesn’t fit into 16 bits
AssertionError If data second dimension isn’t contiguous
AssertionError If data format size times second dimension size is smaller than size of format at given array_size
AssertionError If morph_target_id is less than -1 or greater than 127
AssertionError If morph_target_id is not allowed for name
AssertionError If array_size is zero and name is an array attribute
AssertionError If array_size is non-zero and name can’t be an array attribute

Property documentation

magnum.trade.MeshAttributeData.data: corrade.containers.StridedArrayView2D get

Attribute data

Exceptions
NotImplementedError If format is a half-float or matrix type

A 2D view is returned always, non-array attributes have the second dimension size 1.