math_nodes_ui.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import bpy
  2. from .base_definitions import MantisMathUINode
  3. from bpy.types import Node
  4. from .utilities.utilities import (prRed, prGreen, prPurple, prWhite,
  5. prOrange,
  6. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  7. wrapOrange,)
  8. from .base_definitions import get_signature_from_edited_tree
  9. from .math_nodes_socket_templates import *
  10. def TellClasses():
  11. return [
  12. MathStaticInt,
  13. MathStaticFloatNode,
  14. MathStaticVectorNode,
  15. ]
  16. class MathStaticInt(Node, MantisMathUINode):
  17. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  18. bl_idname = "MathStaticInt"
  19. bl_label = "Static Int Math"
  20. bl_icon = "NODE"
  21. mantis_node_class_name=bl_idname
  22. socket_templates = StaticIntSockets
  23. def display_update(self, parsed_tree, context):
  24. if context.space_data:
  25. node_tree = context.space_data.path[0].node_tree
  26. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  27. op = mantis_node.evaluate_input("Operation")
  28. if op in ['ABSOLUTE']:
  29. self.inputs["Int B"].hide = True
  30. else:
  31. self.inputs["Int B"].hide = False
  32. class MathStaticFloatNode(Node, MantisMathUINode):
  33. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  34. bl_idname = "MathStaticFloat"
  35. bl_label = "Static Float Math"
  36. bl_icon = "NODE"
  37. mantis_node_class_name=bl_idname
  38. socket_templates = StaticFloatSockets
  39. def display_update(self, parsed_tree, context):
  40. if context.space_data:
  41. node_tree = context.space_data.path[0].node_tree
  42. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  43. op = mantis_node.evaluate_input("Operation")
  44. if op in ['ABSOLUTE', 'FLOOR', 'CEIL', 'ROUND']:
  45. self.inputs["Float B"].hide = True
  46. else:
  47. self.inputs["Float B"].hide = False
  48. class MathStaticVectorNode(Node, MantisMathUINode):
  49. """Performs a vector math operation as a preprocess before executing the tree."""
  50. bl_idname = "MathStaticVector"
  51. bl_label = "Static Vector Math"
  52. bl_icon = "NODE"
  53. mantis_node_class_name=bl_idname
  54. socket_templates = StaticVectorSockets
  55. def display_update(self, parsed_tree, context):
  56. if context.space_data:
  57. node_tree = context.space_data.path[0].node_tree
  58. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  59. op = mantis_node.evaluate_input("Operation")
  60. # Scalar output
  61. if op in ['LENGTH', 'DOT']:
  62. self.outputs["Result Vector"].hide = True
  63. self.outputs["Result Float"].hide = False
  64. else: # Vector output
  65. self.outputs["Result Vector"].hide = False
  66. self.outputs["Result Float"].hide = True
  67. # Single Vector and Scalar input
  68. if op in ['SCALE', ]:
  69. self.inputs["Vector B"].hide = True
  70. self.inputs["Scalar A"].hide = False
  71. elif op in ['LENGTH', 'NORMALIZE']: # only a vector input
  72. self.inputs["Vector B"].hide = True
  73. self.inputs["Scalar A"].hide = True
  74. elif op in ['LINEAR_INTERP']: # both inputs
  75. self.inputs["Vector B"].hide = False
  76. self.inputs["Scalar A"].hide = False
  77. else:
  78. self.inputs["Vector B"].hide = False
  79. self.inputs["Scalar A"].hide = True