Skip to main content

Easy and fast access to Blender attributes

Project description

blempy — Blender ↔ NumPy helpers

blempy provides small, safe utilities to efficiently transfer Blender property-collection attributes (e.g. vertex coordinates) to/from NumPy arrays and perform vectorized operations with minimal Python overhead.

[!NOTE]
This module is not fully fleshed out yet, and its contents/interface may change

Key classes

  • PropertyCollectionAttributeProxy

    • Purpose: bulk transfer for any property-collection attribute (uses foreach_get/foreach_set).
    • Important members:
      • get(): fills/allocates a float32 NumPy array from the property collection.
      • set(): writes the NumPy array back to the property collection.
      • ndarray, items, length: current array and shape metadata.
    • Behavior: automatically reallocates array when collection size or vector length changes. Raises ValueError on empty collections.
  • VectorCollectionProxy (subclass)

    • Purpose: conveniences for 3D/4D vector collections.
    • Methods:
      • extend(normal=False): append a 4th column (ones by default, zeros if normal=True).
      • discard(): remove the 4th column.
      • __matmul__(matrix): apply a matrix to all vectors (in-place) and return self.
  • LoopVectorAttributeProxy

    • Purpose: conveniences loop layer attributes.
    • Methods:
      • __matmul____(matrix): apply a matrix to all vectors (in-place) and return self.
      • __iter____ and __next____: to return all the loop layer attributes for each polygon in a mesh
      • __len____: returns the number of polygons in a mesh

Characteristics / notes

  • Uses dtype float32 for most buffers, and int for indices.
  • Designed around Blender's volatile property-collection references — proxies compute references on each get/set.
  • Intended for workflows where mesh data is read/written in bulk (faster than per-item Python attribute access).
  • Raises clear exceptions for empty collections or incompatible shapes.

Minimal usage example

from mathutils import Matrix
from bpy.context import active_object
from blempy import VectorCollectionProxy

mesh = active_object.data
vproxy = VectorCollectionProxy(mesh, "vertices", "co")
vproxy.get()                        # load vertex coordinates into vproxy.ndarray
vproxy.extend()                     # convert to 4D so that matrix multiplication
                                    # can deal with translation too
# combine a rotation and a translation into a single matrix
matrix = Matrix.Rotation(pi/4, 4, [0,0,1])
matrix = matrix @ Matrix.Translation(4, [0,0,1])    
vproxy = vproxy @ matrix            # transform in-place
vproxy.discard()                    # discard the 4th column
vproxy.set()                        # write back to mesh

Installation

for now, simply copy the blempy folder into your PYTHONPATH. We might convert this to a proper pypi package in the future

TODO

  • additional convenience functions for frequently used vector operations like translate, scale, rotate, space conversions, ...
  • ... possibly even mapped to dunder methods (like __add__ for translation or __mul__ for scale, etc.)
  • a specific subclass to deal with properties that are associated with the loop layer, like vertex colors and uv coordinates

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blempy-0.1.0.tar.gz (30.5 kB view details)

Uploaded Source

File details

Details for the file blempy-0.1.0.tar.gz.

File metadata

  • Download URL: blempy-0.1.0.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for blempy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac1d85d50940c4b9c83736c15a6ad8603835f1eb2b8904d48bf821d331ed75cb
MD5 fee057d4b2c8fa700001ec409ae4d804
BLAKE2b-256 58608f8dcb9e6b0faecfc9d33afd2df3977aad1d0e210e217a2b7296f055f8da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page