BlenderObject
A convenience class for working with Blender objects.
Extends BlenderObjectBase with creation methods and additional utility functions.
Attributes
attributes
Get the attributes of the Blender object.
data
Get the data block of the Blender object.
edges
Get the edges of the Blender mesh object.
name
Get the name of the Blender object.
object
Get the Blender object.
position
Get the position of the vertices of the Blender object.
uuid
Get the unique identifier for this object.
vertices
Get the vertices of the Blender mesh object.
Methods
centroid
BlenderObject.centroid(weight= None )
Calculate the weighted or unweighted centroid of the object’s positions.
Parameters
weight
str | np .ndarray | None
The weights or indices for calculating the centroid: - If str: Name of attribute to use as weights - If np.ndarray with float dtype: Weights for each position - If np.ndarray with int dtype: Indices of positions to include - If None: Use all positions equally weighted Defaults to None.
None
Returns
np .ndarray
A 3D vector representing the centroid position.
evaluate
Return a version of the object with all modifiers applied.
Returns
Object
A new Object that isn’t yet registered with the database
from_curves
BlenderObject.from_curves(
positions= None ,
curve_sizes= None ,
name= 'Curves' ,
collection= None ,
)
Create a BlenderObject from curves data.
Parameters
positions
ndarray or None
Control point positions with shape (N, 3). Default is None.
None
curve_sizes
list [int ] | np .ndarray or None
Number of points in each curve. Default is None.
None
name
str
Name of the created object. Default is “Curves”.
'Curves'
collection
bpy.types .Collection or None
Blender collection to link the object to. Default is None.
None
Examples
import numpy as np
import databpy as db
# Create 2 curves with 3 and 4 points
positions = np.random.random((7 , 3 ))
bob = db.BlenderObject.from_curves(positions, [3 , 4 ], name= "MyCurves" )
print (len (bob)) # 7
from_mesh
BlenderObject.from_mesh(
vertices= None ,
edges= None ,
faces= None ,
name= 'Mesh' ,
collection= None ,
)
Create a BlenderObject from mesh data.
Parameters
vertices
ndarray or None
Array of vertex coordinates with shape (N, 3). Default is None.
None
edges
ndarray or None
Array of edge indices. Default is None.
None
faces
ndarray or None
Array of face indices. Default is None.
None
name
str
Name of the created object. Default is “Mesh”.
'Mesh'
collection
bpy.types .Collection or None
Blender collection to link the object to. Default is None.
None
Examples
import numpy as np
import databpy as db
vertices = np.array([[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ]])
bob = db.BlenderObject.from_mesh(vertices= vertices, name= "MyMesh" )
print (len (bob)) # 4
from_pointcloud
BlenderObject.from_pointcloud(
positions= None ,
name= 'PointCloud' ,
collection= None ,
)
Create a BlenderObject from point cloud data.
Parameters
positions
ndarray or None
Point positions with shape (N, 3). Default is None.
None
name
str
Name of the created object. Default is “PointCloud”.
'PointCloud'
collection
bpy.types .Collection or None
Blender collection to link the object to. Default is None.
None
Examples
import numpy as np
import databpy as db
# Create point cloud with 100 random points
positions = np.random.random((100 , 3 ))
bob = db.BlenderObject.from_pointcloud(positions, name= "MyPointCloud" )
print (len (bob)) # 100
list_attributes
BlenderObject.list_attributes(evaluate= False , drop_hidden= False )
Returns a list of attribute names for the object.
Parameters
evaluate
bool
Whether to first evaluate the modifiers on the object before listing the available attributes.
False
drop_hidden
bool
Whether to drop hidden attributes (those starting with a dot). Defaults to False.
False
Returns
list [str ] | None
A list of attribute names if the molecule object exists, None otherwise.
named_attribute
BlenderObject.named_attribute(name, evaluate= False )
Retrieve a named attribute from the object.
Optionally, evaluate the object before reading the named attribute
Parameters
name
str
Name of the attribute to get.
required
evaluate
bool
Whether to evaluate the object before reading the attribute (default is False).
False
Returns
np .ndarray
The attribute read from the mesh as a numpy array.
new_from_pydata
BlenderObject.new_from_pydata(vertices= None , edges= None , faces= None )
Create a new Blender object from vertex, edge and face data.
Parameters
vertices
np .ndarray
The vertices of the object.
None
edges
np .ndarray
The edges of the object.
None
faces
np .ndarray
The faces of the object.
None
Returns
Object
The new Blender object.
remove_named_attribute
BlenderObject.remove_named_attribute(name)
Remove a named attribute from the object.
Parameters
name
str
The name of the attribute to remove.
required
store_named_attribute
BlenderObject.store_named_attribute(
data,
name,
atype= None ,
domain= AttributeDomains.POINT,
)
Store a named attribute on the Blender object.
Parameters
data
np .ndarray
The data to be stored as an attribute.
required
name
str
The name for the attribute. Will overwrite an already existing attribute.
required
atype
str or AttributeType or None
The attribute type to store the data as. Either string or selection from the AttributeTypes enum. None will attempt to infer the attribute type from the input array.
None
domain
str or AttributeDomain
The domain to store the attribute on. Defaults to Domains.POINT.
AttributeDomains.POINT