math_definitions.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import bpy
  2. from .base_definitions import MantisNode
  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, MantisNode):
  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. def init(self, context):
  22. self.inputs.new("MathFloatOperation", "Operation")
  23. self.inputs.new("IntSocket", "Int A")
  24. self.inputs.new("IntSocket", "Int B")
  25. self.outputs.new("IntSocket", "Result Int")
  26. self.initialized = True
  27. def display_update(self, parsed_tree, context):
  28. if context.space_data:
  29. node_tree = context.space_data.path[0].node_tree
  30. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  31. op = nc.evaluate_input("Operation")
  32. if op in ['ABSOLUTE']:
  33. self.inputs["Int B"].hide = True
  34. else:
  35. self.inputs["Int B"].hide = False
  36. def traverse(self, socket):
  37. return default_traverse(self,socket)
  38. # do... make the operations now
  39. class MathStaticFloatNode(Node, MantisNode):
  40. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  41. bl_idname = "MathStaticFloat"
  42. bl_label = "Static Float Math"
  43. bl_icon = "NODE"
  44. initialized : bpy.props.BoolProperty(default = False)
  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']:
  57. self.inputs["Float B"].hide = True
  58. else:
  59. self.inputs["Float B"].hide = False
  60. def traverse(self, socket):
  61. return default_traverse(self,socket)
  62. class MathStaticVectorNode(Node, MantisNode):
  63. """Performs a vector math operation as a preprocess before executing the tree."""
  64. bl_idname = "MathStaticVector"
  65. bl_label = "Static Vector Math"
  66. bl_icon = "NODE"
  67. initialized : bpy.props.BoolProperty(default = False)
  68. def init(self, context):
  69. self.inputs.new("MathVectorOperation", "Operation")
  70. self.inputs.new("VectorSocket", "Vector A")
  71. self.inputs.new("VectorSocket", "Vector B")
  72. h = self.inputs.new("FloatSocket", "Scalar A"); h.hide=True
  73. self.outputs.new("VectorSocket", "Result Vector")
  74. h = self.outputs.new("FloatSocket", "Result Float"); h.hide=True
  75. self.initialized = True
  76. def display_update(self, parsed_tree, context):
  77. if context.space_data:
  78. node_tree = context.space_data.path[0].node_tree
  79. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  80. op = nc.evaluate_input("Operation")
  81. # Scalar output
  82. if op in ['LENGTH', 'DOT']:
  83. self.outputs["Result Vector"].hide = True
  84. self.outputs["Result Float"].hide = False
  85. else: # Vector output
  86. self.outputs["Result Vector"].hide = False
  87. self.outputs["Result Float"].hide = True
  88. # Single Vector and Scalar input
  89. if op in ['SCALE', ]:
  90. self.inputs["Vector B"].hide = True
  91. self.inputs["Scalar A"].hide = False
  92. elif op in ['LENGTH', 'NORMALIZE']: # only a vector input
  93. self.inputs["Vector B"].hide = True
  94. self.inputs["Scalar A"].hide = True
  95. elif op in ['LINEAR_INTERP']: # both inputs
  96. self.inputs["Vector B"].hide = False
  97. self.inputs["Scalar A"].hide = False
  98. else:
  99. self.inputs["Vector B"].hide = False
  100. self.inputs["Scalar A"].hide = True
  101. def traverse(self, socket):
  102. return default_traverse(self,socket)