math_definitions.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. 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. # do... make the operations now
  37. class MathStaticFloatNode(Node, MantisUINode):
  38. """A node that performs mathematical operations on float numbers as a preprocess step before generating the rig."""
  39. bl_idname = "MathStaticFloat"
  40. bl_label = "Static Float Math"
  41. bl_icon = "NODE"
  42. initialized : bpy.props.BoolProperty(default = False)
  43. def init(self, context):
  44. self.inputs.new("MathFloatOperation", "Operation")
  45. self.inputs.new("FloatSocket", "Float A")
  46. self.inputs.new("FloatSocket", "Float B")
  47. self.outputs.new("FloatSocket", "Result Float")
  48. self.initialized = True
  49. def display_update(self, parsed_tree, context):
  50. if context.space_data:
  51. node_tree = context.space_data.path[0].node_tree
  52. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  53. op = nc.evaluate_input("Operation")
  54. if op in ['ABSOLUTE']:
  55. self.inputs["Float B"].hide = True
  56. else:
  57. self.inputs["Float B"].hide = False
  58. class MathStaticVectorNode(Node, MantisUINode):
  59. """Performs a vector math operation as a preprocess before executing the tree."""
  60. bl_idname = "MathStaticVector"
  61. bl_label = "Static Vector Math"
  62. bl_icon = "NODE"
  63. initialized : bpy.props.BoolProperty(default = False)
  64. def init(self, context):
  65. self.inputs.new("MathVectorOperation", "Operation")
  66. self.inputs.new("VectorSocket", "Vector A")
  67. self.inputs.new("VectorSocket", "Vector B")
  68. h = self.inputs.new("FloatSocket", "Scalar A"); h.hide=True
  69. self.outputs.new("VectorSocket", "Result Vector")
  70. h = self.outputs.new("FloatSocket", "Result Float"); h.hide=True
  71. self.initialized = True
  72. def display_update(self, parsed_tree, context):
  73. if context.space_data:
  74. node_tree = context.space_data.path[0].node_tree
  75. nc = parsed_tree.get(get_signature_from_edited_tree(self, context))
  76. op = nc.evaluate_input("Operation")
  77. # Scalar output
  78. if op in ['LENGTH', 'DOT']:
  79. self.outputs["Result Vector"].hide = True
  80. self.outputs["Result Float"].hide = False
  81. else: # Vector output
  82. self.outputs["Result Vector"].hide = False
  83. self.outputs["Result Float"].hide = True
  84. # Single Vector and Scalar input
  85. if op in ['SCALE', ]:
  86. self.inputs["Vector B"].hide = True
  87. self.inputs["Scalar A"].hide = False
  88. elif op in ['LENGTH', 'NORMALIZE']: # only a vector input
  89. self.inputs["Vector B"].hide = True
  90. self.inputs["Scalar A"].hide = True
  91. elif op in ['LINEAR_INTERP']: # both inputs
  92. self.inputs["Vector B"].hide = False
  93. self.inputs["Scalar A"].hide = False
  94. else:
  95. self.inputs["Vector B"].hide = False
  96. self.inputs["Scalar A"].hide = True