math_nodes_ui.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. def TellClasses():
  10. return [
  11. MathStaticInt,
  12. MathStaticFloatNode,
  13. MathStaticVectorNode,
  14. ]
  15. class MathStaticInt(Node, MantisUINode):
  16. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  17. bl_idname = "MathStaticInt"
  18. bl_label = "Static Int Math"
  19. bl_icon = "NODE"
  20. initialized : bpy.props.BoolProperty(default = False)
  21. mantis_node_class_name=bl_idname
  22. def init(self, context):
  23. self.inputs.new("MathFloatOperation", "Operation")
  24. self.inputs.new("IntSocket", "Int A")
  25. self.inputs.new("IntSocket", "Int B")
  26. self.outputs.new("IntSocket", "Result Int")
  27. self.initialized = True
  28. def display_update(self, parsed_tree, context):
  29. if context.space_data:
  30. node_tree = context.space_data.path[0].node_tree
  31. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  32. op = nc.evaluate_input("Operation")
  33. if op in ['ABSOLUTE']:
  34. self.inputs["Int B"].hide = True
  35. else:
  36. self.inputs["Int B"].hide = False
  37. # do... make the operations now
  38. class MathStaticFloatNode(Node, MantisUINode):
  39. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  40. bl_idname = "MathStaticFloat"
  41. bl_label = "Static Float Math"
  42. bl_icon = "NODE"
  43. initialized : bpy.props.BoolProperty(default = False)
  44. mantis_node_class_name=bl_idname
  45. def init(self, context):
  46. self.inputs.new("MathFloatOperation", "Operation")
  47. self.inputs.new("FloatSocket", "Float A")
  48. self.inputs.new("FloatSocket", "Float B")
  49. self.outputs.new("FloatSocket", "Result Float")
  50. self.initialized = True
  51. def display_update(self, parsed_tree, context):
  52. if context.space_data:
  53. node_tree = context.space_data.path[0].node_tree
  54. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  55. op = nc.evaluate_input("Operation")
  56. if op in ['ABSOLUTE', 'FLOOR', 'CEIL', 'ROUND']:
  57. self.inputs["Float B"].hide = True
  58. else:
  59. self.inputs["Float B"].hide = False
  60. class MathStaticVectorNode(Node, MantisUINode):
  61. """Performs a vector math operation as a preprocess before executing the tree."""
  62. bl_idname = "MathStaticVector"
  63. bl_label = "Static Vector Math"
  64. bl_icon = "NODE"
  65. initialized : bpy.props.BoolProperty(default = False)
  66. mantis_node_class_name=bl_idname
  67. def init(self, context):
  68. self.inputs.new("MathVectorOperation", "Operation")
  69. self.inputs.new("VectorSocket", "Vector A")
  70. self.inputs.new("VectorSocket", "Vector B")
  71. h = self.inputs.new("FloatSocket", "Scalar A"); h.hide=True
  72. self.outputs.new("VectorSocket", "Result Vector")
  73. h = self.outputs.new("FloatSocket", "Result Float"); h.hide=True
  74. self.initialized = True
  75. def display_update(self, parsed_tree, context):
  76. if context.space_data:
  77. node_tree = context.space_data.path[0].node_tree
  78. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  79. op = nc.evaluate_input("Operation")
  80. # Scalar output
  81. if op in ['LENGTH', 'DOT']:
  82. self.outputs["Result Vector"].hide = True
  83. self.outputs["Result Float"].hide = False
  84. else: # Vector output
  85. self.outputs["Result Vector"].hide = False
  86. self.outputs["Result Float"].hide = True
  87. # Single Vector and Scalar input
  88. if op in ['SCALE', ]:
  89. self.inputs["Vector B"].hide = True
  90. self.inputs["Scalar A"].hide = False
  91. elif op in ['LENGTH', 'NORMALIZE']: # only a vector input
  92. self.inputs["Vector B"].hide = True
  93. self.inputs["Scalar A"].hide = True
  94. elif op in ['LINEAR_INTERP']: # both inputs
  95. self.inputs["Vector B"].hide = False
  96. self.inputs["Scalar A"].hide = False
  97. else:
  98. self.inputs["Vector B"].hide = False
  99. self.inputs["Scalar A"].hide = True
  100. # Set up the class property that ties the UI classes to the Mantis classes.
  101. for cls in TellClasses():
  102. cls.mantis_node_library='.math_nodes'
  103. cls.set_mantis_class()