math_nodes_ui.py 4.1 KB

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