Skip to content

Face

Face(a=None, mode='COPY', selector=None, attr_from=None, **attrs)

Mesh face (polygon) domain.

Inherits loop bookkeeping from :class:FaceSplineDomain and provides face-level operations: area/normal/centroid computation, edge extraction, attribute transfers, and topology-aware deletions.

Attributes:

Name Type Description
loop_start (F,) int

Starting corner index of each face.

loop_total (F,) int

Number of corners per face.

material_index (F,) int, optional

Material index per face.

sharp_face (F,) bool, optional

Sharp shading flag.

Methods:

Name Description
delete_loops

Delete faces and their incident corners; returns removed vertex indices.

get_edges

Unique undirected edges present in the mesh faces.

get_position

Face centroids by averaging incident vertex positions.

area_vectors

Area-weighted normal vectors (unnormalized).

area

Face areas.

normal

Unit normals.

sequences

Per-face sequences of vertex indices.

compute_attribute_on_points

Average a face attribute back to points.

Examples:

Compute normals and areas:

n = faces.normal(corners, points)
A = faces.area(corners, points)

Extract unique edges:

edges = faces.get_edges(corners)

Note: Area vectors are computed by triangulating polygons and summing triangle cross products.

Warning: After deleting faces via :meth:delete_loops, update dependent domains accordingly (e.g., rebuild edges if needed).

Initialize a domain array and its attribute schema.

Initializes the storage from an existing array/domain or creates an empty structure. Optionally merges attribute definitions/values from another domain and keyword-provided attributes.

Domains are never instancied directly but by owning geometries.

Actual Domains are Vertex, [Faces][npblender.Faces], Corner, Edge, ControlPoint, Spline and Point.

Domains are initialized with their defaults attributes, for instance position for point domaines.

Use attributes can be freely added.

Note: user attributes are saved in Blender Mesh objects only, Blender Curve objects don't store user attributes.

Parameters:

Name Type Description Default
a array - like or FieldArray or None

Source data used to initialize the domain. If None, an empty domain is created and _declare_attributes() is called to register defaults.

None
mode (COPY, CAPTURE, EMPTY)

Initialization mode. 'COPY' duplicates the input data, 'CAPTURE' references the input buffer when supported, 'EMPTY' creates the structure without copying values.

'COPY'
selector Any

Optional row/element selector applied to a prior to initialization.

None
attr_from Domain or Mapping or None

Attribute schema (and possibly values) to merge into this domain.

None
**attrs

Additional attribute name/value pairs to inject or override.

{}
Notes

The effective attribute list results from _declare_attributes(), then attr_from, then **attrs (later entries take precedence).

Examples:

cube = Mesh.cube() # points, corners, faces and edges domains are created
# Adding named attribute to point domain
cube.points.new_float('age')
# Setting the age
cube.points.age = np.random.uniforme(10, 10, len(cube.points))

actual_names property

actual_names

Column names.

Returns the actual field names, excluding optional fields.

all_names property

all_names

Column names.

Returns all the field names, including optional ones.

dtype property

dtype

Array structured dtype

Returns the dtype property of the structured array.

next_loop_start property

next_loop_start

Offset to use for the next appended item.

Returns:

Type Description
int

loop_start[-1] + loop_total[-1] if the domain is non-empty, otherwise 0.

See Also

[compute_loop_start][npblender.FaceSplineDomain.compute_loop_start]

reversed_indices property

reversed_indices

Map each corner/control-point index back to its owning item.

Returns:

Type Description
ndarray of shape ``(sum(loop_total),)``

For index k in the flattened corner/control-point array, the value is the face/spline index that owns k.

transdom_names property

transdom_names

List the names of trans-domain attributes.

Returns:

Type Description
list of str

Names of attributes flagged with transdom=True.

Examples:

names = D.transdom_names()

__array__

__array__(dtype=None)

Allow implicit conversion to np.ndarray

add

add(count, **fields)

Add count records

