Simplified base color for socket types #109288

Closed
Lukas Tönne wants to merge 1 commits from LukasTonne/blender:static-node-socket-type-color into main

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

Socket types have a draw_color callback that defines the color of a
socket in the ui (node editor, group interfaces, shader tree view, etc).
This callback is overly generic, it takes a bContext as well as a node
and socket instance. Technically this callback can only be used when
there is a context and a concrete instance of a socket.

In the vast majority of cases this contextual data is not necessary and
we simply use a static type-based color. To make this less complicated,
this patch adds an alternative base_color type member. This is a plain
color value which is used in place of the draw_color callback when it
isn't defined. Standard socket types no longer define a draw_color
callback and only use the base_color.

Compatibility with python nodes addons is important:

  • The draw_color callback was required, it is now optional. Addons can
    keep using it, but bl_base_color is recommended for new code.
  • The new base_color property is registerable, but optional so as to
    not cause errors in existing scripts.
  • Documentation needs updating:
    • Explain that draw_color is now optional, and bl_base_color is
      used by default.
    • Suggest defining the bl_base_color property instead of the
      draw_color function.
  • Update python templates for custom nodes to demonstrate the
    bl_base_color property.
Socket types have a `draw_color` callback that defines the color of a socket in the ui (node editor, group interfaces, shader tree view, etc). This callback is overly generic, it takes a `bContext` as well as a node and socket instance. Technically this callback can only be used when there is a context and a concrete instance of a socket. In the vast majority of cases this contextual data is not necessary and we simply use a static type-based color. To make this less complicated, this patch adds an alternative `base_color` type member. This is a plain color value which is used in place of the `draw_color` callback when it isn't defined. Standard socket types no longer define a `draw_color` callback and only use the `base_color`. Compatibility with python nodes addons is important: - The `draw_color` callback was required, it is now optional. Addons can keep using it, but `bl_base_color` is recommended for new code. - The new `base_color` property is registerable, but optional so as to not cause errors in existing scripts. - [ ] Documentation needs updating: - Explain that `draw_color` is now optional, and `bl_base_color` is used by default. - Suggest defining the `bl_base_color` property instead of the `draw_color` function. - [ ] Update python templates for custom nodes to demonstrate the `bl_base_color` property.
Lukas Tönne added 1 commit 2023-06-23 14:04:04 +02:00
397532a5a5 Simplified base color for socket types
Socket types have a `draw_color` callback that defines the color of a
socket in the ui (node editor, group interfaces, shader tree view, etc).
This callback is overly generic, it takes a `bContext` as well as a node
and socket instance. Technically this callback can only be used when
there is a context and a concrete instance of a socket.

In the vast majority of cases this contextual data is not necessary and
we simply use a static type-based color. To make this less complicated,
this patch adds an alternative `base_color` type member. This is a plain
color value which is used in place of the `draw_color` callback when it
isn't defined. Standard socket types no longer define a `draw_color`
callback and only use the `base_color`.

Compatibility with python nodes addons is important:
- The `draw_color` callback was required, it is now optional. Addons can
  keep using it, but `bl_base_color` is recommended for new code.
- The new `base_color` property is registerable, but optional so as to
  not cause errors in existing scripts.
- [ ] Documentation needs updating:
  - Explain that `draw_color` is now optional, and `bl_base_color` is
    used by default.
  - Suggest defining the `bl_base_color` property instead of the
    `draw_color` function.
- [ ] Update python templates for custom nodes to demonstrate the
  `bl_base_color` property.
Lukas Tönne added this to the Nodes & Physics project 2023-06-23 14:04:24 +02:00
Lukas Tönne requested review from Jacques Lucke 2023-06-23 14:04:36 +02:00
Lukas Tönne requested review from Hans Goudey 2023-06-23 14:04:36 +02:00
Author
Member

Custom nodes colors currently seem to be somewhat broken by #109231

Custom nodes colors currently seem to be somewhat broken by #109231

This should not be simplified. If we want to have dynamic socket types in the future, determined from the context of the node tree, then this will still be in demand.

This should not be simplified. If we want to have dynamic socket types in the future, determined from the context of the node tree, then this will still be in demand.

