math_nodes_ui.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import bpy
  2. from .base_definitions import MantisMathUINode
  3. from bpy.types import Node
  4. from .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. initialized : bpy.props.BoolProperty(default = False)
  22. mantis_node_class_name=bl_idname
  23. socket_templates = StaticIntSockets
  24. def display_update(self, parsed_tree, context):
  25. if context.space_data:
  26. node_tree = context.space_data.path[0].node_tree
  27. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  28. op = mantis_node.evaluate_input("Operation")
  29. if op in ['ABSOLUTE']:
  30. self.inputs["Int B"].hide = True
  31. else:
  32. self.inputs["Int B"].hide = False
  33. class MathStaticFloatNode(Node, MantisMathUINode):
  34. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  35. bl_idname = "MathStaticFloat"
  36. bl_label = "Static Float Math"
  37. bl_icon = "NODE"
  38. initialized : bpy.props.BoolProperty(default = False)
  39. mantis_node_class_name=bl_idname
  40. socket_templates = StaticFloatSockets
  41. def display_update(self, parsed_tree, context):
  42. if context.space_data:
  43. node_tree = context.space_data.path[0].node_tree
  44. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  45. op = mantis_node.evaluate_input("Operation")
  46. if op in ['ABSOLUTE', 'FLOOR', 'CEIL', 'ROUND']:
  47. self.inputs["Float B"].hide = True
  48. else:
  49. self.inputs["Float B"].hide = False
  50. class MathStaticVectorNode(Node, MantisMathUINode):
  51. """Performs a vector math operation as a preprocess before executing the tree."""
  52. bl_idname = "MathStaticVector"
  53. bl_label = "Static Vector Math"
  54. bl_icon = "NODE"
  55. initialized : bpy.props.BoolProperty(default = False)
  56. mantis_node_class_name=bl_idname
  57. socket_templates = StaticVectorSockets
  58. def display_update(self, parsed_tree, context):
  59. if context.space_data:
  60. node_tree = context.space_data.path[0].node_tree
  61. mantis_node = parsed_tree.get(get_signature_from_edited_tree(self, context))
  62. op = mantis_node.evaluate_input("Operation")
  63. # Scalar output
  64. if op in ['LENGTH', 'DOT']:
  65. self.outputs["Result Vector"].hide = True
  66. self.outputs["Result Float"].hide = False
  67. else: # Vector output
  68. self.outputs["Result Vector"].hide = False
  69. self.outputs["Result Float"].hide = True
  70. # Single Vector and Scalar input
  71. if op in ['SCALE', ]:
  72. self.inputs["Vector B"].hide = True
  73. self.inputs["Scalar A"].hide = False
  74. elif op in ['LENGTH', 'NORMALIZE']: # only a vector input
  75. self.inputs["Vector B"].hide = True
  76. self.inputs["Scalar A"].hide = True
  77. elif op in ['LINEAR_INTERP']: # both inputs
  78. self.inputs["Vector B"].hide = False
  79. self.inputs["Scalar A"].hide = False
  80. else:
  81. self.inputs["Vector B"].hide = False
  82. self.inputs["Scalar A"].hide = True