New records are set with default values or values provided by the user in fields dict.

Parameters:

Name Type Description Default
count int

Number of records to add.

required
fields dict

Keyword arguments mapping field names to values.

{}

append

append(**fields)

Append values to the structured array.

The number of records to append is determined by the number of fields provided in the fields dictionary. The values of the fields are copied to the new records.

Parameters:

Name Type Description Default
fields dict

Keyword arguments mapping field names to values.

{}

append_sizes

append_sizes(sizes, **fields)

Append new items given their sizes.

If loop_start is not provided in fields, computes it from sizes using [compute_loop_start][npblender.FaceSplineDomain.compute_loop_start].

Parameters:

Name Type Description Default
sizes array-like of int or None

Number of corners/control-points for each new item.

required
**fields

Additional per-item attributes to append (e.g., material_index).

{}

Returns:

Type Description
Any

The value returned by append(...) (implementation-defined, often the indices/slice of appended items).

Notes

Passing sizes=None is a no-op and returns an empty list.

area

area(corners, points)

Compute face areas.

Returns the scalar area of each polygonal face by taking half the Euclidean norm of its area-weighted normal vector (see [area_vectors][npblender.Face.area_vectors]).

Parameters:

Name Type Description Default
corners Corner

Corner domain providing the per-corner vertex_index.

required
points Point

Point (vertex) domain providing position of shape (P, 3).

required

Returns:

Type Description
numpy.ndarray of shape ``(F,)`` and dtype float

Area per face.

Notes
  • Internally, faces are triangulated and triangle cross-products are summed to form area vectors; the area is half the vector norm. See [area_vectors][npblender.Face.area_vectors] for details.
  • Degenerate faces (zero area) produce zeros here.
See Also

[area_vectors][npblender.Face.area_vectors] normal get_surface

as_kwargs

as_kwargs(selector=None, include=None, exclude=None)

Return a dictionary of field values formatted as kwargs.

Parameters:

Name Type Description Default
selector slice, int, list, or mask

Optional selection of elements to extract.

None
include list[str]

List of field names (original or python names) to include.

None
exclude list[str]

List of field names (original or python names) to exclude.

None

Returns:

Type Description
dict

Mapping from python-safe field names to array values.

check

check(count, halt=True)

Validate loop counters against a reference element count.

Verifies that the sum of loop_total equals count (i.e., the total number of referenced elements such as corners or control points).

Parameters:

Name Type Description Default
count int

Expected total number of elements referenced by all items.

required
halt bool

If True, raise on failure; otherwise print a message and return False.

True

Returns:

Type Description
bool

True if the check passes or the domain is empty; False only when invalid and halt is False.

Raises:

Type Description
RuntimeError

If sum(loop_total) != count and halt is True.

Examples:

ok = fs.check(count=len(corners), halt=False)
if not ok:
    # fix topology or sizes, then recompute
    fs.update_loop_start()

compute_attribute_on_points

compute_attribute_on_points(attr, corners, points)

Average a per-face attribute back to points (vertices).

For each face attribute value, accumulates it to all incident points (via corners) and divides by the number of incident contributions per point.

Parameters:

Name Type Description Default
attr str or ndarray

Name of the face attribute to transfer, or an explicit array of shape (F, ...).

required
corners Corner

Corner domain (provides vertex_index).

required
points Point

Target point domain (length defines the number of output points).

required

Returns:

Type Description
ndarray

Array of shape (len(points), ...) with the averaged values.

Raises:

Type Description
AttributeError

If attr is a string and no such face attribute exists.

IndexError

If corner vertex indices fall outside [0, len(points)).

compute_loop_start

compute_loop_start(loop_total=None)

Compute offsets for one or many new items to append.

Parameters:

Name Type Description Default
loop_total int or array-like of int or None

Sizes of the items to add. If None, returns None. If a scalar, returns the single offset. If 1D array-like, returns one offset per size.

None

Returns:

Type Description
int or ndarray or None

