Not possible to link a "Vector math" node using operation "Dot product" to another node in python . #72901

Closed
opened 2020-01-04 17:50:14 +01:00 by Cédric · 12 comments
Member

System Information
Operating system: Windows-10-10.0.17763-SP0 64 Bits
Graphics card: GeForce GTX 1080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.66

Blender Version
Broken: version: 2.81 official
Broken: version: 2.82 (sub 6), branch: master, commit date: 2020-01-03 10:02, hash: 9b74e648c5

Short description of error
When using the Vector Math node with the "Dot product" operation, it is not possible to link this node to another one. The link is invisible and broken.

Exact steps for others to reproduce the error
Using the factory settings, select the cube and copy/paste and execute the following script, wich create 2 nodes and try to connect them or open the dot_product.blend wich includ the script :

import bpy

mat = bpy.data.materials['Material']

# Clear node tree
mat.node_tree.nodes.clear()

dot_product = mat.node_tree.nodes.new('ShaderNodeVectorMath')
dot_product.operation = 'DOT_PRODUCT'
dot_product.location = (-580.0, 80.0)

subtract = mat.node_tree.nodes.new('ShaderNodeMath')
subtract.operation = 'SUBTRACT'
subtract.location = (-360.0, 40.0)

mat.node_tree.links.new(dot_product.outputs[0], subtract.inputs[0])

dot_product.blend

As you can see, the nodes are not connected together and it is not possible to cut the link. Changing the vector math to a vector operation works :

2020-01-04_17-29-08.gif

**System Information** Operating system: Windows-10-10.0.17763-SP0 64 Bits Graphics card: GeForce GTX 1080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 441.66 **Blender Version** Broken: version: 2.81 official Broken: version: 2.82 (sub 6), branch: master, commit date: 2020-01-03 10:02, hash: `9b74e648c5` **Short description of error** When using the Vector Math node with the "Dot product" operation, it is not possible to link this node to another one. The link is invisible and broken. **Exact steps for others to reproduce the error** Using the factory settings, select the cube and copy/paste and execute the following script, wich create 2 nodes and try to connect them or open the dot_product.blend wich includ the script : ``` import bpy mat = bpy.data.materials['Material'] # Clear node tree mat.node_tree.nodes.clear() dot_product = mat.node_tree.nodes.new('ShaderNodeVectorMath') dot_product.operation = 'DOT_PRODUCT' dot_product.location = (-580.0, 80.0) subtract = mat.node_tree.nodes.new('ShaderNodeMath') subtract.operation = 'SUBTRACT' subtract.location = (-360.0, 40.0) mat.node_tree.links.new(dot_product.outputs[0], subtract.inputs[0]) ``` [dot_product.blend](https://archive.blender.org/developer/F8259821/dot_product.blend) As you can see, the nodes are not connected together and it is not possible to cut the link. Changing the vector math to a vector operation works : ![2020-01-04_17-29-08.gif](https://archive.blender.org/developer/F8259819/2020-01-04_17-29-08.gif)
Author
Member

Added subscriber: @Clarkx

Added subscriber: @Clarkx

Added subscriber: @Stan_Pancakes

Added subscriber: @Stan_Pancakes

It would seem that to work correctly, this should be
mat.node_tree.links.new(dot_product.outputs- [x], subtract.inputs[0])
(first output is vector, second is scalar, but only one of them is displayed depending on operation).

The same behavior can be recreated without a script: add the same two nodes (Vector Math and Math), connect the vector output of Vector Math to the value input of Math, then switch Vector Math to 'Dot Product'. Value input of Math node will remain "connected", even though no noodle is displayed.

It would seem that to work correctly, this should be ```mat.node_tree.links.new(dot_product.outputs- [x], subtract.inputs[0])``` (first output is vector, second is scalar, but only one of them is displayed depending on operation). The same behavior can be recreated without a script: add the same two nodes (Vector Math and Math), connect the vector output of Vector Math to the value input of Math, then switch Vector Math to 'Dot Product'. Value input of Math node will remain "connected", even though no noodle is displayed.

Added subscriber: @rjg

Added subscriber: @rjg

The issue is that the Vector Math node has actually two output sockets, one of type [bpy.types.NodeSocketVector ]] and one of type https:*docs.blender.org/api/current/bpy.types.NodeSocketFloat.html . Since you want to connect the Vector Math node to the Math node that only has input sockets of type [ https://docs.blender.org/api/current/bpy.types.NodeSocketFloat.html | bpy.types.NodeSocketFloat , you will have to use the latter.

In order to let Blender determine the appropriate socket based on its type you can address them by name instead of index:

mat.node_tree.links.new(subtract.inputs["Value"], dot_product.outputs["Value"])

If you want to use indices, you will have to use the one of appropriate type:

mat.node_tree.links.new(subtract.inputs[0], dot_product.outputs[1])
The issue is that the *Vector Math* node has actually two output sockets, one of type [bpy.types.NodeSocketVector ]] and one of type [[ https:*docs.blender.org/api/current/bpy.types.NodeSocketFloat.html | bpy.types.NodeSocketFloat ]]. Since you want to connect the *Vector Math* node to the *Math* node that only has input sockets of type [[ https://docs.blender.org/api/current/bpy.types.NodeSocketFloat.html | bpy.types.NodeSocketFloat ](https:*docs.blender.org/api/current/bpy.types.NodeSocketVector.html), you will have to use the latter. In order to let Blender determine the appropriate socket based on its type you can address them by name instead of index: ``` mat.node_tree.links.new(subtract.inputs["Value"], dot_product.outputs["Value"]) ``` If you want to use indices, you will have to use the one of appropriate type: ``` mat.node_tree.links.new(subtract.inputs[0], dot_product.outputs[1]) ```

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Robert Guetzkow self-assigned this 2020-01-04 18:39:08 +01:00

This is working as designed and is therefore not a bug.

This is working as designed and is therefore not a bug.
Author
Member

Thanks to both of you for the tips, it's working now using your advise. Sorry for the misunderstanding !
But as @Stan_Pancakes say, the same behavior appear when changing manually the operation in the node editor, wich is really strange

Thanks to both of you for the tips, it's working now using your advise. Sorry for the misunderstanding ! But as @Stan_Pancakes say, the same behavior appear when changing manually the operation in the node editor, wich is really strange

@Clarkx Basically one output socket and its connections are hidden when changing to an operation that produces a different type of output and therefore requires a different output socket. Internally the connection is still remembered.

@Clarkx Basically one output socket and its connections are hidden when changing to an operation that produces a different type of output and therefore requires a different output socket. Internally the connection is still remembered.
Author
Member

@rjg Yes I understand now, but as user it's really disconcerting to see the link disappearing without any warning when you change from a vector to a float, but the connection is still there. And as an addon developper, there is no error telling you that the link is not corresponding to the operation. But, well, it's working now, not a big deal. Again, thanks a lot for taking the time.

@rjg Yes I understand now, but as user it's really disconcerting to see the link disappearing without any warning when you change from a vector to a float, but the connection is still there. And as an addon developper, there is no error telling you that the link is not corresponding to the operation. But, well, it's working now, not a big deal. Again, thanks a lot for taking the time.

@rjg Is this documented somewhere? I can't find anything on this in the manual, but may be looking in the wrong place. What use is there for current behavior? Confusing UI should have a reason (connected socket with no visible connection).

@rjg Is this documented somewhere? I can't find anything on this in the manual, but may be looking in the wrong place. What use is there for current behavior? Confusing UI should have a reason (connected socket with no visible connection).

@Clarkx @Stan_Pancakes I agree that this behavior should be documented. Currently the manual states that the chosen operator determines the output data type, but it doesn't explain how existing links are handled when switching between them.

The output of the node is dynamic. It is either a vector or a scalar depending on the operator. For instance, the Length operator have a scalar output while the Add operator have a vector output.

Since I wasn't involved in the design or implementation of this feature, I can't say why the decision was made not to clear existing links when switching the operation. I'm sure there are good arguments for both approaches.

@Clarkx @Stan_Pancakes I agree that this behavior should be documented. Currently the [manual ](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/vector_math.html#outputs) states that the chosen operator determines the output data type, but it doesn't explain how existing links are handled when switching between them. > The output of the node is dynamic. It is either a vector or a scalar depending on the operator. For instance, the Length operator have a scalar output while the Add operator have a vector output. Since I wasn't involved in the design or implementation of this feature, I can't say why the decision was made not to clear existing links when switching the operation. I'm sure there are good arguments for both approaches.
Sign in to join this conversation.
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 project
No Assignees
3 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#72901
No description provided.