RNA: compositor output node API #121382

Open
Eyad Ahmed wants to merge 1 commits from EyadAhmed/blender:compositor-output-node-rna-api into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

adds:
is_active_output property to CompositorNodeComposite
get_output_node method to CompositorNodeTree

making this right click select request come true:
https://blender.community/c/rightclickselect/LJl4/

and makes the Compositor Node Tree RNA API more similar to Shader Node tree

adds: `is_active_output` property to `CompositorNodeComposite` `get_output_node` method to `CompositorNodeTree` making this right click select request come true: https://blender.community/c/rightclickselect/LJl4/ and makes the Compositor Node Tree RNA API more similar to Shader Node tree

First of all, what for?

First of all, what for?
Iliya Katushenock added this to the Nodes & Physics project 2024-05-03 09:32:32 +02:00
Iliya Katushenock added the
Module
VFX & Video
Interest
Compositing
labels 2024-05-03 09:32:41 +02:00
First-time contributor

First of all, what for?

I have the use case : I'm working on an addon that needs to detect which Composite output node is the active one, when the user has added many of them.

Anyway, similar property/method exists for the shaders output node, so it seems legit and consistent to have this for the compositor too.

> First of all, what for? I have the use case : I'm working on an addon that needs to detect which Composite output node is the active one, when the user has added many of them. Anyway, similar property/method exists for the shaders output node, so it seems legit and consistent to have this for the compositor too.

Okay, mainly my question was about get_output_node\

Okay, mainly my question was about `get_output_node`\
First-time contributor

Okay, mainly my question was about get_output_node\

For consistency with the similar method in shaders

> Okay, mainly my question was about `get_output_node`\ For consistency with the similar method in shaders
Brecht Van Lommel requested changes 2024-05-03 15:40:02 +02:00
Brecht Van Lommel left a comment
Owner

This should call ED_node_set_active. Currently there is no check to verify that the node can in fact be used as an output, and it's missing a call to e.g. BKE_ntree_update_tag_active_output_changed.

It raises the question if this can a more general property for other nodes and node trees. Since shader and geometry nodes also have an active output node.

This should call `ED_node_set_active`. Currently there is no check to verify that the node can in fact be used as an output, and it's missing a call to e.g. `BKE_ntree_update_tag_active_output_changed`. It raises the question if this can a more general property for other nodes and node trees. Since shader and geometry nodes also have an active output node.
Eyad Ahmed force-pushed compositor-output-node-rna-api from 01f79e31aa to 248e8b213e 2024-05-04 20:46:32 +02:00 Compare
Eyad Ahmed force-pushed compositor-output-node-rna-api from 248e8b213e to 72ca8d644a 2024-05-04 20:48:21 +02:00 Compare
Author
Contributor

This should call ED_node_set_active. Currently there is no check to verify that the node can in fact be used as an output, and it's missing a call to e.g. BKE_ntree_update_tag_active_output_changed.

It raises the question if this can a more general property for other nodes and node trees. Since shader and geometry nodes also have an active output node.

I updated the code to call ntreeSetOutput(ntree);
in static bNode *ntreeCompositorOutputNode(bNodeTree *ntree)
similar to the existing Shader Nodes implementation ntreeShaderOutputNode

also regarding BKE_ntree_update_tag_active_output_changed
is_active_output property already calls rna_Node_update via RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
just like the existing Shader Nodes implementation

void rna_Node_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
{
  bNodeTree *ntree = reinterpret_cast<bNodeTree *>(ptr->owner_id);
  bNode *node = static_cast<bNode *>(ptr->data);
  BKE_ntree_update_tag_node_property(ntree, node);
  ED_node_tree_propagate_change(nullptr, bmain, ntree);
}
> This should call `ED_node_set_active`. Currently there is no check to verify that the node can in fact be used as an output, and it's missing a call to e.g. `BKE_ntree_update_tag_active_output_changed`. > > It raises the question if this can a more general property for other nodes and node trees. Since shader and geometry nodes also have an active output node. I updated the code to call `ntreeSetOutput(ntree);` in `static bNode *ntreeCompositorOutputNode(bNodeTree *ntree)` similar to the existing Shader Nodes implementation `ntreeShaderOutputNode` also regarding `BKE_ntree_update_tag_active_output_changed` `is_active_output` property already calls `rna_Node_update` via `RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");` just like the existing Shader Nodes implementation ``` void rna_Node_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr) { bNodeTree *ntree = reinterpret_cast<bNodeTree *>(ptr->owner_id); bNode *node = static_cast<bNode *>(ptr->data); BKE_ntree_update_tag_node_property(ntree, node); ED_node_tree_propagate_change(nullptr, bmain, ntree); } ```
Iliya Katushenock reviewed 2024-05-04 21:19:26 +02:00
@ -3941,6 +3941,20 @@ static PointerRNA rna_NodeMenuSwitch_enum_definition_get(PointerRNA *ptr)
return *ptr;
}
constexpr auto rna_CompositorNode_is_active_output_set = rna_ShaderNode_is_active_output_set;

Just use rna_ShaderNode_is_active_output_set in RNA_def_property_boolean_funcs.