Offsets starting from [next_loop_start][npblender.FaceSplineDomain.next_loop_start], shaped like loop_total.

Examples:

# Prepare offsets for three faces of sizes 4, 5, 4
starts = fs.compute_loop_start([4, 5, 4])
fs.append(loop_start=starts, loop_total=[4, 5, 4])

copy_field

copy_field(field_name, new_name, **infos)

Duplicate an existing field under a new name, with optional metadata overrides.

Parameters:

Name Type Description Default
field_name str

The name of the existing field to copy.

required
new_name str

The name of the new field to create.

required
infos keyword arguments

Optional metadata (e.g. default, unit, description...) to override or supplement the original field's metadata.

{}

Raises:

Type Description
KeyError

If the source field does not exist.

ValueError

If the target name already exists or is reserved.

delete

delete(selection)

Delete selected items and maintain consistent offsets.

After deleting items via super().delete(selection), recomputes loop_start with [update_loop_start][npblender.FaceSplineDomain.update_loop_start].

Parameters:

Name Type Description Default
selection Any

Boolean mask, integer index, slice, or array of indices.

required

Returns:

Type Description
None
See Also

[update_loop_start][npblender.FaceSplineDomain.update_loop_start]

delete_loops

delete_loops(selection, corners)

Delete faces and their incident corners.

Removes the selected faces and deletes the corresponding corner loops from corners. Returns the vertex indices (as stored on corners) that were removed with those loops.

Parameters:

Name Type Description Default
selection Any

Face selection accepted by the domain (boolean mask, indices, slice, etc.).

required
corners Corner

Corner domain holding at least the per-corner vertex_index array.

required

Returns:

Type Description
numpy.ndarray of int

The (possibly non-unique) vertex indices referenced by the deleted corners. If you need the unique set of affected vertices, apply np.unique on the result.

Notes
  • Internally calls [delete][npblender.delete] on the face domain, which updates loop bookkeeping (see [update_loop_start][npblender.update_loop_start]).
  • Corners corresponding to the deleted faces are also removed via corners.delete(...).

Raises:

Type Description
IndexError

If selection is out of bounds or if corner indices are inconsistent with the provided corners domain.

dump

dump(title='Dump', attributes=None, target='SCREEN')

Pretty-print or export domain content.

Formats attribute values and prints to screen or builds a tabular dump suitable for spreadsheets.

Parameters:

Name Type Description Default
title str

Title displayed in the report.

'Dump'
attributes Sequence[str] or None

Subset of attribute names to include. If None, all attributes are shown.

None
target (SCREEN, ...)

Output target. 'SCREEN' prints to stdout; other targets may trigger file creation depending on the implementation.

'SCREEN'

Returns:

Type Description
None

Examples:

Domain(points).dump(title="Vertices")

Note: Formatting adapts to the chosen target.

extend

extend(other, join_fields=True)

Append multiple records from another array or FieldArray.

Parameters:

Name Type Description Default
other FieldArray or structured np.ndarray

The array of records to append. Must have named fields matching a subset of the current array's fields.

required

filtered

filtered(selector, *, copy=False)

Return a FieldArray containing only the selected records.

Parameters:

Name Type Description Default
selector array‑like, slice or int

Any valid NumPy 1‑D index: boolean mask, integer index/array, or slice. It is applied to the current valid part of the buffer (self._data[:self._length]).

required
copy bool
  • False (default) => the new array shares the same memory (changes propagate both ways).
  • True => the data are physically copied.
False

Returns:

Type Description
FieldArray

A new instance holding exactly len(selector) records and inheriting the current field‑infos.

flip

flip(corners)

Flip faces by inverting the order of the corners.

Parameters:

Name Type Description Default
corners Corner

Corner domain (provides vertex_index).

required

Returns:

Type Description
ndarray

New corners.

from_bl_attributes

from_bl_attributes(bl_attributes)

Import attributes from a Blender attribute collection.

