Skip to content

Commit

Permalink
bump with fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed Dec 19, 2024
1 parent a74f166 commit 94b7e23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions databpy/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ def __getitem__(self, key: str) -> Object:
return bpy.data.objects[key]


def _check_obj_is_mesh(obj: Object) -> None:
if not isinstance(obj.data, bpy.types.Mesh):
raise ValueError("Object must be a mesh")
def _check_obj_accsibble_attributes(obj: Object) -> None:
if isinstance(obj.data, bpy.types.Mesh):
return
if isinstance(obj, bpy.types.PointCloud):
return

raise ValueError(
f"Object must be a mesh or point cloud to have point attributes: {obj}"
)


bdo = ObjectDatabase()
Expand Down Expand Up @@ -158,6 +164,9 @@ def __init__(self, obj: Object | str | None = None):
elif obj is None:
self._object_name = ""

def _check_obj(self) -> None:
_check_obj_accsibble_attributes(self.object)

@property
def object(self) -> Object:
"""
Expand Down Expand Up @@ -197,8 +206,6 @@ def object(self, value: Object) -> None:
if not isinstance(value, Object):
raise ValueError(f"{value} must be a bpy.types.Object")

_check_obj_is_mesh(value)

try:
value.uuid = self.uuid
except AttributeError:
Expand Down Expand Up @@ -259,6 +266,7 @@ def new_from_pydata(
Object
The new Blender object.
"""
self._check_obj()
vertices, edges, faces = [
[] if x is None else x for x in (vertices, edges, faces)
]
Expand Down Expand Up @@ -293,6 +301,7 @@ def store_named_attribute(
-------
self
"""
self._check_obj()
attr.store_named_attribute(
self.object, data=data, name=name, atype=atype, domain=domain
)
Expand All @@ -307,6 +316,7 @@ def remove_named_attribute(self, name: str) -> None:
name : str
The name of the attribute to remove.
"""
self._check_obj()
attr.remove_named_attribute(self.object, name=name)

def named_attribute(self, name: str, evaluate: bool = False) -> np.ndarray:
Expand All @@ -326,6 +336,7 @@ def named_attribute(self, name: str, evaluate: bool = False) -> np.ndarray:
np.ndarray
The attribute read from the mesh as a numpy array.
"""
self._check_obj()
return attr.named_attribute(self.object, name=name, evaluate=evaluate)

def set_boolean(self, array: np.ndarray, name: str) -> None:
Expand All @@ -339,6 +350,7 @@ def set_boolean(self, array: np.ndarray, name: str) -> None:
name : str
The name for the attribute.
"""
self._check_obj()
self.store_named_attribute(array, name=name, atype=AttributeTypes.BOOLEAN)

def evaluate(self) -> Object:
Expand All @@ -350,6 +362,7 @@ def evaluate(self) -> Object:
Object
A new Object that isn't yet registered with the database
"""
self._check_obj()
obj = self.object
obj.update_tag()
return obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
Expand All @@ -372,6 +385,7 @@ def centroid(self, weight: str | np.ndarray | None = None) -> np.ndarray:
np.ndarray
A 3-component vector with the calculated centroid.
"""
self._check_obj()
if isinstance(weight, str):
return centre(self.position, self.named_attribute(weight))

Expand Down Expand Up @@ -402,6 +416,7 @@ def vertices(self):
bpy.types.Vertices
The vertices of the Blender object.
"""

return self.object.data.vertices

@property
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "databpy"
version = "0.0.2"
version = "0.0.3"
description = "A data-oriented wrapper library for the Blender Python API"
readme = "README.md"
dependencies = ["numpy>=1.26.0,<2.0"]
Expand Down

0 comments on commit 94b7e23

Please sign in to comment.