Cloud ¶
Cloud(points=None, attr_from=None, **attrs)
Bases: Geometry
Point-cloud geometry container.
Cloud
stores a set of points and their attributes, with helpers to
import/export from Blender data (Mesh or PointCloud), join other clouds,
apply basic transforms, and generate common point distributions.
Attributes:
Name | Type | Description |
---|---|---|
points |
[Point][Point]
|
Point domain storing per-point attributes (e.g., |
Notes
Initialize an empty cloud, optionally with points and attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
array-like of shape (N, 3) or (N, D)
|
Coordinates to append as |
None
|
attr_from
|
object
|
Source whose attribute schemas should be merged into this geometry,
see |
None
|
**attrs
|
Additional per-point attributes to append alongside |
{}
|
bounding_box
property
¶
bounding_box
Axis-aligned bounding box of the point positions.
Returns:
Type | Description |
---|---|
tuple of numpy.ndarray
|
|
bounding_box_dims
property
¶
bounding_box_dims
Extents of the axis-aligned bounding box.
Returns:
Type | Description |
---|---|
numpy.ndarray of shape (3,)
|
|
max_size
property
¶
max_size
Maximum dimension of the bounding box.
Returns:
Type | Description |
---|---|
float
|
|
add_materials ¶
add_materials(materials)
Append material name(s) to the geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
materials
|
str or sequence of str
|
One name or a sequence of names to append. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Notes
This method does not deduplicate names; duplicates may be appended.
apply_scale ¶
apply_scale(scale, pivot=None)
Scale points (convenience wrapper).
See: transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
ndarray
|
Per-point or broadcastable scales. |
required |
pivot
|
ndarray
|
Optional pivot(s) for scaling. |
None
|
Returns:
Type | Description |
---|---|
Geometry
|
|
capture ¶
capture(other)
check ¶
check(title='Geometry Check', halt=True)
Validate the geometry consistency.
Placeholder in the base class: returns True
. Subclasses may override
to perform domain-level checks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
Label for messages or errors. |
"Geometry Check"
|
halt
|
bool
|
Whether to raise on failure (in subclasses that implement checks). |
True
|
Returns:
Type | Description |
---|---|
bool
|
Always |
clear_geometry ¶
clear_geometry()
Clear all point data (schemas kept, values cleared).
Returns:
Type | Description |
---|---|
None
|
|
compute_attribute_on_domain ¶
compute_attribute_on_domain(domain_from, attr, domain_to)
Transfer an attribute from one domain to another.
Performs a domain mapping (e.g., points → faces) using the appropriate domain operator, and returns the computed array on the target domain.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
domain_from
|
str
|
Source domain name (e.g., |
required |
attr
|
str or ndarray
|
Source attribute to transfer. If a string, it is looked up on the source domain; if an array, it must match the source domain length. |
required |
domain_to
|
str
|
Target domain name. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Attribute values on the target domain. If |
Raises:
Type | Description |
---|---|
AttributeError
|
If either |
Exception
|
If the requested mapping is not implemented. |
Notes
Implemented mappings include:
- points → faces: [Point.compute_attribute_on_faces
][npblender.Point.compute_attribute_on_faces]
- points → edges: [Point.compute_attribute_on_edges
][npblender.Point.compute_attribute_on_edges]
- points → corners: [Point.compute_attribute_on_corners
][npblender.Point.compute_attribute_on_corners]
- points → splines: [Point.compute_attribute_on_splines
][npblender.Point.compute_attribute_on_splines]
- faces → points: Face.compute_attribute_on_points
- edges → points: Edge.compute_attribute_on_points
- corners → points: Corner.compute_attribute_on_points
from_cloud
classmethod
¶
from_cloud(other, selection=None)
Synonym of from_geometry
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Cloud
|
|
required |
selection
|
selection or None
|
|
None
|
Returns:
Type | Description |
---|---|
Cloud
|
|
from_data
classmethod
¶
from_data(data)
Initialize the cloud from Blender data (Mesh or PointCloud).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Mesh or PointCloud or str
|
A Blender data-block or a resolvable identifier accepted by
[ |
required |
Returns:
Type | Description |
---|---|
Cloud
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the data-block type is not supported. |
from_dict
classmethod
¶
from_dict(d)
Deserialize a cloud from a dictionary produced by to_dict
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
Serialized payload with at least the |
required |
Returns:
Type | Description |
---|---|
Cloud
|
New instance with points loaded from |
from_geometry
classmethod
¶
from_geometry(other, selection=None)
Build a cloud from another geometry that has a point domain.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
[Geometry][Geometry]
|
Source geometry (must have a |
required |
selection
|
selection or None
|
Selection on points to keep; if provided, the complement is deleted after copying. |
None
|
Returns:
Type | Description |
---|---|
Cloud
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
from_object
classmethod
¶
from_object(obj, evaluated=False)
Create a cloud from an existing Blender object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
str or Object
|
Object or name resolvable by [ |
required |
evaluated
|
bool
|
If True, read from the evaluated object (modifiers applied). |
False
|
Returns:
Type | Description |
---|---|
Cloud
|
|
get_cubic_envelop ¶
get_cubic_envelop()
get_material_index ¶
get_material_index(mat_name)
Return the index of a material name, creating it if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mat_name
|
str
|
Material name to look up or append. |
required |
Returns:
Type | Description |
---|---|
int
|
Index of |
Notes
If mat_name
is not present, it is appended to self.materials
and the
new index is returned.
get_points_selection ¶
get_points_selection()
Selection of points relevant to operations.
Returns slice(None)
in the base class (all points). Subclasses (e.g.,
curves) may override to select only referenced points.
Returns:
Type | Description |
---|---|
slice
|
|
join ¶
join(*others)
join_attributes ¶
join_attributes(other, **kwargs)
Merge attribute schemas from another geometry.
For each domain listed in self.domain_names
and also present in other
,
copies (joins) the attribute definitions (names, dtypes, metadata) from
other
into this geometry's domains. Use keyword flags to include/exclude
domains by name (e.g., faces=False
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Geometry or None
|
Source geometry. If |
required |
**kwargs
|
Per-domain boolean switches to filter which domains to join. |
{}
|
Returns:
Type | Description |
---|---|
Geometry
|
|
Examples:
mesh.join_attributes(other_mesh, faces=False)
curve.join_attributes(mesh) # only common domains are merged
load_models
staticmethod
¶
load_models(*specs)
Load multiple geometries from collections, objects, or instances.
Accepts mixed inputs such as Blender collections, Blender objects, lists/
tuples of either, or already-instantiated Mesh
/Curve
. Returns a flat
list of geometries discovered or constructed.
This method is mainly intended to be used by Instances
to load its models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*specs
|
Collections, objects, lists/tuples, or |
()
|
Returns:
Type | Description |
---|---|
list
|
List of geometries ( |
Raises:
Type | Description |
---|---|
ValueError
|
If a spec cannot be resolved to a geometry. |
load_object
staticmethod
¶
load_object(name)
Load a Blender object and return a Mesh
or a Curve
.
Resolves name
to a Blender object, inspects its data type, and returns a
matching geometry by calling the subclass' from_object
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str or Object
|
Object name or object instance. |
required |
Returns:
Type | Description |
---|---|
Mesh or Curve or None
|
Raises:
Type | Description |
---|---|
Exception
|
If the object exists but is neither a |
Examples:
geo = Geometry.load_object("MyObject")
if geo is not None:
print(type(geo).__name__)
object ¶
object(index=0, readonly=True, **kwargs)
Temporary access to a Blender Object built from this geometry.
Creates a transient object (named "BPBL Temp {index}"
unless index
is a
string), selects and activates it, yields it for editing, then cleans up.
If readonly=True
, the edited object is captured back into self
.
This method can be used to set and apply a modifier (see exemple below).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int or str
|
Index or name used to label the temporary object. |
0
|
readonly
|
bool
|
If |
True
|
kwargs
|
dict
|
Keyword arguments passed to |
{}
|
Yields:
Type | Description |
---|---|
Object
|
The temporary Blender object built from |
Examples:
plane = Mesh.Grid()
with plane.object(readonly=False) as obj:
mod = obj.modifiers.new("Solidify", 'SOLIDIFY')
mod.thickness = .1
bpy.ops.object.modifier_apply(modifier=mod.name)
# plane is now solidifed
rotate ¶
rotate(rotation, pivot=None)
Rotate points (convenience wrapper).
See: transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rotation
|
ndarray or Rotation - like
|
Rotation(s) to apply as |
required |
pivot
|
ndarray
|
Optional pivot(s) for rotation. |
None
|
Returns:
Type | Description |
---|---|
Geometry
|
|
to_data ¶
to_data(data)
Write this cloud into a Blender Mesh data-block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Mesh or str
|
Target mesh data (or identifier resolvable by
[ |
required |
Returns:
Type | Description |
---|---|
None
|
|
Notes
- Vertices are created to match the point count; per-point attributes are
written to
data.attributes
.
Caution: This writes to a Mesh data-block (not PointCloud) because Blender’s Python API does not allow changing the point count of a
PointCloud
at runtime.
to_dict ¶
to_dict()
Serialize the cloud to a plain Python dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary with keys: |
to_object ¶
to_object(obj, point_cloud=False, collection=None)
Create or update a Blender object from this cloud.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
str or Object
|
Object or name. If it does not exist, it is created. |
required |
point_cloud
|
bool
|
If True, convert the created mesh object to a |
False
|
collection
|
str or Collection or None
|
Collection to link a newly created object into. |
None
|
Returns:
Type | Description |
---|---|
Object
|
The created/updated Blender object. |
transform ¶
transform(transformation)
Apply a rotation matrix or batch of matrices.
See: transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformation
|
ndarray
|
Rotation matrix or batch of rotation matrices. |
required |
Returns:
Type | Description |
---|---|
Geometry
|
|
transformation ¶
transformation(rotation=None, scale=None, translation=None, pivot=None)
Apply rotation/scale/translation (with optional per-packet broadcasting).
Operates in-place on points.position
and, when present, Bezier handles
(points.handle_left
, points.handle_right
). Shapes can represent packets
of points: broadcasting rules are handled by
[Point._get_shape_for_operation
][npblender.Point._get_shape_for_operation].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rotation
|
ndarray or Rotation - like
|
Rotation matrix/matrices applied as |
None
|
scale
|
ndarray
|
Per-axis scaling. Shape may broadcast over points. |
None
|
translation
|
ndarray
|
Per-point translation. Shape may broadcast over points. |
None
|
pivot
|
ndarray
|
Pivot(s) subtracted before, and added after, the rotation/scale; same
broadcasting rules as |
None
|
Returns:
Type | Description |
---|---|
Geometry
|
|
Notes
- If handles exist, they are transformed consistently with positions.
Examples:
# 12 cubes laid out randomly with per-instance transforms
cubes = Mesh.cube(size=1).multiply(12)
T = np.random.uniform(-1, 1, (12, 3))
S = np.random.uniform(0.5, 2.0, (12, 3))
R = Rotation.from_euler(np.random.uniform(0, 2*np.pi, (12, 3)))
cubes.transformation(rotation=R, scale=S, translation=T)
translate ¶
translate(translation)
Translate points (convenience wrapper).
See: transformation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translation
|
ndarray
|
Per-point or broadcastable translation vectors. |
required |
Returns:
Type | Description |
---|---|
Geometry
|
|