Reads geometry attributes from a Blender data-block and creates/updates the corresponding domain attributes, resizing the domain if needed.

Parameters:

Name Type Description Default
bl_attributes Mapping[str, Any]

Blender attributes collection (name → attribute descriptor) providing at least .domain, .is_internal, .data_type, and .data.

required

Returns:

Type Description
None
> ***Note:*** Only external (non-internal) Blender attributes matching this
domain are imported. Missing attributes are created with `transfer=True`.

from_dict classmethod

from_dict(data)

Build a FieldArray from a dictionary with field data and optional metadata.

Parameters:

Name Type Description Default
data dict[str, array - like or (array, dict)]

Mapping field names to arrays or (array, infos). Infos must include NAME.

required
copy bool

Whether to copy the data. Default: True.

required

Returns:

Type Description
FieldArray

get

get(name, default=None, broadcast_shape=None)

Get attribute by name.

If name is not an actual field, return default value. Name can be an array.

pos = field_array.get("position", (0, 0, 1))
pos = field_array.get([[0, 0, 1], [0, 0, 0]])

get_corner_indices

get_corner_indices()

Return the contiguous range of corner/control-point indices.

For each item, expands its [loop_start, loop_start + loop_total) range and concatenates the result for all items.

Returns:

Type Description
ndarray of shape ``(sum(loop_total),)``

Absolute indices into the corner/control-point array.

Notes

A fast Numba kernel is used for vectorized cases; the scalar case is handled directly.

get_edges

get_edges(corners)

Return the unique undirected edges present in the faces.

Parameters:

Name Type Description Default
corners Corner

Corner domain providing the vertex_index array.

required

Returns:

Type Description
numpy.ndarray of shape (E, 2), dtype=int

Unique vertex-index pairs for all edges.

get_surface

get_surface(corners, points)

Convenience bundle of per-face surface data.

Returns a dictionary containing: - normals : (F, 3) float — unit normals, - areas : (F,) float — face areas, - sizes : (F,) int — number of corners per face (loop_total), - verts : (P, 3) float — reference to point positions array.

Parameters:

Name Type Description Default
corners Corner
required
points Point
required

Returns:

Type Description
dict

Mapping with keys normals, areas, sizes, verts.

join_attributes

join_attributes(other)

Merge trans-domain attributes from another domain.

Copies or aligns attributes from other into the current domain, excluding any attributes not flagged as trans-domain in other.

Parameters:

Name Type Description Default
other Domain or None

Source domain. If None, the call is a no-op.

required

Returns:

Type Description
Domain

The domain itself (for chaining).

join_fields

join_fields(other, exclude=[])

Add all missing fields from another FieldArray.

For every field in other that is not present in self, a new field is created with the same dtype and shape, and initialized with its default value across all existing records.

Parameters:

Name Type Description Default
other FieldArray

Another FieldArray instance whose fields will be checked for missing fields.

required

Returns:

Type Description
self

make_buckets

make_buckets(attr)

Group items into buckets by attribute value.

When a domain is to be considered as a collection of packets of various sizes, buckets mechanism groups pakets by size, allowing further operation with numpy vectorization.

Parameters:

Name Type Description Default
attr array - like or str

Either an integer of shape (N,) or the name of an existing integer attribute in the domain.

required

Returns:

Type Description
list[ndarray(count, n)]

A list of int arrays (count, n): count is the number of buckets of length n.

Examples:

buckets = mesh.make_buckets('material')
for bucket in buckets:
    print(bucket.shape)

Note: The bucket attribute can be read with attr[bucket[:, 0]].

multiply

multiply(count)

Duplicate the current records count times.

Parameters:

Name Type Description Default
count int

Number of times to repeat the current records.

required
Notes

This duplicates the current valid records (up to self._length). If the array is empty or count <= 1, nothing happens.

Example:

If the array has 3 records and count == 4, the result will be:

[rec0, rec1, rec2, rec0, rec1, rec2, rec0, rec1, rec2, rec0, rec1, rec2]

