Name | databpy JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | A data-oriented wrapper library for the Blender Python API |
upload_time | 2024-12-20 05:54:26 |
maintainer | None |
docs_url | None |
author | None |
requires_python | ~=3.11.0 |
license | None |
keywords |
blender
python
numpy
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# databpy
[![codecov](https://codecov.io/gh/BradyAJohnston/databpy/graph/badge.svg?token=KFuu67hzAz)](https://codecov.io/gh/BradyAJohnston/databpy)
[![pypi](https://img.shields.io/pypi/v/databpy.png)](https://pypi.org/project/databpy/)
![tests](https://github.com/bradyajohnston/databpy/actions/workflows/tests.yml/badge.svg)
![deployment](https://github.com/bradyajohnston/databpy/actions/workflows/ci-cd.yml/badge.svg)
A set of data-oriented wrappers around the python API of Blender.
## Installation
Available on PyPI, install with pip:
``` bash
pip install databpy
```
> [!CAUTION]
>
> `bpy` (Blender as a python module) is listed as an optional
> dependency, so that if you install `databpy` inside of Blender you
> won’t install a redundant version of `bpy`. If you are using this
> outside of Blender, you will need to specifically request `bpy` with
> either of these methods:
>
> ``` bash
> # install wtih bpy dependency
> pip install 'databpy[bpy]'
>
> # install both packages
> pip install databpy bpy
>
> # install with all optional dependencies
> pip install 'databpy[all]'
> ```
## Usage
The main use cases are to create objects, store and retrieve attributes
from them. The functions are named around nodes in Geometry Nodes
`Store Named Attribute` and `Named Attribute`
``` python
import databpy as db
db.store_named_attribute() # store a named attribute on a mesh object
db.named_attribute() # retrieve a named attribute from a mesh object
```
Mostly oriented around creating mesh objects, assigning and getting back
attributes from them. Currently designed around storing and retrieving
`numpy` data types:
``` python
import numpy as np
import databpy as db
np.random.seed(6)
# Create a mesh object
random_verts = np.random.rand(10, 3)
obj = db.create_object(random_verts, name="RandomMesh")
obj.name
```
'RandomMesh'
Access attributes from the object’s mesh.
``` python
db.named_attribute(obj, 'position')
```
array([[0.89286017, 0.33197981, 0.8212291 ],
[0.04169663, 0.10765668, 0.59505206],
[0.52981734, 0.41880742, 0.33540785],
[0.62251943, 0.43814144, 0.7358821 ],
[0.51803643, 0.57885861, 0.64535511],
[0.99022424, 0.81985819, 0.41320094],
[0.87626767, 0.82375944, 0.05447451],
[0.71863723, 0.80217057, 0.73640662],
[0.70913178, 0.54093683, 0.12482417],
[0.95764732, 0.4032563 , 0.21695116]])
### `BlenderObject` class (bob)
This is a convenience class that wraps around the `bpy.types.Object`,
and provides access to all of the useful functions. We can wrap an
existing Object or return one when creating a new object.
This just gives us access to the `named_attribute()` and
`store_named_attribute()` functions on the object class, but also
provides a more intuitive way to access the object’s attributes.
``` python
bob = db.BlenderObject(obj) # wraps the existing object
bob = db.create_bob(random_verts) # creates a new object and returns it already wrapped
# these two are identical
bob.named_attribute('position')
bob.position
```
array([[0.89286017, 0.33197981, 0.8212291 ],
[0.04169663, 0.10765668, 0.59505206],
[0.52981734, 0.41880742, 0.33540785],
[0.62251943, 0.43814144, 0.7358821 ],
[0.51803643, 0.57885861, 0.64535511],
[0.99022424, 0.81985819, 0.41320094],
[0.87626767, 0.82375944, 0.05447451],
[0.71863723, 0.80217057, 0.73640662],
[0.70913178, 0.54093683, 0.12482417],
[0.95764732, 0.4032563 , 0.21695116]])
We can clear all of the data from the object and initialise a new mesh
underneath:
``` python
bob.new_from_pydata(np.random.randn(5, 3))
bob.position
```
array([[ 0.82465386, -1.17643154, 1.5644896 ],
[ 0.71270508, -0.1810066 , 0.53419954],
[-0.58661294, -1.48185325, 0.85724759],
[ 0.94309896, 0.11444143, -0.02195668],
[-2.12714458, -0.83440745, -0.46550831]])
## Example with Polars data
``` python
import polars as pl
import databpy as db
from io import StringIO
json_file = StringIO("""
{
"Dino": [
[55.3846, 97.1795, 0.0],
[51.5385, 96.0256, 0.0]
],
"Star": [
[58.2136, 91.8819, 0.0],
[58.1961, 92.215, 0.0]
]
}
""")
df = pl.read_json(json_file)
columns_to_explode = [col for col in df.columns if df[col].dtype == pl.List(pl.List)]
df = df.explode(columns_to_explode)
vertices = np.zeros((len(df), 3), dtype=np.float32)
bob = db.create_bob(vertices, name="DinoStar")
for col in df.columns:
data = np.vstack(df.get_column(col).to_numpy())
bob.store_named_attribute(data, col)
bob.named_attribute("Dino")
```
array([[55.38460159, 97.17949677, 0. ],
[51.53850174, 96.02559662, 0. ]])
``` python
bob.named_attribute("Star")
```
array([[58.21360016, 91.88189697, 0. ],
[58.19609833, 92.21499634, 0. ]])
Raw data
{
"_id": null,
"home_page": null,
"name": "databpy",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.11.0",
"maintainer_email": "Brady Johnston <brady.johnston@me.com>",
"keywords": "blender, python, numpy",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/51/5f/92c20e2fe178927e949485431d74a6cfefa738dce43465a1dff1ccdf432c/databpy-0.0.4.tar.gz",
"platform": null,
"description": "# databpy\n\n\n[![codecov](https://codecov.io/gh/BradyAJohnston/databpy/graph/badge.svg?token=KFuu67hzAz)](https://codecov.io/gh/BradyAJohnston/databpy)\n[![pypi](https://img.shields.io/pypi/v/databpy.png)](https://pypi.org/project/databpy/)\n![tests](https://github.com/bradyajohnston/databpy/actions/workflows/tests.yml/badge.svg)\n![deployment](https://github.com/bradyajohnston/databpy/actions/workflows/ci-cd.yml/badge.svg)\n\nA set of data-oriented wrappers around the python API of Blender.\n\n## Installation\n\nAvailable on PyPI, install with pip:\n\n``` bash\npip install databpy\n```\n\n> [!CAUTION]\n>\n> `bpy` (Blender as a python module) is listed as an optional\n> dependency, so that if you install `databpy` inside of Blender you\n> won\u2019t install a redundant version of `bpy`. If you are using this\n> outside of Blender, you will need to specifically request `bpy` with\n> either of these methods:\n>\n> ``` bash\n> # install wtih bpy dependency\n> pip install 'databpy[bpy]'\n>\n> # install both packages\n> pip install databpy bpy\n>\n> # install with all optional dependencies\n> pip install 'databpy[all]'\n> ```\n\n## Usage\n\nThe main use cases are to create objects, store and retrieve attributes\nfrom them. The functions are named around nodes in Geometry Nodes\n`Store Named Attribute` and `Named Attribute`\n\n``` python\nimport databpy as db\n\ndb.store_named_attribute() # store a named attribute on a mesh object\ndb.named_attribute() # retrieve a named attribute from a mesh object\n```\n\nMostly oriented around creating mesh objects, assigning and getting back\nattributes from them. Currently designed around storing and retrieving\n`numpy` data types:\n\n``` python\nimport numpy as np\nimport databpy as db\nnp.random.seed(6)\n\n# Create a mesh object\nrandom_verts = np.random.rand(10, 3)\n\nobj = db.create_object(random_verts, name=\"RandomMesh\")\n\nobj.name\n```\n\n 'RandomMesh'\n\nAccess attributes from the object\u2019s mesh.\n\n``` python\ndb.named_attribute(obj, 'position')\n```\n\n array([[0.89286017, 0.33197981, 0.8212291 ],\n [0.04169663, 0.10765668, 0.59505206],\n [0.52981734, 0.41880742, 0.33540785],\n [0.62251943, 0.43814144, 0.7358821 ],\n [0.51803643, 0.57885861, 0.64535511],\n [0.99022424, 0.81985819, 0.41320094],\n [0.87626767, 0.82375944, 0.05447451],\n [0.71863723, 0.80217057, 0.73640662],\n [0.70913178, 0.54093683, 0.12482417],\n [0.95764732, 0.4032563 , 0.21695116]])\n\n### `BlenderObject` class (bob)\n\nThis is a convenience class that wraps around the `bpy.types.Object`,\nand provides access to all of the useful functions. We can wrap an\nexisting Object or return one when creating a new object.\n\nThis just gives us access to the `named_attribute()` and\n`store_named_attribute()` functions on the object class, but also\nprovides a more intuitive way to access the object\u2019s attributes.\n\n``` python\nbob = db.BlenderObject(obj) # wraps the existing object \nbob = db.create_bob(random_verts) # creates a new object and returns it already wrapped\n\n# these two are identical\nbob.named_attribute('position')\nbob.position\n```\n\n array([[0.89286017, 0.33197981, 0.8212291 ],\n [0.04169663, 0.10765668, 0.59505206],\n [0.52981734, 0.41880742, 0.33540785],\n [0.62251943, 0.43814144, 0.7358821 ],\n [0.51803643, 0.57885861, 0.64535511],\n [0.99022424, 0.81985819, 0.41320094],\n [0.87626767, 0.82375944, 0.05447451],\n [0.71863723, 0.80217057, 0.73640662],\n [0.70913178, 0.54093683, 0.12482417],\n [0.95764732, 0.4032563 , 0.21695116]])\n\nWe can clear all of the data from the object and initialise a new mesh\nunderneath:\n\n``` python\nbob.new_from_pydata(np.random.randn(5, 3))\nbob.position\n```\n\n array([[ 0.82465386, -1.17643154, 1.5644896 ],\n [ 0.71270508, -0.1810066 , 0.53419954],\n [-0.58661294, -1.48185325, 0.85724759],\n [ 0.94309896, 0.11444143, -0.02195668],\n [-2.12714458, -0.83440745, -0.46550831]])\n\n## Example with Polars data\n\n``` python\nimport polars as pl\nimport databpy as db\nfrom io import StringIO\n\njson_file = StringIO(\"\"\"\n{\n \"Dino\": [\n [55.3846, 97.1795, 0.0],\n [51.5385, 96.0256, 0.0]\n ],\n \"Star\": [\n [58.2136, 91.8819, 0.0],\n [58.1961, 92.215, 0.0]\n ]\n}\n\"\"\")\n\ndf = pl.read_json(json_file)\ncolumns_to_explode = [col for col in df.columns if df[col].dtype == pl.List(pl.List)]\ndf = df.explode(columns_to_explode)\n\nvertices = np.zeros((len(df), 3), dtype=np.float32)\nbob = db.create_bob(vertices, name=\"DinoStar\")\n\nfor col in df.columns:\n data = np.vstack(df.get_column(col).to_numpy())\n bob.store_named_attribute(data, col)\n\nbob.named_attribute(\"Dino\")\n```\n\n array([[55.38460159, 97.17949677, 0. ],\n [51.53850174, 96.02559662, 0. ]])\n\n``` python\nbob.named_attribute(\"Star\")\n```\n\n array([[58.21360016, 91.88189697, 0. ],\n [58.19609833, 92.21499634, 0. ]])\n",
"bugtrack_url": null,
"license": null,
"summary": "A data-oriented wrapper library for the Blender Python API",
"version": "0.0.4",
"project_urls": {
"Dcumentation": "https://bradyajohnston.github.io/databpy",
"Homepage": "https://bradyajohnston.github.io/databpy",
"Repository": "https://github.com/bradyajohnston/databpy"
},
"split_keywords": [
"blender",
" python",
" numpy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "654dcd07ba7c3d8808faca748c6ffc9eaaaa06260d123d2f61d5b8c8f64e4060",
"md5": "d08dfa80040de572353408a56fb5bfb7",
"sha256": "cde902036c2b476bf35beb2fc4fbdd0aaf4c8d4717ae29e2899aa7534acffa14"
},
"downloads": -1,
"filename": "databpy-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d08dfa80040de572353408a56fb5bfb7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.11.0",
"size": 28514,
"upload_time": "2024-12-20T05:54:24",
"upload_time_iso_8601": "2024-12-20T05:54:24.409844Z",
"url": "https://files.pythonhosted.org/packages/65/4d/cd07ba7c3d8808faca748c6ffc9eaaaa06260d123d2f61d5b8c8f64e4060/databpy-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "515f92c20e2fe178927e949485431d74a6cfefa738dce43465a1dff1ccdf432c",
"md5": "0bc07361c9c490605315ecef1d0f6f7c",
"sha256": "a5c941ce07ce90734367872086356fdd9a0f02aa347c61915e84ef4d9edfd153"
},
"downloads": -1,
"filename": "databpy-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "0bc07361c9c490605315ecef1d0f6f7c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.11.0",
"size": 29932,
"upload_time": "2024-12-20T05:54:26",
"upload_time_iso_8601": "2024-12-20T05:54:26.218317Z",
"url": "https://files.pythonhosted.org/packages/51/5f/92c20e2fe178927e949485431d74a6cfefa738dce43465a1dff1ccdf432c/databpy-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 05:54:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bradyajohnston",
"github_project": "databpy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "databpy"
}