VectorMathNode.hx 774 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package arm.node.brush;
  2. import iron.math.Vec4;
  3. @:keep
  4. class VectorMathNode extends LogicNode {
  5. public var operation: String;
  6. var v = new Vec4();
  7. public function new(tree: LogicTree) {
  8. super(tree);
  9. }
  10. override function get(from: Int): Dynamic {
  11. var v1: Vec4 = inputs[0].get();
  12. var v2: Vec4 = inputs[1].get();
  13. v.setFrom(v1);
  14. var f = 0.0;
  15. switch (operation) {
  16. case "Add":
  17. v.add(v2);
  18. case "Subtract":
  19. v.sub(v2);
  20. case "Average":
  21. v.add(v2);
  22. v.x *= 0.5;
  23. v.y *= 0.5;
  24. v.z *= 0.5;
  25. case "Dot Product":
  26. f = v.dot(v2);
  27. v.set(f, f, f);
  28. case "Cross Product":
  29. v.cross(v2);
  30. case "Normalize":
  31. v.normalize();
  32. case "Multiply":
  33. v.x *= v2.x;
  34. v.y *= v2.y;
  35. v.z *= v2.z;
  36. }
  37. if (from == 0) return v;
  38. else return f;
  39. }
  40. }