new_attribute

new_attribute(name, data_type, default, optional=False, transfer=True, transdom=True)

Register a new attribute in the domain schema.

Creates (or ensures) an attribute with a given name, logical data type, default value, and flags controlling Blender transfer and cross-domain propagation.

Note: data_type argument is a Blender data type not a python data type. The data type name is compatible with Blender internal storage. FLOATdata type is implemented as np.float32 and 'INT' as np.int32.

Parameters:

Name Type Description Default
name str

Attribute name (Python identifier recommended).

required
data_type (FLOAT, INT, BOOL, VECTOR, VECTOR2, COLOR, QUATERNION, MATRIX, STRING, ...)

Logical data type used by the domain.

'FLOAT'
default Any

Default value for newly allocated elements.

required
optional bool

If True, the attribute may be absent on some elements.

False
transfer bool

If True, eligible to be transferred to Blender as a geometry attribute.

True
transdom bool

If True, considered a trans-domain attribute that can be copied across compatible domains.

True
See Also

new_float, new_vector, new_int, new_bool, new_color, new_vector2, new_quaternion, new_matrix

new_bool

new_bool(name, default=False, optional=False, transfer=True, transdom=True)

Create or ensure a boolean attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default bool

Default value.

False
optional bool
False
transfer bool
True
transdom bool
True

new_color

new_color(name, default=(0.5, 0.5, 0.5, 1.0), optional=False, transfer=True, transdom=True)

Create or ensure a color attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default array-like of shape (3,) or (4,)

Default color as RGB or RGBA.

(0.5, 0.5, 0.5, 1.0)
optional bool
False
transfer bool
True
transdom bool
True

new_field

new_field(name, dtype, shape=None, default=0, optional=False, **infos)

Add a field to the structured array.

Arguments
- name (str) : field name
- dtype (type) : a valid numpy dtype
- shape (tuple = None) : the shape of the field
- default (any = 0) : default value
- optional (bool = False) : the field is created only when accessed
- infos (dict) : field infos

new_float

new_float(name, default=0.0, optional=False, transfer=True, transdom=True)

Create or ensure a scalar float attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default float

Default value.

0.0
optional bool
False
transfer bool
True
transdom bool
True

new_int

new_int(name, default=0, optional=False, transfer=True, transdom=True)

Create or ensure an integer attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default int

Default value.

0
optional bool
False
transfer bool
True
transdom bool
True

new_matrix

new_matrix(name, default=np.eye(4), optional=False, transfer=True, transdom=True)

Create or ensure a matrix attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default array - like

Default matrix. By convention this is a square matrix per element (e.g., (3, 3) rotation or (4, 4) transform).

np.eye(4)
optional bool
False
transfer bool
True
transdom bool
True
order
required

new_quaternion

new_quaternion(name, default=(0.0, 0.0, 0.0, 1.0), optional=False, transfer=True, transdom=True)

Create or ensure a quaternion attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default array-like of shape (4,)

Default quaternion in (x, y, z, w) convention.

(0.0, 0.0, 0.0, 1.0)
optional bool
False
transfer bool
True
transdom bool
True

new_vector

new_vector(name, default=(0.0, 0.0, 0.0), optional=False, transfer=True, transdom=True)

Create or ensure a 3D vector attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default array-like of shape (3,)

Default XYZ vector.

(0.0, 0.0, 0.0)
optional bool
False
transfer bool
True
transdom bool
True

new_vector2

new_vector2(name, default=(0.0, 0.0), optional=False, transfer=True, transdom=True)

Create or ensure a 2D vector attribute.

Parameters:

Name Type Description Default
name str

Attribute name.

required
default array-like of shape (2,)

Default XY vector.

(0.0, 0.0)
optional bool
False
transfer bool
True
transdom bool
True

normal

normal(corners, points)

Compute per-face unit normals.

Returns a normalized area vector for each face (see [area_vectors][npblender.Face.area_vectors]). The direction follows the winding of the face’s corners.

