Add length, distance, reflect, project, divide to vector math node

This commit is contained in:
Florian Heinrich
2021-04-22 12:11:59 +02:00
parent 5d7766f27c
commit 254e6f47e3
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -465,7 +465,7 @@ class NodesBrush {
{
name: _tr("operation"),
type: "ENUM",
data: ["Add", "Subtract", "Average", "Dot Product", "Cross Product", "Normalize", "Multiply" ],
data: ["Add", "Subtract", "Multiply", "Divide", "Average", "Dot Product", "Cross Product", "Normalize", "Project", "Reflect", "Length", "Distance" ],
default_value: 0,
output: 0
}
+18
View File
@@ -38,6 +38,24 @@ class VectorMathNode extends LogicNode {
v.x *= v2.x;
v.y *= v2.y;
v.z *= v2.z;
case "Divide":
v.x /= v2.x == 0.0 ? 0.000001 : v2.x;
v.y /= v2.y == 0.0 ? 0.000001 : v2.y;
v.z /= v2.z == 0.0 ? 0.000001 : v2.z;
case "Length":
f = v.length();
v.set(f, f, f);
case "Distance":
f = v.distanceTo(v2);
v.set(f, f, f);
case "Project":
v.setFrom(v2);
v.mult(v1.dot(v2)/v2.dot(v2));
case "Reflect":
var tmp = new Vec4();
tmp.setFrom(v2);
tmp.normalize();
v.reflect(tmp);
}
if (from == 0) return v;