Just use `rna_ShaderNode_is_active_output_set` in `RNA_def_property_boolean_funcs`.
Author
Contributor

Done, renamed rna_ShaderNode_is_active_output_set to rna_Node_is_active_output_set
and used it in both

Done, renamed `rna_ShaderNode_is_active_output_set` to `rna_Node_is_active_output_set` and used it in both
EyadAhmed marked this conversation as resolved
@ -3944,0 +3948,4 @@
/* Make sure we only have single node tagged as output. */
ntreeSetOutput(ntree);
for (bNode *node : ntree->all_nodes()) {
if (node->type == CMP_NODE_COMPOSITE && node->flag & NODE_DO_OUTPUT) {

Why this can not be node group output?

Why this can not be node group output?
Author
Contributor

this is already handled in rna_GroupOutput_is_active_output_set

static void def_group_output(StructRNA *srna)
{
  ...
  RNA_def_property_boolean_funcs(prop, nullptr, "rna_GroupOutput_is_active_output_set");
  ...
}
this is already handled in `rna_GroupOutput_is_active_output_set` ``` static void def_group_output(StructRNA *srna) { ... RNA_def_property_boolean_funcs(prop, nullptr, "rna_GroupOutput_is_active_output_set"); ... } ```

No, i mean, this function should return node group if node tree is group.

No, i mean, this function should return node group if node tree is group.
Author
Contributor

@mod_moder apologies for delay now it is done

static bNode *ntreeCompositorOutputNode(bNodeTree *ntree)
{
  /* Make sure we only have single node tagged as output. */
  ntreeSetOutput(ntree);
  for (bNode *node : ntree->all_nodes()) {
    if (ELEM(node->type, CMP_NODE_COMPOSITE, NODE_GROUP_OUTPUT) && node->flag & NODE_DO_OUTPUT) {
      return node;
    }
  }
  return nullptr;
}
@mod_moder apologies for delay now it is done ``` static bNode *ntreeCompositorOutputNode(bNodeTree *ntree) { /* Make sure we only have single node tagged as output. */ ntreeSetOutput(ntree); for (bNode *node : ntree->all_nodes()) { if (ELEM(node->type, CMP_NODE_COMPOSITE, NODE_GROUP_OUTPUT) && node->flag & NODE_DO_OUTPUT) { return node; } } return nullptr; } ```

Foe this propose, we have bNode::is_group()

Foe this propose, we have `bNode::is_group()`

Testing compositor nodes with output nodes inside group nodes, it doesn't seem to actually work this way?

Testing compositor nodes with output nodes inside group nodes, it doesn't seem to actually work this way?
Eyad Ahmed force-pushed compositor-output-node-rna-api from 72ca8d644a to 7d6b60b0af 2024-05-05 00:25:43 +02:00 Compare
Eyad Ahmed force-pushed compositor-output-node-rna-api from 7d6b60b0af to fbe3b50695 2024-05-06 01:46:25 +02:00 Compare

I just noticed that something like this already exists in the API.
https://docs.blender.org/api/main/bpy.types.Nodes.html#bpy.types.Nodes.active

But it's not exactly the same, since active and active output are not quite the same thing. But maybe we should make the API more consistent and have nodes.active and nodes.output.

also regarding BKE_ntree_update_tag_active_output_changed
is_active_output property already calls rna_Node_update via RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");

BKE_ntree_update_tag_active_output_changed and BKE_ntree_update_tag_node_property are not the same thing?

I just noticed that something like this already exists in the API. https://docs.blender.org/api/main/bpy.types.Nodes.html#bpy.types.Nodes.active But it's not exactly the same, since active and active output are not quite the same thing. But maybe we should make the API more consistent and have `nodes.active` and `nodes.output`. > also regarding `BKE_ntree_update_tag_active_output_changed` > `is_active_output` property already calls `rna_Node_update` via `RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");` `BKE_ntree_update_tag_active_output_changed` and `BKE_ntree_update_tag_node_property` are not the same thing?
First-time contributor

I just noticed that something like this already exists in the API.
https://docs.blender.org/api/main/bpy.types.Nodes.html#bpy.types.Nodes.active

But it's not exactly the same, since active and active output are not quite the same thing. But maybe we should make the API more consistent and have nodes.active and nodes.output.

The "is_active_output" property appears clear to me. Are you concerned about the usage of the word "active" in this property name?

> I just noticed that something like this already exists in the API. > https://docs.blender.org/api/main/bpy.types.Nodes.html#bpy.types.Nodes.active > > But it's not exactly the same, since active and active output are not quite the same thing. But maybe we should make the API more consistent and have `nodes.active` and `nodes.output`. > The "is_active_output" property appears clear to me. Are you concerned about the usage of the word "active" in this property name?

I'm not concerned about active_output vs. output naming, but about consistently using a property vs. a function for this.

I'm not concerned about `active_output` vs. `output` naming, but about consistently using a property vs. a function for this.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u compositor-output-node-rna-api:EyadAhmed-compositor-output-node-rna-api
git checkout EyadAhmed-compositor-output-node-rna-api
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121382
No description provided.