Skip to content

Default node properties to the values Blender sets on a new node - #256

Merged
BradyAJohnston merged 2 commits into
mainfrom
fix-property-init-defaults
Oct 9, 2026
Merged

BradyAJohnston merged 2 commits into
mainfrom
fix-property-init-defaults

Conversation

@BradyAJohnston

@BradyAJohnston BradyAJohnston commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Generated constructors took property defaults from RNA (prop.default) and assigned them, overwriting what each node's init sets. So nodebpy nodes differed from ones added in the editor; e.g. s.AmbientOcclusion() got 1 sample instead of 16. The generator now reads defaults from a freshly added node.

Behaviour change for code relying on the old defaults, most notably:

Node Property Was Now
Mix clamp_factor False True
Map Range clamp False True
Noise Texture normalize False True
Resample Curve keep_last_segment False True
Ambient Occlusion / Bevel samples 1 / 0 16 / 4

Plus Magic Texture, Sky Texture, Transform Gizmo, Input Color/Integer, and compositor Defocus, File Output and Image (full list in the changelog).

Context-dependent properties (checked against Blender's init code) are now only set when passed:

  • is_active_output: Blender keeps the first output of each type active; setting it in every constructor made the newest one active.
  • Color Balance white points: derived from the Temperature/Tint sockets, so a passed value used to be overwritten. Now applied after the sockets.
  • noise_dimensions: 2D in the compositor, 3D elsewhere.

Exports no longer spell out these defaults on untouched nodes.

New test: every node class built with no arguments matches a node added via nodes.new().

The generator took property defaults from RNA (prop.default), and the
generated constructors assign every property, so they overwrote what a
node's init function sets. A nodebpy node therefore differed from the
same node added in the editor: Mix without Clamp Factor, Map Range
without Clamp, Noise Texture without Normalize, Ambient Occlusion with
one sample (RNA default 0, clamped), and about forty more.

Read the defaults off the freshly created node instead, as enum
properties already were. Strings stay empty so machine-specific values
(File Output's temp directory) are not written into the code. The
hand-written compositor Image node had the same wrong frame range and
auto-refresh defaults.

A new test builds every node class with no arguments and compares its
properties with a node added directly.
@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 15 untouched benchmarks


Comparing fix-property-init-defaults (7818ef1) with main (565b7c6)

Open in CodSpeed

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.75510% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.27%. Comparing base (565b7c6) to head (7818ef1).

Files with missing lines Patch % Lines
src/nodebpy/nodes/shader/output.py 62.50% 3 Missing ⚠️
src/nodebpy/export/codegen.py 96.42% 1 Missing ⚠️
src/nodebpy/nodes/compositor/color.py 75.00% 1 Missing ⚠️
src/nodebpy/nodes/geometry/interface.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #256      +/-   ##
==========================================
- Coverage   98.30%   98.27%   -0.04%     
==========================================
  Files         101      101              
  Lines       30574    30611      +37     
==========================================
+ Hits        30056    30083      +27     
- Misses        518      528      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Checking the init functions in Blender's source showed three properties
whose fresh value depends on more than the node:

- is_active_output is decided for the whole tree (the first output of
  each type stays active). Assigning it in every constructor made the
  newest output active, unlike the editor.
- Color Balance's white points are computed from the temperature and
  tint sockets through the color management config, and setting them
  writes those sockets. A default was config-specific, and a passed
  value was always overwritten by the socket defaults.
- Noise Texture starts 2D in the compositor and 3D elsewhere, and one
  class serves both trees.

The generator marks these optional: the parameter defaults to None and
is assigned only when passed (enums before the sockets, since they can
decide which exist; the white points after, so they win over the socket
defaults). The exporter compares None-default properties with a fresh
node in the same kind of tree, writes is_active_output only when a tree
has several outputs of that type, and skips the derived white points.
@BradyAJohnston
BradyAJohnston merged commit 7db486d into main Oct 9, 2026
9 of 11 checks passed
@BradyAJohnston
BradyAJohnston deleted the fix-property-init-defaults branch October 9, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant