Upgrading the Math Node and Vector Math Node


Dynamically change the number of arguments for the selected operation.
Scripts: MathExtNode.zip


I didn’t understand this operation:

var r = 0.0;
case "Fract":
     r = r - Std.int(r);

Perhaps this means:

case "Fract":
     var v1 = inputs[0].get();
     r = r - Std.int(v1);

First of all: great idea!

“Fract” means fraction and can be seen a little bit as the “opposite of floor/ceil”: it returns the value behind the decimal point. So fract(3.14) will return 0.14 and fract(1234.56789) 0.56789. That’s why the integer value is subtracted from the float value. Is r set somewhere in the code other than to 0.0? If not, there is indeed an error I think, it should probably be set to the float value of the input.

Do you plan on upgrading the original math node or do you want to add another as an extension (the node label says Math Ext? I would suggest updating the original one to bundle everything in one node.



  1. r is the variable with the result. Set at the beginning and gets the result of the expression for output. So a hundred error in the expression.

      case "Fract":
           var v1 = inputs[0].get();
           r = v1 - Std.int(v1);
  2. I will update the original node, the current name is “working”, so as not to be confused during testing.

  3. I want add operation exp.


Upgrading the mathematical node for vectors (the name on the screenshots is “working”, the original node will be updated).
I tried to change the type / name of the output value, but got the following conclusions:

  • the socket type or name cannot be changed for an existing output parameter;
  • clearing all the output parameters array (self.outputs.clear()) in the draw_buttons() function results in the following errors (I believe these are Blender problems, tried different options to get rid of the bug):
    vector_blender_bug vector_blender_bug_2 vector_blender_bug_3

As a result, I propose the following modernization options:

  1. Socket *Shader:
  2. Or two outputs:
  3. Well, and a variant with a separator for the output vector (for two outputs):

What do you think?

Update: add number option.

1 Like

I personally prefer Option 2. With two outs.


Another question:
The "Length" output parameter outputs the Length or Distance value, depending on the selected operation. Do you have a suggestion for a generic name for this parameter?

Maybe use “metric” in ref to topology.

It seems to me that it will not be clear.

Is it possible to just leave both names?

Effectively it seems less clear as it’s generic to use “metric” in order to define a concept of distance between any two members into a space … , if it’s not clear, you could see for example this ref https://en.wikipedia.org/wiki/Metric_space

The original name was Distance. But in the case of choosing the Length operation, the length of the vector is determined, which does not correspond to the space metrics.
In this parameter, display either the distances between objects (which is easier to call Distance), or the length of the vector. So I’m trying to somehow combine these concepts into one.

maybe magnitude … :wink:

1 Like

Added operation multiplication by Float.
Final version:

If there are no comments and suggestions, then they will do PR.
Scripts: VectorMathNode.zip


Eh … It’s hard to stop if something doesn’t suit you. :sweat_smile:
Another final option. The output parameter appears depending on the operation, if a value is displayed there, then the parameter appears with the appropriate name (Length, Distance, Scalar):

Scripts: VectorMathNode.zip