Page MenuHome

Geometry Nodes: Implicit conversion from vector to float uses distance
Closed, ResolvedPublic

Description

While working on an Attribute Convert node, I noticed that vectors are converted to float using distance.

See in screenshot: pos_to_fl column

The offending line is in source/blender/nodes/intern/node_tree_multi_function.cc

add_implicit_conversion<float3, float>(
    conversions, "Vector Length", [](float3 a) { return a.length(); });

The existing method for sockets is to use the average:

if (type_in == SOCK_FLOAT) {
  if (ns->sockettype == SOCK_FLOAT) {
    *in = *from;
  }
  else {
    *in = (from[0] + from[1] + from[2]) / 3.0f;
  }
}

Proposal:

  • Change all conversions from distance to average. Add a new average operator to corresponding BLI_float..
  • Add float to boolean to return true for values above zero and false for zero and negative numbers

I can make a patch for this.