Skip to main content

Build nodes in Blender with code

Project description

nodebpy

Run Tests

A package to help build node trees in blender more elegantly with python code.

The Design Idea

Other projects have attempted similar but none quite handled the API how I felt it should be done. Notable existing projects are geometry-script, geonodes, NodeToPython.

Other projects implement chaining of nodes mostly as dot methos of nodes to chain them (InstanceOnPoints().set_position()). This has the potential to crowd the API for individual nodes and easy chaining is instead approached via overriding the >> operator.

Chain Nodes with >>

By default the operator attempts to link the first output of the previous node with the first input of the next. You can override this behaviour by being explicit with the socket you are passing out (AccumulateField().o_total) or using the ... for the inputs into the next node. The dots can appear at multiple locations and each input will be linked to the previous node via the inferred or specified socket.

Example Node Tree

from nodebpy import TreeBuilder, nodes as n, sockets as s

with TreeBuilder("AnotherTree", collapse=True) as tree:
    with tree.inputs:
        count = s.SocketInt("Count", 10)
    with tree.outputs:
        instances = s.SocketGeometry("Instances")

    rotation = (
        n.RandomValue.vector(min=-1, seed=2)
        >> n.AlignRotationToVector()
        >> n.RotateRotation(rotate_by=n.AxisAngleToRotation(angle=0.3))
    )

    _ = (
        count
        >> n.Points(position=n.RandomValue.vector(min=-1))
        >> n.InstanceOnPoints(instance=n.Cube(), rotation=rotation)
        >> n.SetPosition(
            position=n.Position() * 2.0 + (0, 0.2, 0.3),
            offset=(0, 0, 0.1),
        )
        >> n.RealizeInstances()
        >> n.InstanceOnPoints(n.Cube(), instance=...)
        >> instances
    )

Design Considerations

Whenever possible, support IDE auto-complete and have useful types. We should know as much ahead of time as possible if our network will actually build.

  • Stick as closely to Geometry Nodes naming as possible
    • RandomValue creates a random value node
      • RandomValue.vector() creates it set to "VECTOR" data type and provides arguments for IDE auto-complete
  • Inputs and outputs from a node are prefixed with i_* and o_:
    • AccumulateField().o_total returns the output Total socket
    • AccumulateField().i_value returns the input Value socket
  • If inputs are subject to change depending on enums, provide separate constructor methods that provide related inputs as arguments. There should be no guessing involved and IDEs should provide documentation for what is required:
    • TransformGeometry.matrix(CombineTrasnsform(translation=(0, 0, 1))
    • TransformGeoemtry.components(translation=(0, 0, 1))
    • TransformGeometry(translation=(0, 0, 1))

Building

Most node classes are generated automatically with this. The nodes in nodes/manual.py are currently manually specified due to varying complexities of particular nodes (usually lergacy).

uv run generate.py && ruff format && ruff check --fix --unsafe-fixes

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

nodebpy-0.4.0.tar.gz (110.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nodebpy-0.4.0-py3-none-any.whl (127.4 kB view details)

Uploaded Python 3

File details

Details for the file nodebpy-0.4.0.tar.gz.

File metadata

  • Download URL: nodebpy-0.4.0.tar.gz
  • Upload date:
  • Size: 110.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nodebpy-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2bdd42b0376d33835d60763d7c04980d1db5f92fc847c3887d03bc916eaec0d0
MD5 0d2cc92a22fd30dd9a0a0b484909e92a
BLAKE2b-256 a9e049fcdd257e3a5d17d9cd13bb996ced6bf76d6d94da24827d5199df7e4152

See more details on using hashes here.

Provenance

The following attestation bundles were made for nodebpy-0.4.0.tar.gz:

Publisher: pypi.yml on BradyAJohnston/nodebpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nodebpy-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: nodebpy-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 127.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nodebpy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81eb7d7cacca4a9b4ffd610a79bd8bc1898163ab6558a4b4b2a02057ec3b26f2
MD5 f7c808e8089e6173604606a9770c0dbf
BLAKE2b-256 36eeda65e1ae6bdd2e5cd95e5814c52cf08e0dfbb533427482f87e1494a8d3f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for nodebpy-0.4.0-py3-none-any.whl:

Publisher: pypi.yml on BradyAJohnston/nodebpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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