Repository navigation
Default node properties to the values Blender sets on a new node - #256
Merged
Merged
Conversation
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.
Contributor
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
clamp_factorclampnormalizekeep_last_segmentsamplesPlus 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.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().