Custom nodes colors currently seem to be somewhat broken by #109231

This is not related. There the problem is that users need their own version of the declaration to update nodes...

> Custom nodes colors currently seem to be somewhat broken by #109231 This is not related. There the problem is that users need their own version of the declaration to update nodes...
Member

Generally seems fine. I mainly wonder right now whether a better alternative could be to allow passing in null into draw_color to avoid having two ways to find the socket color. Can't make up my mind right now. Have you thought about that?

Generally seems fine. I mainly wonder right now whether a better alternative could be to allow passing in null into `draw_color` to avoid having two ways to find the socket color. Can't make up my mind right now. Have you thought about that?
Author
Member

Allowing null for context, node, and socket pointers would be ideal, yes. However, we have not stated any such requirements for custom python nodes, so we can't expect those callbacks to handle nullptr gracefully (it should not crash, but would throw lots of errors).

Allowing null for context, node, and socket pointers would be ideal, yes. However, we have not stated any such requirements for custom python nodes, so we can't expect those callbacks to handle nullptr gracefully (it should not crash, but would throw lots of errors).
Member

Right now I think the main argument for the new base color property is that it can be used without a socket instance and that may be enough reason. I think it would be ok to change the API so that passing in None for the context is allowed, however passing None for the socket would be weird and makes the callback kind of useless.

Right now I think the main argument for the new base color property is that it can be used without a socket instance and that may be enough reason. I think it would be ok to change the API so that passing in `None` for the context is allowed, however passing `None` for the socket would be weird and makes the callback kind of useless.
Jacques Lucke reviewed 2023-06-23 16:49:30 +02:00
@ -171,6 +171,7 @@ typedef struct bNodeSocketType {
struct PointerRNA *ptr,
struct PointerRNA *node_ptr,
float *r_color);
float base_color[4];
Member

Add comment saying that this is only used when draw_color is null, or when the context is not available, or when there is no socket instance.

Why base btw?

Add comment saying that this is only used when `draw_color` is null, or when the context is not available, or when there is no socket instance. Why `base` btw?
Author
Member

I was thinking of how base_cpp_type and geometry_nodes_cpp_type works. It's implied that the complex type/color is a variation of the base type/color, even though they can be totally separate.

No strong feelings about the name, could be simple_color or just color. Will add more comments.

I was thinking of how `base_cpp_type` and `geometry_nodes_cpp_type` works. It's implied that the complex type/color is a variation of the base type/color, even though they can be totally separate. No strong feelings about the name, could be `simple_color` or just `color`. Will add more comments.
Member

Would use just color for now.

Would use just `color` for now.
Member

Allowing null for context, node, and socket pointers would be ideal, yes. However, we have not stated any such requirements for custom python nodes, so we can't expect those callbacks to handle nullptr gracefully (it should not crash, but would throw lots of errors).

This seems like a reasonable API change. For 4.0 we can make this sort of change, and I'd argue it makes sense when it simplifies the design.

> Allowing null for context, node, and socket pointers would be ideal, yes. However, we have not stated any such requirements for custom python nodes, so we can't expect those callbacks to handle nullptr gracefully (it should not crash, but would throw lots of errors). This seems like a reasonable API change. For 4.0 we can make this sort of change, and I'd argue it makes sense when it simplifies the design.

This should not be simplified. If we want to have dynamic socket types in the future, determined from the context of the node tree, then this will still be in demand.

Maybe it will be easier to change socket colors, shapes, link field interface types, and everything else when it is bound to the context of the object - the owner of the context (modifier, material, ...), so then this change is not so blocking for wounds time of socket types.

> This should not be simplified. If we want to have dynamic socket types in the future, determined from the context of the node tree, then this will still be in demand. Maybe it will be easier to change socket colors, shapes, link field interface types, and everything else when it is bound to the context of the object - the owner of the context (modifier, material, ...), so then this change is not so blocking for wounds time of socket types.
Author
Member

We have the draw_color_simple callback now, so this is redundant.

We have the `draw_color_simple` callback now, so this is redundant.
Lukas Tönne closed this pull request 2023-09-25 11:16:43 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
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#109288
No description provided.