Parameters:

Name Type Description Default
corners Corner

Corner domain providing the per-corner vertex_index.

required
points Point

Point (vertex) domain providing position of shape (P, 3).

required

Returns:

Type Description
numpy.ndarray of shape ``(F, 3)`` and dtype float

Unit normal per face.

Notes
  • Area vectors are obtained by triangulating polygons and summing triangle cross-products before normalization.
  • Degenerate faces (zero area) yield undefined normals (NaNs or inf). You may sanitize with np.nan_to_num or mask faces where the area is zero.
See Also

[area_vectors][npblender.Face.area_vectors] area get_surface

per_size

per_size()

Group items by their loop_total (polygon/control-point count).

Returns a dictionary keyed by size (3, 4, …) where each entry contains: - 'start' : array of loop_start values for items of that size. - 'indices' : array mapping entry order back to item indices.

Returns:

Type Description
dict[int, dict[str, ndarray]]

Grouped start offsets and reverse indices for each size present.

Notes

Uses a Numba kernel to bucketize items efficiently.

position

position(corners, points)

Face centroids (mean of corner positions).

Computes the arithmetic mean of corner positions per face.

Parameters:

Name Type Description Default
corners Corner
required
points Point
required

Returns:

Type Description
numpy.ndarray of shape (F, 3), dtype=float

Centroid of each face.

position_DEPRECATED

position_DEPRECATED(corners, points)

Centers of the faces

Args: verts (array (:, 3) of floats): The vertices

Returns: array (len(self), 3) of floats: The centers

sequences

sequences(corners)

Vertex-index sequences per face.

Returns a Python list where each item is the ordered sequence of vertex indices for the corresponding face.

Parameters:

Name Type Description Default
corners Corner
required

Returns:

Type Description
list[list[int]]

Vertex index sequence for each face.

to_bl_attributes

to_bl_attributes(attributes, update=False)

Export attributes to a Blender attribute collection.

Writes eligible domain attributes to a Blender data-block, creating missing attributes and adjusting sizes as needed.

Parameters:

Name Type Description Default
attributes Any

Blender attributes collection receiving the values.

required
update bool

If True, update existing attributes in-place; otherwise create them when missing.

False

Returns:

Type Description
None
> ***Caution:*** Only attributes with `transfer=True` are exported. Optional
attributes are skipped.
> ***Caution:*** Curve domains user attributes are not saved.

to_dict

to_dict(*, copy=True, with_infos=True)

Convert the array to a dictionary of fields or (field, infos) pairs.

Parameters:

Name Type Description Default
copy bool

Whether to copy the arrays.

True
with_infos bool

If True, return (array, infos) for each field.

True

Returns:

Type Description
dict[str, array or (array, dict)]

transfer_attributes

transfer_attributes(other, shape=None, other_shape=None)

Transfer values of trans-domain attributes from another domain.

Copies values for each trans-domain attribute present in other into the corresponding attributes of self, with optional reshaping for batched assignments.

Parameters:

Name Type Description Default
other Domain

Source domain providing attribute values.

required
shape tuple of int or None

Target reshape for self before assignment. If None, uses (self._length,).

None
other_shape tuple of int or None

Source reshape for other before assignment. If None, uses (other._length,).

None

Returns:

Type Description
Domain

The domain itself (for chaining).

> ***Note:*** Each attribute is reshaped as `shape + item_shape` on `self`
and `other_shape + item_shape` on `other` prior to assignment.

update_loop_start

update_loop_start()

Recompute loop_start from loop_total (cumulative layout).

Sets loop_start to a left-rolled cumulative sum of loop_total, so item i starts right after the end of item i-1.

Returns:

Type Description
FaceSplineDomain

Self (for chaining).

Notes

Call this after deletions / resizes to keep indices consistent.

See Also

[compute_loop_start][npblender.FaceSplineDomain.compute_loop_start] : Compute offsets for new items to be appended.