Curve ¶
Curve(points=None, splines=None, curve_type=POLY, materials=None, attr_from=None, **attrs)
Bases: Geometry
Construct a curve geometry.
Initializes empty domains by default, or builds a curve from provided
control points and spline sizes/types. If both points
and splines
are
already instances of ControlPoint
and
Spline
, the curve is created as a view
on these domains (no data copy). Otherwise, domains are allocated and
populated via add_splines
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
array-like or [`ControlPoint`][npblender.ControlPoint]
|
Control-point positions (and optional per-point attributes) used to
populate the curve. If a |
None
|
splines
|
array-like or [`Spline`][npblender.Spline]
|
Per-spline control-point counts (when building), or a ready-made
|
None
|
curve_type
|
int
|
Default spline type for construction. One of
[ |
POLY
|
materials
|
str or sequence of str
|
Material names used by the curve. A single string is accepted and promoted to a one-element list. |
None
|
attr_from
|
object
|
Source whose transferable attributes are joined into this geometry
(see |
None
|
**attrs
|
Additional geometry attributes to forward to
|
{}
|
Notes
- When
points
andsplines
are provided as domains, the instance is a view:self.is_view
isTrue
if the sum ofsplines.loop_total
differs fromlen(points)
. Useno_view
to materialize a standalone copy. :contentReference[oaicite:0]{index=0} - Otherwise, the constructor allocates empty
ControlPoint
andSpline
domains, joins attributes fromattr_from
if any, then callsadd_splines
. :contentReference[oaicite:1]{index=1}
Raises:
Type | Description |
---|---|
ValueError
|
Propagated from |
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_bezier ¶
add_bezier(points, splines=None, handle_left=None, handle_right=None, cyclic=False, **attrs)
Append Bezier spline(s).
The arguments splines
gives the length(s) of the bezier spline(s). If None:
- the number of points is taken (one spline is added)
- points.shape[1] is taken if the shape of points is (m, , 3)
handle_left and handle_right must have the same shape as points if provided. If they aren't provided, they are computed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
(ndarray, shape(N, 3) or (B, N, 3))
|
Anchor positions (single spline or a batch). |
required |
splines
|
int or 1D array of int or None
|
Per-spline point counts. If |
None
|
handle_left
|
ndarray or None
|
Left handles (same shape as |
None
|
handle_right
|
ndarray or None
|
Right handles (same shape as |
None
|
cyclic
|
bool or 1D array of bool
|
Whether each spline is closed (broadcastable to number of splines). |
False
|
**attrs
|
Additional attributes dispatched to points/splines. |
{}
|
Returns:
Type | Description |
---|---|
dict
|
Indices of appended points and splines. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
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.
add_poly ¶
add_poly(points, splines=None, curve_type=POLY, cyclic=False, w=1.0, **attrs)
Append Poly or NURBS spline(s).
The arguments 'splines' gives the length(s) of the spline(s). If None: - the number of points is taken (one spline is added) - points.shape[1] is taken if the shape of points is (m, , 3)
Non bezeier splines use 4D points. If the provided vectors are 4D, the argument w is ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
ndarray
|
Either |
required |
splines
|
int or 1D array of int or None
|
Per-spline point counts. If |
None
|
curve_type
|
int
|
[ |
POLY
|
cyclic
|
bool or 1D array of bool
|
Whether each spline is closed. |
False
|
w
|
float
|
Default weight if |
1.0
|
**attrs
|
Additional attributes dispatched to points/splines. |
{}
|
Returns:
Type | Description |
---|---|
dict
|
Indices of appended points and splines. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
add_splines ¶
add_splines(points=None, splines=None, curve_type=POLY, **attrs)
Append new splines (Bezier, Poly, or NURBS) with their control points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
ndarray or None
|
Control-point coordinates. Shape depends on |
None
|
splines
|
int or 1D array of int or None
|
Per-spline sizes. If |
None
|
curve_type
|
int
|
One of [ |
POLY
|
**attrs
|
Mixed per-point and per-spline attributes to broadcast and assign. |
{}
|
Returns:
Type | Description |
---|---|
dict
|
Keys |
Raises:
Type | Description |
---|---|
ValueError
|
If |
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
|
|
arc
classmethod
¶
arc(resolution=16, radius=1.0, start_angle=0.0, sweep_angle=7 * np.pi / 4, connect_center=False, invert_arc=False)
Build a polyline arc in the XY plane.
The arc is sampled uniformly with resolution
points between
start_angle
and start_angle + sweep_angle
. If invert_arc
is True,
the parameterization is reversed (clockwise), producing the same locus
but with swapped start/end angles. When connect_center
is True, the
center (0, 0, 0)
is appended, and the spline is marked as cyclic to
form a pie slice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int
|
Number of samples along the arc (min 2). |
16
|
radius
|
float
|
Arc radius. |
1.0
|
start_angle
|
float
|
Start angle in radians. |
0.0
|
sweep_angle
|
float
|
Signed sweep angle in radians. |
7π/4
|
connect_center
|
bool
|
If True, append the origin and mark the spline cyclic (pie slice). |
False
|
invert_arc
|
bool
|
If True, reverse the arc direction (clockwise). |
False
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one POLY spline sampled in the XY plane. |
See Also
bezier_circle
classmethod
¶
bezier_circle()
Unit circle approximated by 4 cubic Bezier arcs (cyclic).
Returns:
Type | Description |
---|---|
Curve
|
Bezier circle with pre-set handles. |
bezier_segment
classmethod
¶
bezier_segment(resolution=16, start=(-1, 0, 0), start_handle=(-0.5, 0.5, 0), end_handle=(0, 0, 0), end=(1, 0, 0))
Create a single two-point Bezier segment.
Produces a Bezier spline with two control points located at start
and end
. The left/right handles are set from start_handle
and
end_handle
(mirrored appropriately). The resolution
argument is
accepted for API symmetry but not used at construction; sampling and
evaluation rely on the per-spline resolution
attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int
|
Kept for API symmetry; not used during construction. |
16
|
start
|
(3,) float
|
Start control point. |
(-1, 0, 0)
|
start_handle
|
(3,) float
|
Handle associated to the start point (as right handle). |
(-0.5, 0.5, 0)
|
end_handle
|
(3,) float
|
Handle associated to the end point (as left handle). |
(0, 0, 0)
|
end
|
(3,) float
|
End control point. |
(1, 0, 0)
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one BEZIER spline (open). |
Notes
Handles are applied as:
- handle_right[0] = start_handle
- handle_left[1] = end_handle
The opposite handles are mirrored so that each handle is expressed
in absolute coordinates.
blender_data ¶
blender_data(readonly=False)
Temporary access to a transient Blender Curve
datablock.
Yields a throwaway curve data populated from this instance; upon exit,
reads back into self
unless readonly=True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
readonly
|
bool
|
If True, do not read back any change made to the temporary data. |
False
|
Yields:
Type | Description |
---|---|
Curve
|
The temporary curve data. |
Examples:
curve = Curve.Spiral()
with curve.blender_data() as bcurve:
print("Number of points", len(bcurve.splines[0].points))
capture ¶
capture(other)
check ¶
check(title='Mesh Check', halt=True)
Validate internal spline bookkeeping.
Delegates to Spline.check
. When invalid
and halt=True
, raises; otherwise prints a message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
Label used in error messages. |
"Mesh Check"
|
halt
|
bool
|
Whether to raise on failure. |
True
|
Returns:
Type | Description |
---|---|
bool
|
True if valid. |
Raises:
Type | Description |
---|---|
Exception
|
If the check fails and |
circle
classmethod
¶
circle(resolution=32, radius=1.0)
Regular polygonal approximation of a circle (Poly, cyclic).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int
|
Number of points. |
32
|
radius
|
float
|
Circle radius. |
1.0
|
Returns:
Type | Description |
---|---|
Curve
|
|
clear ¶
clear()
Remove all points and splines (attributes 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
compute_bezier_handles
staticmethod
¶
compute_bezier_handles(points, cyclic=False, eps=1e-06)
Compute cubic Bezier handles (left/right) from anchors using Catmull-Rom style tangents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
(N,3) or (B,N,3) float32/float64
|
OPEN storage (no duplicated first point). |
required |
cyclic
|
bool
|
If True, wrap neighbors; else use one-sided differences at ends. |
False
|
eps
|
float
|
Small epsilon to guard against zero-length tangents. |
1e-06
|
Returns:
Type | Description |
---|---|
left, right : same shape as `points`
|
left[i] = P[i] - T[i] * (len_in[i] / 3) right[i] = P[i] + T[i] * (len_out[i] / 3) with len_in = ||P[i] - P[i-1]|| and len_out = ||P[i+1] - P[i]|| (wrapped if cyclic). |
delete_points ¶
delete_points(points=None, splines=None)
Delete points (and prune splines when emptied).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
selection or None
|
Points to delete. |
None
|
splines
|
selection or None
|
Splines whose all points should be deleted. |
None
|
Returns:
Type | Description |
---|---|
Curve
|
Self (for chaining). |
delete_splines ¶
delete_splines(splines=None)
Delete splines (and their points).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splines
|
selection or None
|
Splines to delete. |
None
|
Returns:
Type | Description |
---|---|
Curve
|
Self (for chaining). |
evaluate ¶
evaluate(t)
Evaluate positions along each spline at parameter(s) t
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float or ndarray
|
Parametric coordinate(s) in |
required |
Returns:
Type | Description |
---|---|
(ndarray, shape(..., 3))
|
Evaluated positions. |
for_each_bucket ¶
for_each_bucket(func)
Iterate homogeneous spline buckets and apply func
.
Spline buckets share the same (curve_type, N, cyclic, resolution)
signature.
func
is called with (curve, curve_type, N, cyclic, resolution)
and must
return a value; the generator yields (bucket_indices, value)
pairs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
Callback applied once per bucket. |
required |
Yields:
Type | Description |
---|---|
tuple
|
|
from_curve
classmethod
¶
from_curve(other, points=None, splines=None)
Copy a curve (optionally subsetting points and/or splines).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Curve
|
Source curve. |
required |
points
|
selection or None
|
Points to exclude when copying (interpreted as mask if array of bool; see code for details). |
None
|
splines
|
selection or None
|
Splines to exclude when copying. |
None
|
Returns:
Type | Description |
---|---|
Curve
|
|
from_curve_data
classmethod
¶
from_curve_data(data)
Build a curve from a Blender Curve
datablock.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Curve
|
Blender curve data. |
required |
Returns:
Type | Description |
---|---|
Curve
|
|
from_dict
classmethod
¶
from_dict(d)
Deserialize a curve from a dict produced by to_dict
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
Serialized curve payload. |
required |
Returns:
Type | Description |
---|---|
Curve
|
|
from_object
classmethod
¶
from_object(obj, evaluated=False)
Build a curve from a Blender object holding curve data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
str or Object
|
Object or object name. |
required |
evaluated
|
bool
|
If True, read the evaluated (modifier-applied) data via depsgraph. |
False
|
Returns:
Type | Description |
---|---|
Curve
|
|
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()
Indices/slice selecting the points actually referenced by the current splines.
If the curve is a view (splines refer to a subset of points), returns a
boolean mask selecting those rows in points
. Otherwise returns slice(None)
.
Returns:
Type | Description |
---|---|
slice or ndarray of bool
|
Selection usable to index |
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
line
classmethod
¶
line(start=(0, 0, 0), end=(0, 0, 1), resolution=2)
Build a straight polyline between two points.
Generates resolution
evenly spaced points from start
to end
(inclusive) and returns an open POLY spline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
(3,) float
|
Line start point. |
(0, 0, 0)
|
end
|
(3,) float
|
Line end point. |
(0, 0, 1)
|
resolution
|
int
|
Number of samples along the line (min 2). |
2
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one POLY spline containing |
Examples:
c = Curve.line(start=(0, 0, 0), end=(1, 0, 0), resolution=5)
print(len(c.points))
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__)
multiply ¶
multiply(count, in_place=True)
Duplicate the whole curve count
times (instancing-like expansion).
Multiplying is a way to efficiently duplicate the geometry a great number of times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
Number of copies to create. |
required |
in_place
|
bool
|
If True, expand this instance; otherwise return a new expanded curve. |
True
|
Returns:
Type | Description |
---|---|
Curve or None
|
Self (in place) or a new curve; |
Raises:
Type | Description |
---|---|
Exception
|
If |
no_view ¶
no_view()
Materialize a view curve into an owned, self-consistent curve.
Deep-copies the splines
and gathers the referenced rows of points
so that sum(splines.loop_total) == len(points)
holds true.
Returns:
Type | Description |
---|---|
Curve
|
Self (for chaining). |
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
quadratic_bezier
classmethod
¶
quadratic_bezier(resolution=16, start=(-1, 0, 0), middle=(0, 2, 0), end=(1, 0, 0))
Quadratic Bézier segment (not implemented).
Intended to create a single quadratic Bézier curve defined by the control
points start
, middle
, and end
. Currently not implemented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int
|
Suggested sampling resolution (unused in the current implementation). |
16
|
start
|
(3,) float
|
Start control point. |
(-1, 0, 0)
|
middle
|
(3,) float
|
Middle (control) point. |
(0, 2, 0)
|
end
|
(3,) float
|
End control point. |
(1, 0, 0)
|
Raises:
Type | Description |
---|---|
Exception
|
Always raised with the message "Not implemented yet". |
Examples:
try:
c = Curve.quadratic_bezier()
except Exception as e:
print(e) # "Not implemented yet"
quadrilateral
classmethod
¶
quadrilateral(width=2.0, height=2.0)
Axis-aligned rectangle in the XY plane (closed polyline).
Builds a cyclic POLY spline with four vertices:
(-w/2, -h/2) → (w/2, -h/2) → (w/2, h/2) → (-w/2, h/2)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
float
|
Rectangle width along X. |
2.0
|
height
|
float
|
Rectangle height along Y. |
2.0
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one cyclic POLY spline. |
Examples:
c = Curve.quadrilateral(width=1.0, height=0.5)
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
|
|
sample_attributes ¶
sample_attributes(t, names=None, cubic=False)
Sample point-domain attributes along the curve(s) at t
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float or ndarray
|
Parametric coordinate(s) in |
required |
names
|
sequence of str or None
|
Attribute names to sample; if |
None
|
cubic
|
bool
|
Use cubic interpolation (typically for Bezier). |
False
|
Returns:
Type | Description |
---|---|
dict[str, ndarray]
|
Sampled arrays keyed by attribute name. |
select ¶
select(indices)
Convenience alias for subsetting splines: curve[indices]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indices
|
selection
|
Boolean mask, slice, or integer array indexing splines. |
required |
Returns:
Type | Description |
---|---|
Curve
|
A view on the selected splines (potentially a view curve). |
set_spline2d_thickness ¶
set_spline2d_thickness(thickness=0.1, mode=0, factor=1.0, cuts=(0.1, np.nan), inner_mode=None, inner_factor=None, inner_cuts=None, resolution=12, offset=0.0, start_thickness=1, end_thickness=1)
Transform the splines into flat 2D mesh..
This method constructs a single polygonal outline from the current polyline by: (1) offsetting a copy to the "inner" side and resolving its corners, (2) offsetting a copy to the "outer" side and resolving its corners, then (3) reversing the outer side and concatenating both sides into one path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thickness
|
float or array-like of shape (n,)
|
Target stroke width per vertex. Scalars are broadcast to all vertices.
The distance between the two resulting offset sides is |
0.1
|
mode
|
int or array-like of shape (n,)
|
Corner style for the outer side:
|
0
|
factor
|
float or array-like of shape (n,)
|
Per-corner effect factor. |
1.0
|
cuts
|
couple of floats or array-like of couples of floats
|
First value is the distance of the cut measured along the first segment.
Second value is the angle (in radians) of the cut line. If second value is
|
(.1, np.nan)
|
inner_mode
|
None, int or array-like of shape (n,)
|
Corner style for the inner side. If |
None
|
inner_factor
|
float or array-like of shape (n,)
|
Same as |
None
|
inner_cuts
|
float or couple of floats or array-like of such values
|
Same as |
None
|
resolution
|
int
|
Number of samples used for each rounded corner (when the corresponding mode is |
12
|
offset
|
float
|
Centerline bias in the range
Values are clipped to |
0.0
|
start_thickness
|
float
|
Start-cap scaling when |
1
|
end_thickness
|
float
|
End-cap scaling when |
1
|
Returns:
Name | Type | Description |
---|---|---|
Mesh |
splines transformed into faces
|
|
spiral
classmethod
¶
spiral(resolution=32, rotations=2.0, start_radius=1.0, end_radius=2.0, height=2.0, reverse=False)
Create a 3D polyline spiral in the XY plane with linear Z elevation.
Samples a spiral with 1 + int(rotations * resolution)
points. The radius
linearly interpolates from start_radius
to end_radius
. The angle evolves
by 2π * rotations
(clockwise unless reverse=True
). The Z coordinate is
linearly distributed from 0
to height
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int
|
Number of samples per full rotation. |
32
|
rotations
|
float
|
Number of turns (can be fractional). |
2.0
|
start_radius
|
float
|
Radius at the beginning of the spiral. |
1.0
|
end_radius
|
float
|
Radius at the end of the spiral. |
2.0
|
height
|
float
|
Final Z value (start is Z = 0). |
2.0
|
reverse
|
bool
|
If True, swap the trigonometric direction of the spiral. |
False
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with a single POLY spline. |
Examples:
c = Curve.spiral(resolution=64, rotations=3.5, start_radius=0.5, end_radius=3.0, height=5.0)
star
classmethod
¶
star(points=8, inner_radius=1.0, outer_radius=2.0, twist=0.0)
Create a star polygon (alternating outer/inner vertices) in the XY plane.
Builds a cyclic POLY spline with 2 * points
vertices alternating
between outer_radius
and inner_radius
. The inner vertices are rotated
by π / points + twist
to control the star lobes' alignment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
int
|
Number of star tips (minimum 3). |
8
|
inner_radius
|
float
|
Radius of inner vertices. |
1.0
|
outer_radius
|
float
|
Radius of outer vertices (tips). |
2.0
|
twist
|
float
|
Additional rotation (radians) applied to inner vertices. |
0.0
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one cyclic POLY spline forming a star. |
See Also
tangent ¶
tangent(t, normalize=True)
Evaluate tangents along each spline at parameter(s) t
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float or ndarray
|
Parametric coordinate(s) in |
required |
normalize
|
bool
|
If True, return unit tangents. |
True
|
Returns:
Type | Description |
---|---|
(ndarray, shape(..., 3))
|
Tangent vectors. |
to_bezier ¶
to_bezier(control_count=None, resolution=16)
Convert all splines to Bezier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_count
|
int or None
|
Number of anchors per spline. If |
None
|
resolution
|
int
|
Per-segment resolution written to |
16
|
Returns:
Type | Description |
---|---|
Curve
|
A new Bezier curve. |
to_curve_data ¶
to_curve_data(data)
Write this curve into an existing Blender Curve
datablock.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Curve
|
Target Blender curve data (cleared and repopulated). |
required |
to_dict ¶
to_dict()
Serialize the curve to a plain Python dict.
Returns:
Type | Description |
---|---|
dict
|
Keys: |
to_mesh ¶
to_mesh(profile=None, caps=True, use_radius=True, camera_culling=False)
Convert the curve to a mesh (optionally sweeping a profile).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
profile
|
Curve or None
|
Profile curve to sweep along each spline. If |
None
|
caps
|
bool
|
Close ends when the profile is cyclic and the path is open. |
True
|
use_radius
|
bool
|
Use per-point |
True
|
camera_culling
|
bool or Camera
|
If truthy, drop splines that would be sub-pixel using a camera model. |
False
|
Returns:
Type | Description |
---|---|
[Mesh][Mesh]
|
The generated mesh. |
to_object ¶
to_object(obj, collection=None)
Create or update a Blender curve object from this geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
str or Object
|
Target object or name (created if it doesn't exist). |
required |
collection
|
Collection or None
|
Collection to link a newly created object into. |
None
|
Returns:
Type | Description |
---|---|
Object
|
The Blender curve object. |
Notes
The object type must be Curve. Type conversion is not performed.
to_poly ¶
to_poly(resolution=None)
Convert all splines to Poly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution
|
int or None
|
If |
None
|
Returns:
Type | Description |
---|---|
Curve
|
A new curve with |
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
|
|
xyfunction
classmethod
¶
xyfunction(func, x0=0.0, x1=1.0, resolution=100, materials=None)
Sample a 2D function y = f(x) as a polyline in the XY plane.
Evaluates y = func(x)
for x
uniformly spaced in [x0, x1]
and creates a
POLY spline with points (x, y, 0)
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
A function mapping an array of X values to Y values (vectorized). |
required |
x0
|
float
|
Start of the X interval. |
0.0
|
x1
|
float
|
End of the X interval. |
1.0
|
resolution
|
int
|
Number of samples in |
100
|
materials
|
str or sequence of str or None
|
Optional material(s) to attach to the curve. |
None
|
Returns:
Type | Description |
---|---|
Curve
|
A curve with one POLY spline sampled from |
Examples:
import numpy as np
def f(x):
return np.sin(2 * np.pi * x)
c = Curve.xyfunction(f, x0=0.0, x1=1.0, resolution=200)